Home > front end >  Tampermonkey met a puzzling question, answer genuflect is begged?
Tampermonkey met a puzzling question, answer genuflect is begged?

Time:09-25

the complete code is as follows, very simple code
/==UserScript==
//@ name test
//@ namespace http://tampermonkey.net/
//@ version 0.1
//@ the description the try to take over the world!
//@ the author You
//@ match https://live.bilibili.com/*
//@ grant none
//==/UserScript==

(function () {
'use strict';

; (function func () {

Const anchor=document. GetElementsByClassName (' right action ') [0].
The console. The log (anchor);
If (anchor) {
The console. The log (' find injectAnchor ');
return false;
} else {
RequestAnimationFrame ((function () {
Func ();
}))
}

}) ();


}) ();

Can run it, if you have time match any script b station studio,
Script to manage to do is get the name of the class in requestanimationframe contains right - the action of the element, no cycle, until you find position, it's as simple as that, out of the question, the script during execution will have a moment to find this element, to enter the if, and print out the "find injectAnchor" this sentence, but the script will not stop, will continue to run, and then can't find a 'right action' - this element, the results are as follows:

Study a day also didn't try to understand, tm in other scripts I also deleted, even the tm and chrome reinstall again, also not line, I tried it on firefox, semicolons, add or remove requestanimationframe with settimeout or setinterval, functions, variables directly tie binding the window doesn't work, remove the closure directly through a function call, return false to add or not add also tried, no matter use, is the feeling... I on Google search didn't even know what to search, beg you dalao solutions,

CodePudding user response:

Found the problem, the problem is that tempermonkey used to match the address label @ match and @ include, if use the matching address form will appear this kind of problem, such as www.example.com/* if you use a specific address such as www.example.com/123456 will not have this kind of problem,
But also don't know what is the solution... Match the address can't write one by one

CodePudding user response:

Found the problem,
The problem is that in tempermonkey used to match the url match entered a live.bilibili.com/* such an address, and b standing live embedded in the page of an invisible iframe, this is the address of the iframe live.bilibili.com/p/, also be matched to the nature, so tampermonkey in this iframe label and opened up a single thread, are some meta tags in the iframe, so that is why the console output element was not found,

CodePudding user response:

Can be ruled out a url, in the script url judge whether the detector satisfies the conditions, do not conform to the don't perform, can determine the page characteristics to determine whether to perform
  • Related