首页 > 解决方案 > 工作的tampermonkey脚本在网站上不起作用

问题描述

<div id="captchaWindow" style="display: none;> </div>我有工作脚本来更改显示以阻止但它在网站上不起作用我不明白我做错了什么以及它们如何阻止我的脚本工作。(按 j 隐藏/显示)

// ==UserScript==
// @name         captcha
// @namespace    c
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match       *://*.agar.io/*


// @grant        none
// ==/UserScript==

function myFunction() {
    var x = document.getElementById("captchaWindow");
    if (x.style.display === "none") {
      x.style.display = "block";
    } else {
      x.style.display = "none";
    }

  }
  document.addEventListener("keydown", function(){
   if (event.which === 74)
   {myFunction();}
  });

我的最终目标是在验证码有效时“自动”隐藏验证码,并在验证码过期后再次显示......我还没有找到它是如何工作的(哪个元素说它是有效的)。

标签: javascript

解决方案


您需要myFunction();在代码的末尾。


推荐阅读