greasemonkey 在新标签页上启动刷新功能

greasemonkey start refresh function on new tab

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

// ==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==
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();
}

我不能再让它工作了,我假设自 firefox 57+ 以来一些功能已经改变, 是否可以 fix/debug 这个,以便它再次工作?

相关 html 我正在尝试 运行 这个时间:

<!DOCTYPE html>
<html>
<head><title></title>
<link rel="mask-icon" href="//s.192.168.10.1/mask-icon.svg" color="#990e0e">
<link type="text/css" rel="stylesheet" href="//s.192.168.10.1/cache/css/e/etsmpm.css" data-modules="1k">
<link type="text/css" rel="stylesheet" href="//s.192.168.10.1/cache/css/c/cze0ax.css" data-modules="3q">
<link type="text/css" rel="stylesheet" href="//s.192.168.10.1/cache/css/1/1vbpas.css" data-modules="1c,1e,1,3h,3g,3n,3o,3p">
</head><body class="_3q_7">
<div class="_3p_0">
<div class="_3o_6">
<h1 class="_3o_1">
<a href="/?r=1">
<img src="//s.192.168.10.1/cache/images/b/bvi5yh.png" alt="Apache" width="388" height="120">
</a></h1><div class="_3o_3"> Logged in as <a href="/user/Test">Test</a> 
<a href="/notifications"><span title="No unread notifications" class="_3g_3" id="95f64d6ba8"><i class="_3h_0 _3h_4"></i></span></a> 
<a href="/market">787<i class="_3h_0 _3h_b"></i></a> 
<a href="/help/time" class="_3o_4"><span title="Night:" class="_3g_3 _3h_0 _3h_2" id="c1f1299e22"></span> 3:07 am EST</a> 
<a href="/logout">Log out</a>
</div><div class="_3o_9">
<a href="/?r=2">Route</a>
<a href="/account">Account</a>
<a href="/items">Items</a>
<a href="/trading">Trading</a>
<a href="/help">Help</a>
<a href="http://forums.192.168.10.1/" target="_blank">Forum</a>
</div></div>
<div class="_3p_6"></div>
<div class="_3p_7">
<div id="middle">
<h1>Index2</h1>
<ul class="_1k_0"><li>
<a href="/index/5">index5</a></li>
<li><a href="/index/1">index1</a></li>
<li style="font-weight:bold">
<a href="/index/2">index2</a></li><li><a href="/index/3">index3</a></li><li><a href="/index/4">index4</a></li><li><a href="/index/6">index6</a></li></ul><section>
<div class="A" id="44c39a0cc4"><div><a aria-labeledby="ef21da66ab" href="/get/22eKE"><img src="//s.192.168.10.1/cache/images/8/8itcaf.gif" alt="A" width="26" height="28"></a><br>
<span id="ef21da66ab">valid deascription</span></div><div><a aria-labeledby="1d460c3daf" href="/get/tg9ZF">
<img src="//s.192.168.10.1/cache/images/8/8itcaf.gif" alt="A" width="26" height="28"></a><br>
<span id="1d460c3daf">valid description</span></div><div><a aria-labeledby="1758a88110" href="/get/1qRTn">
<img src="//s.192.168.10.1/cache/images/8/8itcaf.gif" alt="A" width="26" height="28"></a><br>
<span id="1758a88110">error</span></div></div><div class="online">Users viewing this page: 1</div>
</section>
<noscript><a href="https://secure.fastclick.net/w/click.here?sid=68085&amp;m=1&amp;c=1" target="_blank">
<img src="https://secure.fastclick.net/w/get.media?sid=68085&amp;m=1&amp;tp=5&amp;d=s&amp;c=1&amp;vcm_acv=1.4" style="width:728px;height:90px"></a></noscript>
</ins></div><div class="_3p_5">
</div></div></div><div class="_3p_8"></div>
 </div><script>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");</script><noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1405173446393356&amp;ev=PageView&amp;noscript=1"></noscript><script src="//s.192.168.10.1/cache/js/c/c7yxzl.js" crossorigin="anonymous" defer></script><script>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'))});})</script></body></html>

当我尝试通过 firefox 控制台 运行 连接它时,它确实找到了文本并在新选项卡中打开了 link 我只是无法让它刷新并用 greasemonkey

重复这个过程

您的 post 中的脚本 post 存在问题。

什么是 stuff 因为它会破坏密码?
open_in_new_tab()没有用,有什么用?

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

这是一个简单的例子...

// ==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 事件。

评论更新

这是一个示例用户脚本...

// ==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();
}