首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >greasemonkey在新选项卡上启动刷新功能

greasemonkey在新选项卡上启动刷新功能
EN

Stack Overflow用户
提问于 2021-02-21 22:11:20
回答 1查看 52关注 0票数 0

我有一个旧的greasemonkey脚本,用于在新选项卡上开始刷新页面:

代码语言:javascript
运行
复制
// ==UserScript==
// @name        script
// @namespace   http://localhost
// @description Monitor the location page and catch the egg you want.
// @include     http://192.168.10.1/index/*
// @version     1
// @grant   none
// ==/UserScript==
代码语言:javascript
运行
复制
var container = document.getElementsByClassName("A");
for (var l = 0; l < container.length; l++) {
    container[l].setAttribute('id', 'A');
    var A = document.getElementById("A");
    var divs = A.getElementsByTagName("div");
    for (var i = 0; i < divs.length; i++) {
        if ((divs[i].innerHTML.indexOf("failure") != -1) || (divs[i].innerHTML.indexOf("error") != -1)) {
            var div = divs[i];
            var link = divs[i].innerHTML.href;
            for (var b = 0; b < div.childNodes.length; b++) {
                var test = div.childNodes[0].href;
                //window.location.href = test;
                open_in_new_tab(test);
            }
        }
    }
}
setTimeout(function () { window.location.href = window.location.href }, 800);

function open_in_new_tab(url )
{
  var win=window.open(url, '_blank');
  win.focus();
}

我再也不能让它工作了,我假设自从火狐57+的一些功能已经改变了,有没有可能修复/调试这个问题,这样它就可以再次工作了?

我尝试在上面运行的相关html:

代码语言:javascript
运行
复制
Logged in as Test 
 
787 
 3:07 am EST 
Log out

Route
Account
Items
Trading
Help
Forum




Index2

index5
index1

index2index3index4index6


valid deascription


valid description


errorUsers viewing this page: 1





 window.onerror=function(b,c,d,e,a){navigator.sendBeacon("/el",JSON.stringify([b,c,d,e,a&&a.stack]))};window.onbeforeunload=function(){delete window.onerror};(function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,"script","//www.google-analytics.com/analytics.js","ga");ga("create","UA-2864033-4","auto");ga("set","dimension1","new");ga("set","userId",89632);ga("send","pageview");!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version="2.0";n.queue=[];t=b.createElement(e);t.async=!0;t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,document,"script","https://connect.facebook.net/en_US/fbevents.js");fbq("init","1405173446393356");fbq("track","PageView");window.addEventListener('DOMContentLoaded',function(){global=window;require.config({"enforceDefine":true,"waitSeconds":60,"paths":{"1mh":"\/\/s.192.168.10.1\/cache\/js\/9\/9xrboc","2":"\/\/s.192.168.10.1\/cache\/js\/2\/2mcg3g","1cc":"\/\/s.192.168.10.1\/cache\/js\/7\/7y8rpz","1gi":"\/\/s.192.168.10.1\/cache\/js\/a\/a1ys2f","1gn":"\/\/s.192.168.10.1\/cache\/js\/8\/8zhrpq","b":"\/\/s.192.168.10.1\/cache\/js\/a\/asqoew"},"bundles":[]});require(["1mh"],function(_){_.i(document.getElementById('44c39a0cc4'))});require(["1cc"],function(_){_.init()});require(["1gi"],function(_){_.bindToElement(document.getElementById('95f64d6ba8'),"auto")});require(["1gi"],function(_){_.bindToElement(document.getElementById('c1f1299e22'),"auto")});require(["b"],function(_){_.init(document.getElementById('75079eec42'))});})

当我尝试通过firefox控制台运行它时,它确实找到了文本并在新选项卡中打开了链接。我就是无法让它刷新并使用greasemonkey重复此过程

EN

Stack Overflow用户

回答已采纳

发布于 2021-02-22 14:07:21

你的帖子中的脚本帖子有问题。

因为它会破解密码?

用途是什么open_in_new_tab()因为它没有被使用?

800表示800毫秒。每0.8秒重新加载一个页面是不切实际的,因为加载一个页面通常需要更长的时间。

这里有一个简单的例子..。

代码语言:javascript
运行
复制
// ==UserScript==
// @name        script
// @namespace   http://localhost
// @description Monitor the location page and catch the egg you want.
// @match       http://192.168.10.1/index/*
// @version     1
// @grant       none
// ==/UserScript==

setTimeout(function() { location.reload(); }, 5000);

请注意,某些页面可能会干扰reload()例如,使用unload事件。

更新评论

下面是一个示例用户脚本...

代码语言:javascript
运行
复制
// ==UserScript==
// @name        script
// @namespace   http://localhost
// @description Monitor the location page and catch the egg you want.
// @include     http://192.168.10.1/index/*
// @version     1
// @grant       none
// ==/UserScript==

setTimeout(function() { location.reload(); }, 2000);        // relaod after 2 seconds

document.querySelectorAll('.A div').forEach(item => {       // get all div in class A
  
  if(/failure|error/.test(item.textContent)) {              // test div content
    
    const a = item.querySelector('a');                      // get link in div
    a && openInTab(a.href);                                 // if found, open in new tab
  }
}):

function openInTab(url) {
  
  const win = window.open(url, '_blank');
  win.focus();
}
票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66303169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档