The below script works in Firefox/Greasemonkey, but nothing happens in Chrome/Tampermonkey.
以下脚本适用于Firefox / Greasemonkey,但Chrome / Tampermonkey中没有任何操作。
Can anyone see why it doesn't work in Tampermonkey?
任何人都可以看到为什么它在Tampermonkey中不起作用?
// ==UserScript==
// @name Example
// @namespace Example.com
// @description Example.com
// @include https://example.com/*
// @include http://example.com/*
// @version 1
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=115012
// ==/UserScript==
window.onload = function(){
document.getElementById('close-cookies').click();
};
waitForKeyElements('div.survey16', removeSurvey);
function removeSurvey() {
document.getElementById('survey16').hide();
}
$('.chat-bot').hide();
1 个解决方案
#1
2
The question code should not work in either browser and you should see error messages in the consoles.
问题代码不应在任何一个浏览器中都有效,您应该在控制台中看到错误消息。
Problems:
-
document.getElementById('survey16')
does not have a.hide()
method. That's a jQuery function. -
removeSurvey()
should be:removeSurvey()应该是:
function removeSurvey (jNode) { jNode.hide (); //-- .hide is a jQuery function. }
- EXCEPT, there is a mismatch between the
waitForKeyElements
call andremoveSurvey
.
In the first you are searching for a div with classsurvey16
, but in the second you are trying to delete an element with the idsurvey16
. Which is it? - As a general rule, don't use
@grant none
when also using@require
, this usually leads to page conflicts and crashes. jQuery is especially bad. - Also,
@grant none
functions slightly differently in both browsers. When using@require
, specify@grant GM_addStyle
except in special, and rare, cases.
document.getElementById('survey16')没有.hide()方法。这是一个jQuery函数。
除了waitForKeyElements调用和removeSurvey之间不匹配。在第一个中,您正在使用class survey16搜索div,但在第二个中您尝试删除具有id survey16的元素。这是什么?
作为一般规则,在使用@require时不要使用@grant none,这通常会导致页面冲突和崩溃。 jQuery特别糟糕。
此外,@ grant none在两种浏览器中的功能略有不同。使用@require时,请指定@grant GM_addStyle,但特殊情况除外。
#1
2
The question code should not work in either browser and you should see error messages in the consoles.
问题代码不应在任何一个浏览器中都有效,您应该在控制台中看到错误消息。
Problems:
-
document.getElementById('survey16')
does not have a.hide()
method. That's a jQuery function. -
removeSurvey()
should be:removeSurvey()应该是:
function removeSurvey (jNode) { jNode.hide (); //-- .hide is a jQuery function. }
- EXCEPT, there is a mismatch between the
waitForKeyElements
call andremoveSurvey
.
In the first you are searching for a div with classsurvey16
, but in the second you are trying to delete an element with the idsurvey16
. Which is it? - As a general rule, don't use
@grant none
when also using@require
, this usually leads to page conflicts and crashes. jQuery is especially bad. - Also,
@grant none
functions slightly differently in both browsers. When using@require
, specify@grant GM_addStyle
except in special, and rare, cases.
document.getElementById('survey16')没有.hide()方法。这是一个jQuery函数。
除了waitForKeyElements调用和removeSurvey之间不匹配。在第一个中,您正在使用class survey16搜索div,但在第二个中您尝试删除具有id survey16的元素。这是什么?
作为一般规则,在使用@require时不要使用@grant none,这通常会导致页面冲突和崩溃。 jQuery特别糟糕。
此外,@ grant none在两种浏览器中的功能略有不同。使用@require时,请指定@grant GM_addStyle,但特殊情况除外。