javascript - 我制作的用户脚本部分有效。有什么修复吗?
问题描述
我正在制作一个用户脚本来删除Kissanime主页上的广告
动漫网站已经为您提供了隐藏广告的按钮,但我只想删除该按钮,但它不起作用。这是我的代码
// ==UserScript==
// @name Kissanime Tool
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Kissanime Tool
// @author Joe Hill
// @match *://kissanime.ru/
// @grant none
// @require https://code.jquery.com/jquery-3.3.1.min.js
// ==/UserScript==
(function() {
'use strict';
// The code below is an example of the working code
$("#keyword").attr("value", "The script wrote here");
//The code below doesn't work
$(".divCloseBut").remove();
})();
我不确定为什么这不起作用。
解决方案
按钮是动态创建的,具有:
function AddHideButtonToDynamic() {
// some conditions
$(elemDyna).after('<div class="divCloseBut" style="....')
}
window.setTimeout(AddHideButtonToDynamic, 5000);
和
function AddCloseButton(id) {
// some conditions
elem.after('<div class="divCloseBut" style="z-index:1000; ...')
}
拦截这些函数调用是可能的(虽然有点烦人) - 但是,注入一个<style>
提供按钮的标签会更容易display: none
,这可以在页面加载时完成一次,而且只能完成一次,所以你不必等待元素出现:
document.body.appendChild(document.createElement('style')).textContent = `
.divCloseBut {
display: none !important;
}`;
推荐阅读
- docker - 如何将此 gitlab yml 文件重写为 docker 文件
- javascript - 防止 rxjs 主题完成
- c# - 我可以告诉外部函数从其本地函数内部返回吗?
- ruby-on-rails - 如何创建 CSV 并将其保存到 Rails 中的主机?
- python - 无法从 arduino 获取 gps 坐标以与 kivy mapview 绑定
- asp.net-mvc - IIS 从错误的位置读取.. 是吗?
- replication - Gerrit 3.0.4 如何删除已提交但复制失败的提交
- service-worker - 如果未访问,chrome 是否会删除离线内容?
- ios - IOS下OpenGL如何正确渲染广色域(Display p3)
- python - 将模板变量插入块标签