首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >剧本是用Greasemonkey写的,但在Tamper猴子里什么也没有发生?

剧本是用Greasemonkey写的,但在Tamper猴子里什么也没有发生?
EN

Stack Overflow用户
提问于 2016-11-29 16:15:33
回答 1查看 671关注 0票数 1

下面的脚本可以在Firefox/Greasemonkey中使用,但是Chrome/Tamper猴子不会发生任何事情。

有人能明白为什么它在坦佩莫克不起作用吗?

代码语言:javascript
复制
// ==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();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-29 19:00:52

问题代码在两种浏览器中都不应该工作,您应该在控制台中看到错误消息。

问题:

  1. document.getElementById('survey16') method.这是一个jQuery函数。
  2. removeSurvey()应该是: 函数removeSurvey (jNode) { jNode.hide ();//- .hide是一个jQuery函数。}
  3. 但是,waitForKeyElements调用和removeSurvey之间存在不匹配。 在第一个过程中,您使用类survey16搜索一个div,而在第二个过程中,您尝试使用id survey16删除一个元素。到底是哪一个?
  4. 一般情况下,当同时使用@grant none时,不要使用@require,这通常会导致页面冲突和崩溃。jQuery is especially bad.
  5. 另外,@grant none在两种浏览器中的功能略有不同。使用@require时,除特殊和罕见的情况外,请指定@grant GM_addStyle
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40870609

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档