Last active
April 29, 2017 07:35
-
-
Save myfreeer/c990acebd14da5d76421235feaa54eac to your computer and use it in GitHub Desktop.
search text in mokeedev's changelogs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//example url: http://changelog.mokeedev.com/index.php?mk_version=MK60 | |
//usage: query(String str) | |
//result will be shown in console | |
let query = str => Promise.all([...document.querySelectorAll("table > tbody > tr > td > a")].map(e=>fetchretry(e.href).then(res => res.text()).then(text=>text.match(str)&&!console.log(e.href/*,text*/)&&[e.href,text]))).then(e=>e.filter(e => e === 0 || e)); | |
//https://gist.github.com/myfreeer/44f23611451119869804f8c28ee1a190 | |
//rewrite from https://github.com/jonbern/fetch-retry | |
let fetchretry = (url, options) => { | |
var retries = (options && options.retries) ? options.retries : 3; | |
var retryDelay = (options && options.retryDelay) ? options.retryDelay : 500; | |
return new Promise((resolve, reject) => { | |
let wrappedFetch = n => fetch(url, options).then(response => resolve(response)).catch(error => n > 0 ? setTimeout(() => wrappedFetch(--n), retryDelay) : reject(error)); | |
wrappedFetch(retries); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment