我想问一下是否可以构建Chrome或Greasemonkey脚本,可以打开队列中的所有弹出窗口.到目前为止,我有两个单独的脚本,但由于弹出窗口具有反垃圾邮件功能,同时不允许太多的脚本,因此效果不佳.
我想要做的是以队列方式处理弹出链接数组,并仅在前一个关闭时打开.当它归结为队列和任何类型的事件绑定时,我没有任何经验.
所以我得到的资源:
1)已准备好的链接数组
var URL_Array = [];
$('form[name="form_gallery"] .img img').each(function(i,e){
// Format URL array here
if($(this).closest('.object').children('.phs_voted_count').length == 0){
var string = e.src;
var nowBrake = string.substring(string.length-7,7);
var splited = nowBrake.split('/');
var urlStr = '/window/friend/gallery_view/'+splited[3]+'/'+splited[4]+'.html';
URL_Array[i] = urlStr;
}
});
Run Code Online (Sandbox Code Playgroud)
2)在弹出窗口中对图像进行投票的脚本
/*######################################################*/
var voteBy = '#vte_mark_12'; // Prefered vote icon
var voteDefault = '#vte_mark_5'; // Default vote icon
var voteFormLoc = 'image_voting'; // Image voting popups form
var buyExtraVote = 'image_voting_buy'; // If run out of votes buy more
var …Run Code Online (Sandbox Code Playgroud) 我想知道chrome存储安装的用户脚本的位置.
我在其他地方找不到任何答案.
我在Mac上.
我写了一个用户脚本,当按下CTRL+ SHIFT+ 时,它会对textarea中的选定文本执行某些操作B.
这是通过keypress为textarea 注册事件然后检查按下的键来完成的.为了防止浏览器处理组合键我使用的preventDefault()方法在Firefox中工作正常(库窗口没有打开,但我的代码被执行了).
但是,在Chrome中,组合键会打开书签栏,keypress甚至无法触发事件.
我想知道是否有办法在Chrome中创建这样的快捷方式.它需要使用用户脚本 - 真正的扩展不是一个选项,因为我不想为Firefox和Chrome维护两个不同的"版本".
javascript google-chrome keyboard-shortcuts javascript-events userscripts
我目前正在为某个网站编写用户脚本.我想要完成的任务需要使用页面变量和函数访问内容范围.
这种事情的标准操作过程似乎是一个<script>向DOM 注入新标记的函数,如下所示:
function injectScript(f) {
var target = document.head || document.documentElement;
var script = document.createElement("script");
script.type = "text/javascript";
script.text = "(" + f.toString() + ")();";
target.appendChild(script);
target.removeChild(script);
}
Run Code Online (Sandbox Code Playgroud)
但是,此方法不起作用,因为该网站具有内容安全策略,可防止注入的脚本标记执行!我也尝试了位置黑客(基本上location.href="javascript:someCode()"),但这也算作内联脚本,不起作用.
unsafeWindow遗憾的是只有Greasemonkey可以选择.理想情况下,我的脚本也应该与Chrome一起使用.有没有更好的方法来访问页面变量?
我编写了一个用户脚本,当我调用它时我想运行它(不是每次匹配的网页都加载).理想情况下,我想创建一个工具栏按钮来启动此脚本.如何才能做到这一点?
PS:我需要它与网页脚本在相同的上下文中运行,并能够调用嵌入其中的函数.
google-chrome userscripts google-chrome-extension tampermonkey
我正在使用以下代码编写用户脚本:
(function() {
'use strict';
window.addEventListener("keydown", arrows, false);
function arrows(e) {
debugger;
switch(e.keycode) {
case 37: alert("Left"); break;
case 39: alert("Right"); break;
}
}
})();
Run Code Online (Sandbox Code Playgroud)
最终,左侧和右侧案例将分别导航到系列中的上一篇和下一篇文章,例如:
window.location = String(parseInt(window.location.href.match(/\d+$/))-1);
Run Code Online (Sandbox Code Playgroud)
但是,按箭头键不会引起警报。脚本已明确加载,Chrome 开发人员菜单显示该arrows()函数已注册为 的事件侦听器window.keydown,但该函数从未触发。我添加debugger;了该arrows()功能,但是当我按箭头键时,调试器没有显示。
我有很多打开的网站标签 - 我想将其限制为只有一个 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)
* 和后面的任何组合都不起作用。:(
我有一个index.html调用外部 URL的页面。这个外部 URL 是一个 JSON 端点。换句话说,当我打开开发工具(使用F12)时,我看到两个资源:index.html和myJSONEndpoint。
我希望每次加载时都能获取该 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>然后将内容粘贴在那里?
我想在某人的网站中缓存特定请求,然后我发现 service worker 是一个不错的选择。但是我找不到任何通过 tampermonkey 注入 service worker 的方法。那么有没有什么技巧可以做到这一点?
我的问题非常类似于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
userscripts ×10
javascript ×6
tampermonkey ×5
greasemonkey ×2
ecmascript-6 ×1
jquery ×1
json ×1
macos ×1
match ×1
root ×1
url ×1