jquery - Tampermonkey:试图点击按钮
问题描述
我试图点击的按钮:
--
<button data-adblock-el="continueWithAdblockerButton" aria-label="Continue with ad blocker"
class="outline-focus">
<svg aria-labelledby="title-9b2bd6fd-8b00-4d7e-8535-cfc1811b1b07" class="stroke-current"
width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"
role="img">
<title id="title-9b2bd6fd-8b00-4d7e-8535-cfc1811b1b07">Icon: schließen</title>
<g id="l-close-9b2bd6fd-8b00-4d7e-8535-cfc1811b1b07">
<path id="vector-9b2bd6fd-8b00-4d7e-8535-cfc1811b1b07" d="M18 18L6 6m12 0L6 18" stroke-
width="1.3" stroke-linecap="round"></path>
</g>
</svg>
</button>
在 concole 这有效:
document.querySelector('button[data-adblock-el^="continueWithAdblockerButton"]').click();
但是我在 Tampermonkey 中所做的任何事情似乎都没有效果。我的脚本:
// ==UserScript==
// @name some script
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author jhm
// @match https://www.spiegel.de/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
waitForKeyElements ('button[data-adblock-el^="continueWithAdblockerButton"]', clickNode);
document.querySelector('button[data-adblock-el^="continueWithAdblockerButton"]').click();
$(document).ready(function() {
document.querySelector('button[data-adblock-el^="continueWithAdblockerButton"]').click();
}
function clickNode (jNode) {
jNode.click ();
}
// Your code here...
})();
解决方案
推荐阅读
- c++ - "class XXXX;" 是什么意思?在cpp文件中是什么意思?
- kotlin - 为什么系统显示“No main method found in project”。
- mongodb - 创建新文档时增加 Mongoose 数字 ID
- reactjs - 如何在下拉菜单中添加按钮?
- r - 用R中的给定值替换字符串中不相邻索引处的字符的最直接方法是什么?
- ffmpeg - ffmpeg 创建的 m3u8 文件不能被 VLC 播放
- openwisp - openWISP2 可以通过 virtualbox 上的设备 guest openWRT 控制设备 WiFi 适配器吗?
- javascript - 对象作为 React 子对象无效 - 请改用数组
- regex - Ansible:如何在变量中查找单词出现?
- prolog - 如何使用 Prolog 中的一组排列列表生成输出?