MCPcopy Index your code
hub / github.com/hoothin/UserScripts / needUpdate

Function needUpdate

Pagetual/pagetual.user.js:10572–10602  ·  view source on GitHub ↗
(url, id)

Source from the content-addressed store, hash-verified

10570 return true;
10571 }
10572 async function needUpdate(url, id) {
10573 if (!/^https:\/\/hoothin\.github\.io\/|\/hoothin\/UserScripts\/.*\/Pagetual\/pagetualRules\.json/i.test(url)) {
10574 return true;
10575 }
10576 let rulesLength = ruleParser.rules.reduce((acc, cur) => acc + (cur.from == id ? 1 : 0), 0);
10577 if (rulesLength === 0) return true;
10578 if (fetchVersion >= 0) {
10579 return fetchVersion > (rulesData.ruleVersion || 0);
10580 }
10581 fetchVersion = await new Promise(resolve => {
10582 _GM_xmlhttpRequest({
10583 url: url.replace(/\/\w+\.json/i, "/version"),
10584 method: 'GET',
10585 timeout: 20000,
10586 headers: {
10587 'accept': 'application/json,text/html'
10588 },
10589 onload: function(res) {
10590 let version = parseInt(res.response || res.responseText);
10591 resolve(version || -1);
10592 },
10593 onerror: function(e) {
10594 resolve(-1);
10595 },
10596 ontimeout: function(e) {
10597 resolve(-1);
10598 }
10599 });
10600 });
10601 return fetchVersion > (rulesData.ruleVersion || 0);
10602 }
10603 async function addNextRule() {
10604 if (ruleIndex < 0) {
10605 let now = new Date().getTime();

Callers 1

addNextRuleFunction · 0.85

Calls 1

resolveFunction · 0.50

Tested by

no test coverage detected