标签: tampermonkey

如何覆盖警报功能?

在网站上有类似的代码(其网站上的网站)

<script language="JavaScript" type="text/javascript">         
    alert("ble");
</script>
Run Code Online (Sandbox Code Playgroud)

我尝试使用GM禁用该警报.我试图这样做

unsafeWindow.alert=function() {};
Run Code Online (Sandbox Code Playgroud)

但我看到警报并得到此错误

Error: uncaught exception: [Exception... "Component is not available"  nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)"  location: "JS frame :: file:///C:/Documents%20and%20Settings/arokitnicki/Dane%20aplikacji/Mozilla/Firefox/Profiles/sm4bsods.default/extensions/%7Be4a8a97b-f2ed-450b-b12d-ee082ba24781%7D/components/greasemonkey.js :: anonymous :: line 377"  data: no]
Run Code Online (Sandbox Code Playgroud)

如何禁用该警报?

PS这是JavaScript不问题,但Greasemonkey的问题.

编辑:

它的公司的网站,所以我无法粘贴真正的代码

<head>
    <script>    
        dojo.require("dojo.back");
        dojo.back.init(); 
    </script>
</head>
<body onload="someMethod()">
    <iframe></iframe>
    <script>         
        alert("bla");
    </script>
</body>
Run Code Online (Sandbox Code Playgroud)

标题中还有一些脚本和CSS声明.

javascript alert greasemonkey userscripts tampermonkey

6
推荐指数
1
解决办法
4587
查看次数

如何将书签转换为Greasemonkey用户脚本?

有一个简单的方法来做到这一点.还有什么需要改变的,因为它的运行方式不同?

javascript greasemonkey bookmarklet userscripts tampermonkey

6
推荐指数
1
解决办法
3522
查看次数

如何为Chrome Tampermonkey用户脚本创建工具栏按钮?

我编写了一个用户脚本,当我调用它时我想运行它(不是每次匹配的网页都加载).理想情况下,我想创建一个工具栏按钮来启动此脚本.如何才能做到这一点?

PS:我需要它与网页脚本在相同的上下文中运行,并能够调用嵌入其中的函数.

google-chrome userscripts google-chrome-extension tampermonkey

6
推荐指数
1
解决办法
3844
查看次数

除非刷新页面,否则 Grease/tampermonkey 脚本无法工作

我经常光顾一个论坛,该论坛以一种可怕的方式忽视用户。如果您将某人置于忽略状态,则几乎会使该用户的存在更加普遍。

所以我写了这个来完全隐藏它们:

// ==UserScript==
// @name         Freddie
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  hide annoying forum users
// @author       You
// @match        http://www.scout.com/college/kansas/forums/*
// @grant        none
// ==/UserScript==
/* jshint -W097 */

'use strict';

function checkForDiv() { // crappy workaround function to wait for AJAX content      
    if (!document.getElementById("wrapper")) {        
        setTimeout(checkForDiv, 300);   
    } else {       
        checkNames();   
    }
}

