我正在使用greasemonkey 将脚本注入到浏览器中加载的每个页面中。我现在面临的问题是,如果浏览器从同一域中的一个页面移动到另一个页面,greasemonkey 不会再次注入我的脚本。例如,我在 google.com,因此当我的浏览器加载此页面时,我的脚本就会被注入。现在,假设我输入一些搜索字符串并单击搜索。浏览器将我带到主网址为 google.com 的另一个页面。在这里,我的脚本没有被注入。
我该如何解决这样的问题。
任何帮助/意见将不胜感激。
我正在这样做,但它不起作用:
window.addEventListener("load", function load(event){
alert('hola');
},false);
window.location.assign("about:blank");
Run Code Online (Sandbox Code Playgroud)
这是一个 Greasemonkey 脚本。新位置已加载,但警报从未显示。
我正在使用外部服务的 HTML 文档页面,该服务在 HTML 页面中呈现 JSON 片段。HTML 源代码如下所示:
<pre>{
"product-link": "https://example.com/product-link",
"teaser_image": "https://example.com/teaser-image",
"product_image_first": "https://example.com/product-image-first",
"headline": "Example headline",
}</pre>
Run Code Online (Sandbox Code Playgroud)
JSON 块在没有语法突出显示的情况下呈现。由于我无法控制外部服务,因此我想通过用户脚本将语法突出显示(颜色)应用于 JSON 片段。
我找到了Greasemonkey,但仍然没有了解如何注入语法高亮库。
此代码选择数据 ID 之间的最高数值并为其添加石灰背景。顺便说一句,这些数字是十六进制值。我的问题是,在十六进制值中,它是最后 4 个值的问题,但我的代码采用了整个字符。我怎样才能让我的代码只对最后 4 个字符起作用?
对不起,这对您来说可能很容易解决,但我一遍又一遍地尝试,但无法使其正常工作。
十六进制转十进制:
dc61 = 56417
dc62 = 56418
dc63 = 56419
dc64 = 56420
maxData = $(".answers li[data-id]").get ().reduce ( (maxObj, crrntNode) => {
var idVal = parseInt ( $(crrntNode).data("id"), 16) ;
if (idVal > maxObj.value) {
maxObj.value = idVal;
maxObj.node = crrntNode;
}
return maxObj;
},
{value: 0, node: null}
);
$("body").append (`<p>The highest data-id value was ${maxData.value}.</p>`)
$(maxData.node).css ("background", "lime");Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="question-text" class="question sp-element border-radius active">What is favorite colour?</div> …Run Code Online (Sandbox Code Playgroud)我编写了一个脚本,当前在 GreaseMonkey 中的页面加载时工作。但是,当我将此脚本传输到 TamperMonkey(在 Chrome 中)时,该脚本拒绝在页面加载时运行。
查看脚本:
// ==UserScript==
// @name Redirect_ADFS
// @author Eskimonian
// @version 2018.08.20
// @description Auto Redirect ADFS Sites to Internal Login Page
// @run-at document-end
// ==/UserScript==
window.onload = function Redirect() {
var currenturl = window.location.href //define current URL
if(currenturl.indexOf("/adfs") > -1) {
var newurl = "//" + new URL(document.referrer).hostname + '/admin?saml=off'; //set destination URL
alert("[Eskimo.1] SAML Site Detected. Redirecting to Internal Login page.")
window.location = newurl
}
} //redirect URL if the currently …Run Code Online (Sandbox Code Playgroud) 我一直在寻找一种通过用户脚本重写特定 URL 的方法(GreaseMonkey、TamperMonkey...)。我找到了替换特定域的所有部分但不仅仅是一个网址的解决方案。
更准确地说,在 iCloud Mail (icloud.com/mail) 上,我想将 https://www.icloud.com/message/current/en-us/index.html#compose替换 为 https://mail.google.com /mail/?view=cm&fs=1&tf=1
我根本不是脚本专家,我不知道从哪里开始
非常感谢
我正在尝试制作一个自动登录脚本,而且我被困在提交部分......
来自网站的提交表格的来源是
<input type="submit" value="Sign In" class="signin" id="sumbitLogin">
Run Code Online (Sandbox Code Playgroud)
而我正在努力
document.getElementById("sumbitLogin").submit();
Run Code Online (Sandbox Code Playgroud)
如果我设置一个属性,例如值,它就会变好......
我该如何解决?
我正在寻找一些将外部URL的html结合到当前页面的greaseMonkey脚本.
我听说在JavaScript中这样做可能是一个问题,因为同源策略,但是GreaseMonkey是否支持服务器端脚本(jQuery),或者是通过一些外部js库/ api的get-method我可以用吗?
[编辑]是否可以通过添加参考外部网址的iframe来"获取"html?
我正在更新一个Greasemonkey脚本,该脚本href在vBulletin的ignore部分中读取被忽略用户列表中的名称.
我将值存储在一个数组中,然后display:none将td其隐藏在消息板中的被忽略的用户线程中.
执行此操作的唯一方法是访问忽略列表并将数组值存储在其中about:config.但是我无法将数组存储在那里.
以下是更新脚本的相关部分:
// @grant GM_setValue
// ==/UserScript==
(function() {
var allT;
var allR;
var plonk = new Array();
var ignore_threads_from = GM_setValue;
var url = "http://www.site.com/forums/profile.php?do=ignorelist"; //use for iggy list URL
var currentURL = window.location;
if (url == currentURL) {
var GM_setValue = $('#ignorelist.userlist li a').map(function() {
return $(this).text();
}).get();
}
Run Code Online (Sandbox Code Playgroud) 我需要用新网页替换HTML页面的所有旧链接,因此创建了以下脚本
document.body.innerHTML.replace('www.forumoldpage','www.forumnewpage');
Run Code Online (Sandbox Code Playgroud)
保存它,但是当我打开网页时什么也不做。
代码有问题吗?还是我忘了做些事?
greasemonkey ×10
javascript ×7
tampermonkey ×3
jquery ×2
userscripts ×2
arrays ×1
browser ×1
firefox ×1
html ×1
json ×1
onload ×1
replace ×1
text ×1
url ×1