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

Method checkRule

Pagetual/pagetual.user.js:5326–5388  ·  view source on GitHub ↗
(r)

Source from the content-addressed store, hash-verified

5324 }
5325
5326 function checkRule(r) {
5327 if (r.from === 1 && r.url.length <= 13) return false;
5328 let urlReg = new RegExp(r.url, "i");
5329 if (urlReg.test(href)) {
5330 if (!self.ruleMatchPre(r)) return false;
5331 if (r.url.length > 15 && r.from !== 1) {
5332 self.possibleRule = r;
5333 }
5334 if (r.waitElement) {
5335 let waitTime = 500;
5336 let checkReady = () => {
5337 setTimeout(() => {
5338 if (!self.waitElement(document, r.waitElement) || !self.ruleMatchReady(r)) {
5339 checkReady();
5340 } else {
5341 setRule(r);
5342 }
5343 }, parseInt(waitTime));
5344 };
5345 checkReady();
5346 debug(r, 'Wait for');
5347 return true;
5348 } else if (r.wait) {
5349 let waitTime = 500, checkEval, maxCheckTimes = 50;
5350 if (isNaN(r.wait)) {
5351 try {
5352 checkEval = (typeof r.wait === 'function') ? r.wait : AsyncFunction("doc",'"use strict";' + r.wait);
5353 } catch(e) {
5354 debug(e, 'Error when checkeval');
5355 }
5356 } else {
5357 waitTime = r.wait;
5358 }
5359 let checkReady = () => {
5360 if (maxCheckTimes-- <= 0) {
5361 debug("Wait for rule ready but failed");
5362 setRule(r);
5363 return;
5364 }
5365 setTimeout(async() => {
5366 if (!self.ruleMatchReady(r) || (checkEval && !await checkEval(document))) {
5367 checkReady();
5368 } else {
5369 setRule(r);
5370 }
5371 }, parseInt(waitTime));
5372 };
5373 checkReady();
5374 debug(r, 'Wait for');
5375 return true;
5376 }
5377 if (r.pinUrl) {
5378 setRule(r);
5379 return true;
5380 }
5381 if (!self.ruleMatchReady(r)) {
5382 return false;
5383 }

Callers

nothing calls this directly

Calls 4

debugFunction · 0.85
ruleMatchPreMethod · 0.80
ruleMatchReadyMethod · 0.80
checkReadyFunction · 0.50

Tested by

no test coverage detected