Skip to content

Instantly share code, notes, and snippets.

@LewisGet
Last active December 6, 2020 07:27
Show Gist options
  • Save LewisGet/bf6e433803756dffc6d5a9044887c934 to your computer and use it in GitHub Desktop.
Save LewisGet/bf6e433803756dffc6d5a9044887c934 to your computer and use it in GitHub Desktop.
// 需要在同網域執行 否則需要破解 注入腳本
var urls = [
"abc.com"
];
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function wait_selector(basic_dom, selector_value, try_times) {
for (var i = 0; i < try_times; i++) {
var dom = basic_dom.document.querySelector(selector_value);
if (dom != null)
{
return dom;
}
else
{
console.log("not found");
}
await sleep(1000);
}
return false;
}
var not_stop = false;
for (var url_index = 0; url_index < urls.length; url_index++) {
var this_url = urls[url_index];
var website = window.open(this_url, "");
var dom = (await wait_selector(website, ".download", 30));
if (dom != false) { dom.parentElement.click(); }
var dom = (await wait_selector(website, "#tabDownload a", 30));
if (dom != false) { dom.click(); }
await sleep(10000);
if (dom != false)
{
website.window.close();
}
if (not_stop)
{
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment