Skip to content

Instantly share code, notes, and snippets.

@jaygarcia
Last active May 22, 2019 17:54
Show Gist options
  • Save jaygarcia/ae4b2a78466d673887ad9eb6a6c0cc45 to your computer and use it in GitHub Desktop.
Save jaygarcia/ae4b2a78466d673887ad9eb6a6c0cc45 to your computer and use it in GitHub Desktop.
JavaScript code to create a quick BASH script to download Lenovo device drivers (and rename them) -- because their process is a time suck!
/**
Requirements: Linux or macOS with curl, chrome (+ dev tools) installed.
Demo: https://twitter.com/ModusJesus/status/1131255310704873472
Step 1: Go to a Lenovo device driver page like: https://pcsupport.lenovo.com/us/en/products/laptops-and-netbooks/thinkpad-t-series-laptops/thinkpad-t580-type-20l9-20la/downloads
Step 2: Copy and paste the below code & run
Step 3: Copy the CURL output
Step 4: Paste in a text file and run via bash.
Step 5: Do something that is more useful than having to click a ton of times to download device drivers and rename them.
*/
function final() {
console.clear();
var elements = document.getElementsByClassName('dl-link-btn');
var res = '\n\n';
for (var i = 0; i < elements.length; i++) {
var el = elements[i];
var title = el.parentNode.parentNode.children[0].textContent.replace('Checksum','').trim();
if (title.toLocaleLowerCase().match(/readme/ig)) {
continue;
}
title = title.replace(/[^0-9A-Z]/gi, '_').replace(/__/g, '_');
var extension = el.href.split('.')[el.href.split('.').length - 1];
res += `\necho Downloading ${title}.${extension}\n`;
res += `curl ${el.href} > ${title}.${extension}\n\n`;
};
console.log(res);
}
var targetSelector = '.icon.puff.icon-s-down';
function expandGroups() {
var elToClick = document.querySelector(targetSelector)
if (! elToClick) {
targetSelector = '.icon.pointer.lenovo-box-arrow-down.puff';
if (document.querySelector(targetSelector)) {
setTimeout(expandGroups, 50);
}
else {
setTimeout(final, 50);
}
}
else {
elToClick.focus();
elToClick.click();
setTimeout(expandGroups, 50);
}
}
expandGroups();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment