标签: userscripts

用于覆盖站点 css/自定义 css 的用户脚本

我有一个可用的 userstyles.org 解决方案。但是,我也想获得一些自定义 CSS 来通过用户脚本覆盖给定网站的 CSS。

这是我到目前为止所拥有的:

// ==UserScript==
// @id            Custom_Style
// @name          Custom CSS for domain.com
// @version       1.0
// @author        vulgarbulgar
// @description   Changes the default css for domain.com
// @include       http://site.com/*
// @include       https://site.com/*
// @include       http://*.site.com/*
// @include       https://*.site.com/*
// @resource      css http://userstyles.org/custom.css
// ==/UserScript==

$(document).ready(function() {
    GM_addStyle(GM_getResourceText("css"));
});
Run Code Online (Sandbox Code Playgroud)

似乎不起作用。

我没有任何js知识,但是从一些例子中拼凑了上面的内容。将上述用户脚本安装到 Chrome 中似乎在访问目标站点时不会触发更改。

谢谢。

javascript css userscripts

5
推荐指数
1
解决办法
3044
查看次数

在 Google Chrome 中使用内容脚本禁用 onclick 广告

有些视频流网站会在您点击页面上的任意位置时弹出广告。问题是,你必须点击页面才能按播放!所以我正在考虑制作一个用户脚本来禁用执行此操作的脚本。唯一的问题是,我已经禁用了网站上的所有脚本,当我这样做时,它仍然会弹出。有什么方法可以禁用它们吗?我也在使用 jQuery,所以如果我可以通过他们的界面来做到这一点,那就太好了。

编辑:此类网站的两个完美示例是 daclips.in 和 gorrilavid.in

javascript ads popup userscripts

5
推荐指数
1
解决办法
4万
查看次数

如何为 Chrome 编写 Greasemonkey 脚本以便对其进行单元测试?

我正在编写一个 Greasemonkey 用户脚本,该脚本应该使用 jQuery 并在 Google Chrome 和 Firefox 上运行。

我已经看到了几个如何做到这一点的例子,其中包括关于 SO 的非常好的答案。所有这些都归结为调用“注入脚本”函数,并将另一个回调函数作为参数传递。

该回调函数内的代码是“魔法”发生的地方,包括访问jQuery( $) 对象。

这个解决方案效果很好。但是,使用它的后果之一是回调函数外部定义的函数无法从回调函数内部调用:

function doSomethingImportantThatIWantToUnitTest(){ ... }

function with_jquery(callback) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.textContent = "(" + callback.toString() + ")(jQuery)";
    document.body.appendChild(script);
};

with_jquery(function ($) {
    doSomethingImportantThatIWantToUnitTest(); // <---- meh. Not defined!
});
Run Code Online (Sandbox Code Playgroud)


所以,我只能使用回调函数中定义的函数。但反过来,这些函数也不能从外部调用。特别是,例如,它们不能从单元测试中调用,这对我来说非常烦人。

有没有办法为 Chrome 编写 Greasemonkey 脚本并对其进行单元测试?

jquery greasemonkey unit-testing google-chrome userscripts

5
推荐指数
1
解决办法
2456
查看次数

Can I have access to anonymous function variables in a userscript?

I'm looking for modify a javascript game with an userscript.

The problem is that all the game code is wrapped with a anonymous function like this

(function () { "use strict";
    var js = 'test';
})();
Run Code Online (Sandbox Code Playgroud)

Can I have access to a JS variable with my userscript?

Edit :

See also : How to alter this javascript with Greasemonkey?

This question is not the same as Is it possible to gain access to the closure of a function? !

javascript anonymous-function userscripts

5
推荐指数
1
解决办法
1188
查看次数

如何使用用户脚本完全禁用所有退出警告/确认消息?

我正在隔离环境中使用chrome浏览恶意网站,以分析其数据以创建黑名单。用户脚本和浏览器扩展完全自动执行此过程。

问题在于某些站点能够在beforeunloadunload(我将其称为events)上显示退出对话框。

我已经覆盖了这些events,但是当站点再次覆盖我的覆盖时,整个过程将停止。我的意思是,他们可以events通过AJAX调用,模糊脚本,评估等来重新定义。

有什么办法可以摆脱这些消息,或者保护我的覆盖?也许unsafeWindow可以解决这个问题,但是我会避免在这种讨厌的环境中使用它。

编辑 -当前,我在用户脚本中使用以下代码:

location.href = "javascript:(" + function() {
    window.onbeforeunload = null;
    window.onunload = null;
} + ")()";

setInterval(function(){
    location.href = "javascript:(" + function() {
        window.onbeforeunload = null;
        window.onunload = null;
    } + ")()";
}, 3000);
Run Code Online (Sandbox Code Playgroud)

javascript jquery google-chrome userscripts tampermonkey

5
推荐指数
1
解决办法
1229
查看次数

如何拦截API调用并使用UserScript显示来自它的数据?

有一个Web应用程序发出请求(我们称它为/api/item)。该请求返回一个带有称为的字段的json主体,该字段itemData通常对用户隐藏,但我想显示该字段。

那么,如何使用户脚本在以下位置监听请求/api/item并显示itemData字段?

作为参考,webapp发出请求的方式为:

return Promise.resolve(new Request(e,r)).then(sendCookies).then(addLangParam).then(addCacheParam).then(addXsrfKey).then(checkZeroRating).then(function(e) {
            return fetch(e)
        }).then(checkStatus).then(checkApiVersionMismatch).then(checkApiResponse)
Run Code Online (Sandbox Code Playgroud)

大多数都无关紧要,但重要的部分是Request(我认为)。

javascript greasemonkey userscripts tampermonkey fetch-api

5
推荐指数
1
解决办法
1567
查看次数

有没有办法禁用 Safari CSP(内容安全策略)检查?

似乎 Safari 对 CSP 有很强的限制。例如,在 GitHub 上,大多数用户脚本和扩展程序因此不起作用。

我从控制台收到这样的错误。

[Error] Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy. (pulls, line 0)

知道如何在 Safari 中停止 CSP 检查吗?

谢谢。

safari userscripts safari-extension content-security-policy

5
推荐指数
0
解决办法
1348
查看次数

页面更改时 Tampermonkey 播放声音?

基本上,我访问了一个特定的网站,我在计时器上设置了用户脚本自动刷新。该特定页面在刷新时不时更改内容。我希望在页面刷新和发生任何页面更改时播放声音。

这是我目前收集的代码,但我仍然需要做一些事情才能使其正常运行:

// ==UserScript==
// @name     Auto-Refresh
// @include  https://www.prolific.ac/studies
// ==/UserScript==

//--- /sf/ask/1783948491/
setTimeout(function(){ location.reload(); }, 20*1000);

var player = document.createElement('audio');
player.src = 'https://notificationsounds.com/soundfiles/a86c450b76fb8c371afead6410d55534/file-sounds-1108-slow-spring-board.mp3';
player.preload = 'auto';

  // Play a sound with condition and then player.play()
Run Code Online (Sandbox Code Playgroud)

所以基本上脚本的其余部分将是“如果发生页面更改(刷新后),则播放声音。” 这是我遇到麻烦的地方。

我一直在使用此线程作为指导:如何使用 Greasemonkey 监视静态 HTML 页面的更改?使用哈希?但我不太确定哪种方法最有效。任何和所有建议将不胜感激。提前致谢。

javascript google-chrome userscripts page-refresh tampermonkey

5
推荐指数
1
解决办法
2984
查看次数

SetimeOut间隔失败,并显示“无法将未定义或null转换为对象”

我正在使用tampermonkey进入用户脚本编写,并且无法解决此错误,我们将不胜感激。

我检测到很好的按键,只要按键保持在向下位置,空格键就会触发此功能,该功能会重复执行。控制台通常在大约30秒内写入输出,然后出现TypeError。

根据声誉限制,以下是屏幕截图:

用户脚本:

// ==UserScript==
// @name         TEST STUFF--------------------
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @run-at         document-start
// @include        http://*
// @include        https://*
// @grant        none
// ==/UserScript==

( function()
{
    'use strict';
    window.addEventListener ( "keydown", CaptureKeyPress );
    window.addEventListener ( "keyup", CaptureKeyPress );
    var Hotkeys =
    {
        perform: 32
    };
    var HotkeyToggle = false;
    function CaptureKeyPress ( a )
    {
        if ( a.keyCode == Hotkeys.perform )
        { …
Run Code Online (Sandbox Code Playgroud)

javascript userscripts tampermonkey

5
推荐指数
1
解决办法
504
查看次数

带有“凭据:true”的 fetch() 在 Chrome 中的 Tampermonkey 用户脚本中失败

Cookie发送时-header缺失credentials: true-fetch在Tampermonkey userscript -request在Chrome即使CORS配置是否正确。问题是什么?

附加信息:

相同的代码在 Firefox 中的 Tampermonkey 用户脚本中按预期工作。

我在跨域服务器上有一个 API 端点,该端点已正确配置为接受fetch带有credentials: true.

这是我当前的代码:

fetch('https://example.com/api/my/endpoint', {
    credentials: 'include',
    headers: {
        'Content-Type': 'application/json'
    }
});
Run Code Online (Sandbox Code Playgroud)

OPTIONS-preflight-请求example.com被成功返回制成具有以下标题:

access-control-allow-origin: https://requestingsite.com
allow: GET, OPTIONS
access-control-allow-methods: GET, OPTIONS
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept, Cookie, Authorization, Pragma
access-control-allow-credentials: true
Run Code Online (Sandbox Code Playgroud)

之后,发出GET-request to example.com。它在 Firefox 中按预期工作 - 它Cookie在请求中发送必要的-header。

但是,它在 Chrome 中不起作用。Chrome 中的请求包含必要的Origin-header 并匹配access-control-allow-origin服务器返回的标头中的内容。

fetch userscripts cors tampermonkey

5
推荐指数
0
解决办法
294
查看次数