Skip to content

Instantly share code, notes, and snippets.

@devAsadNur
Last active December 8, 2021 09:52
Show Gist options
  • Save devAsadNur/174535bc66b4b5095e9c8d95209a1e0c to your computer and use it in GitHub Desktop.
Save devAsadNur/174535bc66b4b5095e9c8d95209a1e0c to your computer and use it in GitHub Desktop.
Scrapper script for downloading CSS and JS files from any website.
// Go to your desired website. Just paste the below whole script to browser console. Hit enter & see the magic!!!
(function () {
let currentUrl;
let currentUrlBase;
let filePath;
let fileName;
let fileUrl;
let scrapperPopup;
let scrapperContainer;
let outputContent;
// Element filtering function
function filterElement(elementTitle, tagName, fileExtension) {
let contentList = document.createElement('ul');
contentList.classList.add('scrapper-list');
contentList.setAttribute('style', 'margin: 0 auto 50px; padding: 0; list-style: none;');
contentList.innerHTML = `<h2 style="margin: 0 auto 10px; font-size: 20px; line-height: 24px;">Scrapped External ${elementTitle}s:</h2>`;
externalElements = document.querySelectorAll(tagName);
externalElements.forEach(externaElement => {
entireElement = externaElement.outerHTML;
if (!entireElement.includes(fileExtension)) { return }
entireElementSplitted = entireElement.split('"');
entireElementSplitted.forEach(elementPart => {
if (elementPart.includes(fileExtension)) {
filePath = elementPart;
if (filePath.includes('?')) {
filePath = filePath.substring(0, filePath.indexOf('?'));
}
fileName = filePath.split('/').pop();
if (filePath.includes('http')) {
fileUrl = filePath;
} else {
fileUrl = `${currentUrlBase}/${filePath}`;
}
// console.log(filePath);
// console.log(fileName);
// console.log(fileUrl);
outputContent = `<li class="scrapper-item" style="border: solid 1px #dbe2e8; box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.1); margin-bottom: 1em; padding: 20px 25px; box-sizing: border-box; display: flex; flex-direction: row; flex-wrap: nowrap; justify-content: space-between; align-items: center;">
<div class="scrapper-content">
<h3 style="margin: 0 auto 10px; font-size: 20px; line-height: 24px;">${fileName}</h3>
<a style="display: inline-block; font-size: 14px; line-height: 16px; margin-bottom: 5px; text-decoration: none;" href="${fileUrl}" target="_blank">${fileUrl}</a>
</div>
<a class="scrapper-button" style="background: #ddd; padding: 15px 40px; border-radius: 5px; font-size: 16px; line-height: 20px; text-decoration: none; border: solid 1px #ccc; box-shadow: 0 0 15px 0 rgba(0, 0, 0, 0.1); box-sizing: border-box;" href="${fileUrl}" target="_blank" download="">Download</a>
</li>`;
contentList.insertAdjacentHTML('beforeend', outputContent);
}
});
});
scrapperContainer.insertAdjacentElement('beforeend', contentList);
document.body.insertAdjacentElement('beforeend', scrapperPopup);
}
currentUrl = location.href;
let currentUrlSplitted = currentUrl.split('/');
if (currentUrlSplitted[currentUrlSplitted.length - 1].includes('.')) { currentUrlSplitted.pop() };
currentUrlBase = currentUrlSplitted.join('/');
scrapperPopup = document.createElement('div');
scrapperPopup.id = 'scrapper-popup';
scrapperPopup.innerHTML = `<div id="scrapper-container" style="width: 90%; max-width: 1170px; display: block; box-sizing: border-box; margin: 50px auto; padding: 50px; background: #eee; border-radius: 3px;">
<h1 style="text-align: center; font-size: 30px; margin-bottom: 30px;">External Resource Scrapper by <a
href="https://github.com/devAsadNur">Asad Nur</a></h1>
</div>`;
scrapperContainer = scrapperPopup.querySelector('#scrapper-container');
document.body.setAttribute('style', 'position: relative !important; overflow-x: hidden;');
scrapperPopup.setAttribute('style', 'position: absolute; top: 0; left: 0; z-index: 99999; width: 100%; height: 100%; min-width: 100vw; min-height: 100vh; overflow-x: hidden; background: rgba(0,0,0,0.8);');
filterElement('Stylesheet', 'link', '.css');
filterElement('Script', 'script', '.js');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment