您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
given a selector waits for elements to be inserted into the DOM and executes a callback for each match
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/5679/22195/Wait%20For%20Elements.js
- /**
- * @param sel - the selector you want to wait for
- * @param action - the callback that will be executed when element/s matching the given selector are found, it is passed the array of found elements
- * @param stopLooking - if true the function will stop looking for more elements after the first match
- */
- function waitForElems(sel, action, stopLooking) {
- var id = 'fke' + Math.floor(Math.random() * 12345);
- function findElem(sel) {
- var found = [].filter.call(document.querySelectorAll(sel), function(elem) {
- return elem.dataset[id] !== 'y';
- });
- if(found.length > 0) {
- found.forEach(function(elem) {
- elem.dataset[id] = 'y';
- action(elem);
- });
- if(stopLooking) {
- clearInterval(tick);
- }
- }
- }
- var tick = setInterval(findElem.bind(null, sel), 300);
- findElem(sel);
- }
- /**
- * @param regex - should match the site you're waiting for
- * @param action - the callback that will be executed when a matching url is visited
- * @param stopLooking - if true the function will stop waiting for another url match after the first match
- */
- function waitForUrl(regex, action, stopLooking) {
- function checkUrl(regex) {
- var url = window.location.href;
- if(url !== lastUrl && regex.test(url)) {
- action();
- }
- if(stopLooking) {
- clearInterval(tick);
- }
- lastUrl = url;
- }
- var tick = setInterval(checkUrl.bind(null, regex), 300),
- lastUrl;
- checkUrl(regex);
- }