这是一个油脂单脚本.我不知道javascript,所以这使得这特别有趣.
function notify(){
if window.find("1 minute")==true{
alert("y");
setTimeout("alert('time to click soon!')",60000)
}
if window.find("2 minute")==true{
alert("y");
setTimeout("alert('time to click soon!')",2*60000)
}
Run Code Online (Sandbox Code Playgroud)
......重复x30 ......
}
notify();
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我是JavaScript的新手,我自己学习.我目前正在创建和调整GreaseMonkey脚本.我注意到大多数简单的脚本(即那些不需要命名函数的脚本)直接进入主代码,但有些脚本设置如下:
(function() {
//main code here
})();
Run Code Online (Sandbox Code Playgroud)
这种编码有什么意义?我已经注释掉了顶部和底部,脚本仍然运行完全相同.
它只是一个编码标准,还是它实际上有一个功能?并且,正如我的标题所要求的那样,它是GreaseMonkey特有的东西,还是我应该一直做的事情?
我需要在后台发布Greasemonkey.我试图动态创建一个iframe并发布到它,但它不起作用:
function crossDomainPost() {
// Add the iframe with a unique name
var iframe = document.createElement("iframe");
var uniqueString = "CHANGE_THIS_TO_SOME_UNIQUE_STRING";
document.body.appendChild(iframe);
iframe.style.display = "none";
iframe.contentWindow.name = uniqueString;
// construct a form with hidden inputs, targeting the iframe
var form = document.createElement("form");
form.target = uniqueString;
form.action = "http://INSERT_YOUR_URL_HERE";
form.method = "POST";
// repeat for each parameter
var input = document.createElement("input");
input.type = "hidden";
input.name = "INSERT_YOUR_PARAMETER_NAME_HERE";
input.value = "INSERT_YOUR_PARAMETER_VALUE_HERE";
form.appendChild(input);
document.body.appendChild(form);
form.submit();
}
Run Code Online (Sandbox Code Playgroud)
有人说即使我们发帖,我们也无法接受这些价值观.如果我们不能,只需让用户访问该页面即可.它可以在JS,jQuery,AJAX帖子中.不仅仅是form-iframe技巧.
如果您有一个网站,您能否以某种方式找出访问者是否正在使用 javascript 用户脚本修改您的网站?
在我的greasemonkey脚本中,我想检查GM值:用户名和密码是否设置,但是当我尝试以下代码时它会给我回错:
TypeError: GM_getValue(...) is undefined
...f (GM_getValue ("username").length == 0 + GM_getValue ("password").length == 0 )
Run Code Online (Sandbox Code Playgroud)
码:
if (GM_getValue ("username").length == 0 + GM_getValue ("password").length == 0 ){
var username = $('input[name=username]');
var password = $('input[name=password]');
//Username en Password in Firefox zetten met GM_setValue
$(".button").click(function(){
GM_setValue ("username", username.val() );
GM_setValue ("password", password.val() );
});
}
Run Code Online (Sandbox Code Playgroud) 在阅读论坛时,我希望能够使用可自定义的关键字过滤器来隐藏某些行.
例如,在这个论坛上,我想隐藏某些用户名的任何行(第3列).
编写一个只能在此站点上执行此操作的Greasemonkey脚本是否很困难?
或者是否有一个Firefox插件可以做这种事情?
我正在尝试制作Greasemonkey脚本以在Facebook页面中添加按钮.但我需要等待创建一个元素来添加按钮.
我正在尝试使用MutationObserver(如此处所示)来执行此操作,但存在错误.
function init() {
console.log('Launched : ' + launched);
if (!launched) {
launched = true;
main();
}
}
console.log('barfoo');
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (!mutation.addedNodes) return;
console.log(mutation.addedNodes.type());
for (var i = 0; i < mutation.addedNodes.length; i++) {
if (mutation.addedNodes[i].matches('div[class="pam _5shk uiBoxWhite bottomborder"]')) {
console.log('init');
init();
}
}
})
});
console.log('bar');
try {
observer.observe(document.body, {
childlist: true,
subtree: true,
attributes: false,
characterData: false,
});
} catch (error) {
console.log(error);
} …Run Code Online (Sandbox Code Playgroud) 我经常使用一个简单的 Greasemonkey JS 脚本来隐藏网页上的元素 - 这是一个基本脚本,我用来隐藏 Yahoo Mail 上的一些广告,这些广告位于具有特定 ID 的 DIV 中:
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
addGlobalStyle(" #slot_LREC, #slot_LREC4 { display:none; }");
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是雅虎邮件中的很多内容没有通用的类或 ID,而是有一个data-test-id值 - 例如
<a data-test-id="pencil-ad" class="something_very_complicated">example</a>
Run Code Online (Sandbox Code Playgroud)
我想知道是否有任何方法可以创建 addGlobalStyle 函数的变体来隐藏元素具有特定data-test-id值的元素?
我无法选择使用 jQuery - 或者至少,我不知道如何将 jQuery 添加到 GM 脚本中......
据我所知,这不是javascript: select all elements with "data-" attribute (without jQuery)的重复,因为我试图仅隐藏一个 data-test-id 属性具有特定值的元素。我不想隐藏所有具有 data-test-id …
我有一个网站可以更改他的输入ID,我正在尝试进行半自动登录,自动填写电子邮件和密码部分......
我用greasemonkey和jQuery做这个...
我正在尝试这样的事情
$("input[@type=text]").setValue("email@gmail.com");
Run Code Online (Sandbox Code Playgroud)
但没有成功......页面只有登录部分,两个文本类型输入......
我在这里错过了什么?
我在网上找到了一个greasemonkey脚本,它打开了新标签页面上的所有链接.我想要做的是编辑它,以便它只打开包含单词的特定链接forum.
这是我目前使用的脚本:
javascript: (function () {
{
var links = document.getElementsByTagName('a');
for (i in links) {
window.open(links[i].href);
}
}
})()
Run Code Online (Sandbox Code Playgroud)
如何编辑它来做我想要的?
greasemonkey ×10
javascript ×6
html ×2
jquery ×2
userscripts ×2
css ×1
firefox ×1
function ×1
post ×1
tampermonkey ×1