Skip to content

Instantly share code, notes, and snippets.

@grambas
Forked from Yiin/userscript.js
Last active Jan 21, 2019
Embed
What would you like to do?
[Userscripts]
// ==UserScript==
// @name Unnamed Script 760860
// @version 1
// @grant GM.xmlHttpRequest
// get all players who sent reinforcement
// ==/UserScript==
(async () => {
const rows = [...document.querySelectorAll('#overview > tbody > tr')];
const thisPlayer = document.getElementsByClassName('playerName')[0].childNodes[3].innerHTML;
const promises = rows
.filter(el => el.querySelector('.iReport.iReport8'))
.map((el, index) => new Promise(resolve => {
setTimeout(() => {
console.log('parsing', `${index + 1}/${rows.length}`);
GM.xmlHttpRequest({
url: el.querySelector('.iReport + div > a').href,
method: 'GET',
onload(response) {
const parser = new DOMParser();
const page = parser.parseFromString(response.responseText, 'text/html');
//const info = `${page.querySelector('.player').innerHTML.trim()} : ${el.querySelector('.dat').innerHTML.trim()}`;
let info = "";
if( thisPlayer != page.querySelector('.player').innerHTML.trim() ){
info = `${page.querySelector('.player').innerHTML.trim()} : ${el.querySelector('.dat').innerHTML.trim()}`;
}
resolve(info);
},
onerror() {
console.log('error');
resolve();
},
});
}, index * parseInt(Math.floor(Math.random() * 500) + 500));
}));
Promise.all(promises).then(data => data && console.log(data.join('\n')));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment