可以将此书签转换为Greasemonkey用户脚本吗?

adi*_*adi -3 javascript bookmarklet userscripts

我不太确定如何将此代码从小书签转换为用户脚本,因为它使用URL编码的字符:

javascript:var%20multiURL="";%20$('div.titlebox').find('ul.subreddits').find('a').each(function()%20{%20multiURL%20+=%20$(this).text().substr(3)%20+%20"+";%20});%20multiURL%20=%20multiURL.substr(0,multiURL.length-1);%20window.open('http://www.reddit.com/r/'+multiURL);void(0);
Run Code Online (Sandbox Code Playgroud)

有想法吗?

Ast*_*oCB 5

首先,您必须将URL编码的字符转换为常规字符,Jared Farrish 很好地 使用了一些PHP向导。如果将来需要这样做,可以尝试使用此在线URL编码器/解码器

这给了你这个JavaScript blob:

javascript:var multiURL=""; $('div.titlebox').find('ul.subreddits').find('a').each(function() { multiURL += $(this).text().substr(3) + "+"; }); multiURL = multiURL.substr(0,multiURL.length-1); window.open('http://www.reddit.com/r/'+multiURL);void(0);
Run Code Online (Sandbox Code Playgroud)

格式化并转换为适当的JS:

var multiURL = "";
$('div.titlebox').find('ul.subreddits').find('a').each(function () {
    multiURL += $(this).text().substr(3) + "+";
});
multiURL = multiURL.substr(0, multiURL.length - 1);
window.open('http://www.reddit.com/r/' + multiURL);
Run Code Online (Sandbox Code Playgroud)

然后,剩下要做的就是使用用户脚本符号,并将其保存在名称以.user.js(重要)结尾的文件中

// ==UserScript==
// @name           Author's Name
// @namespace      Place where file is stored
// @include        Place(s) where userscript should run
// ==/UserScript==

var multiURL = "";
$('div.titlebox').find('ul.subreddits').find('a').each(function () {
    multiURL += $(this).text().substr(3) + "+";
});
multiURL = multiURL.substr(0, multiURL.length - 1);
window.open('http://www.reddit.com/r/' + multiURL);
Run Code Online (Sandbox Code Playgroud)

请务必注意,此操作将在列出的每个地址上@include运行,因此您可能要考虑在相关页面上注入按钮或其他内容,以免不必要地运行它。