I don't know up-front how many DOIs there will be. If I use this
const started = Date.now()
function detectWeb(doc, url) {
if ((Date.now() - started) < 5000) {
Zotero.monitorDOMChanges(doc.body)
return false
}
// Blacklist the advertising iframe in ScienceDirect guest mode:
//
http://www.sciencedirect.com/science/advertisement/options/num/264322/mainCat/general/cat/general/acct/...
// This can be removed from blacklist when 5c324134c636a3a3e0432f1d2f277a6bc2717c2a hits all clients (Z 3.0+)
const blacklistRe = /^https?:\/\/[^/]*(?:google\.com|sciencedirect\.com\/science\/advertisement\/)/i;
if (blacklistRe.test(url)) {
return false;
}
let doiOrDOIs = getDOIs(doc, url);
if (Array.isArray(doiOrDOIs)) {
return doiOrDOIs.length ? "multiple" : false;
}
return "journalArticle"; // A decent guess
}
I take it that will run the risk of returning false if the last DOM update is before those 5 seconds, regardless of whether DOIs are on the page.
What I'd really like to achieve is "if something changed in the DOM in the past second, try again by calling Zotero.monitorDOMChanges and returning false, else run the rest of the regular body of detectWeb".