2015-04-28 64 views
2

我使用tampermonkey在网站上运行一些脚本。Tampermonkey,用户脚本添加URL到脚本的POP UP

现在我要把它,只要你要去到特定的页面(“example.com”)

U将得到一个弹出,其中u可以按下yes或no。

是=添加的URL tampermonkey脚本的用户包括(脚本会比这个URL运行) 否=不添加

无法找到在互联网上这个问题的文件,所以我想知道如果有人有任何建议?

+0

您是否尝试过使用'确认()'? –

+0

是打开弹出不是问题。将URL添加到userscript是我不知道如何解决 – Lozeputten

+0

我不认为脚本可以通过脚本更改它的设置... – dandavis

回答

0

由于我不认为您可以动态添加规则,即包含的网址,因此您必须先解决一个解决方法。

将以下内容添加到您的用户脚本标题中。

// @match * 
// @grant GM_setValue 
// @grant GM_getValue 

以下代码将包含一个URL。

function includeUrl(url) { 
    var includes = JSON.parse(GM_getValue('includes')) || []; 
    includes.push(url); 
    GM_setValue('includes', JSON.stringify(includes)); 
} 

以下代码将确定脚本是否应该运行。

function shouldRun() { 
    var includes = JSON.parse(GM_getValue('includes')); 
    if (includes) { 
    var url = window.location.href; 
    if (includes.indexOf(url) > -1) { 
     return true; 
    } 
    } 
    return false; 
} 

拼接起来

// prompt user if they want to include Url (use includeUrl) 

if (!shouldRun()) return; // prevent execution  

// your code ...