function checkNames() {  
    var mybannedList = ["Pyros", "GOHawksGators", "th30r3o"]; // add usernames  here
    var nms = document.body.querySelectorAll('a.authName'), i = 0, len …
Run Code Online (Sandbox Code Playgroud)

javascript greasemonkey tampermonkey

6
推荐指数
1
解决办法
3114
查看次数

如何以编程方式将tampermonkey脚本更新为本地文件?

出于安全原因,Tampermonkey脚本不会保存在可访问的文件中,而是保存在插件数据中。实时编辑它们的唯一方法是使用Tampermonkey的集成编辑器。

但是,我宁愿使用IDE及其所有功能。我还想使用webpack从多个文件中打包脚本。

为此,我需要一种以编程方式将Tampermonkey中的脚本更改为新版本的方法。到目前为止,我所做的是手动将新脚本复制并粘贴到Tampermonkey的编辑器中,这真的很累。

那么如何以编程方式更改Tampermonkey的脚本源代码?

javascript tampermonkey

6
推荐指数
2
解决办法
1500
查看次数

Tampermonkey 未显示 Chrome 通知

我正在尝试让我的 Tampermonkey 脚本显示 Chrome 通知,但没有显示通知。我已允许在网站上发送通知。

这是我的代码:

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        somewebsite.com/*
// @grant        GM_notification
// @require      http://code.jquery.com/jquery-1.12.4.min.js
// ==/UserScript==

(function ($, undefined) {
    $(function () {
        GM_notification({title: 'foo', image: 'bar', text: '42', onclick: console.log});
    });
})(window.jQuery.noConflict(true));
Run Code Online (Sandbox Code Playgroud)

我需要改变什么?

javascript google-chrome tampermonkey

6
推荐指数
1
解决办法
1894
查看次数

如何@match 用户脚本中的 URL 哈希?

我有很多打开的网站标签 - 我想将其限制为只有一个 URL。

问题是 URL 包含#在其中,我似乎无法 @match 它。

该网址如下所示: https://xxx.xxxxxx.xxx/#/xxxxxx

我试过:

// @match https://xxx.xxxxxx.xxx/#/xxxxxx - doesnt work

// @match https://xxx.xxxxxx.xxx/* - works - but works on all tabs

// @match https://xxx.xxxxxx.xxx/*/xxxxxx -doesnt work;/

// @match https://xxx.xxxxxx.xxx/\#/xxxxxx -doesnt work;/
Run Code Online (Sandbox Code Playgroud)

* 和后面的任何组合都不起作用。:(

url greasemonkey match userscripts tampermonkey

6
推荐指数
1
解决办法
3960
查看次数

Tampermonkey 访问页面上的 JSON 调用/URL?

我有一个index.html调用外部 URL的页面。这个外部 URL 是一个 JSON 端点。换句话说,当我打开开发工具(使用F12)时,我看到两个资源:index.htmlmyJSONEndpoint

我希望每次加载时都能获取该 JSONindex.html并对其进行处理。

Greasemonkey 或 Tampermonkey 能做到这一点吗?

页面示例:

<!doctype html>
<html>
<head>
 <title>Weather</title>
<script>
   var xmlhttp = new XMLHttpRequest();
   xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
             var myObj = JSON.parse(this.responseText);
        }
 };
xmlhttp.open("GET", "https://api.weather.gov/points/39.7456,-97.0892", true);
xmlhttp.send();
</script>
</head>
<body>
  <p>Page Loaded...</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

当我加载该页面时,开发工具中会出现两个请求。基本索引页面和 JSON 请求。

我想获取 JSON 内容并将其推送到 DOM 上。然后用户可以从那里复制/粘贴。
创建一个新的<div>然后将内容粘贴在那里?

javascript json greasemonkey userscripts tampermonkey

6
推荐指数
1
解决办法
9911
查看次数

如何在用户脚本中使用 Service Worker

我想在某人的网站中缓存特定请求,然后我发现 service worker 是一个不错的选择。但是我找不到任何通过 tampermonkey 注入 service worker 的方法。那么有没有什么技巧可以做到这一点?

userscripts tampermonkey service-worker

6
推荐指数
1
解决办法
239
查看次数

编写用户脚本时是否真的需要立即调用函数表达式 (IIFE) 模式?

我的问题非常类似于javascript中自执行函数的目的是什么?,但是它涉及用户脚本(特别是针对 GreaseMonkey)。

我看到有些用户脚本是用这种模式分发的,有些则不是。

具有 IIFE 模式的脚本示例:(来源)

// ==UserScript==
// (...)
// ==/UserScript==

(function(){
    // if <condition>
        document.location.href += '?sk=h_chr';
    // ...
})();
Run Code Online (Sandbox Code Playgroud)

没有它的脚本示例:(来源)

// ==UserScript==
// (...)
// ==/UserScript==

window.location.href = "https://www.facebook.com/?sk=h_chr";
Run Code Online (Sandbox Code Playgroud)

此外,我还发现 TamperMonkey 的“新脚本”模板遵循它,而 GreaseMonkey 和 ViolentMonkey 的模板没有。

那么问题是,IIFE 模式在编写用户脚本时有用吗?

特别是,如果我的脚本处于strictmode,并且我使用let而不是var. 无论如何,据我所知,用户脚本中定义的函数和变量在全局页面范围内不可用。

谢谢。

javascript userscripts tampermonkey ecmascript-6 greasemonkey-4

6
推荐指数
1
解决办法
708
查看次数