2013-10-25 50 views

回答

2

該按鈕是一個鏈接,該頁面使用jQuery。所以你可以得到如下按鈕:

var buyItBtn = $("a:contains('Send me this thing')"); 

然後修改鏈接以在新標籤頁/窗口中打開。
然後點擊鏈接。

的代碼是:

//-- Note that :contains() is case-sensitive. 
var buyItBtn = $("a:contains('Send me this thing')"); 
buyItBtn.attr ("target", "_blank"); 
buyItBtn[0].click(); 

,提防現代彈出窗口攔截器會阻止這個,我不知道嵌入你的流體版本WebKit的。告訴你的彈出窗口攔截器允許這些特定的彈出窗口。

而且,因爲這是Greasekit,你需要注入上面的代碼,所以完全userscript將是這樣的:

// ==UserScript== 
// @name  _Amazon-like store, buy things in a new window 
// @include  https://dl.dropboxusercontent.com/u/5546881/* 
// @grant  GM_addStyle 
// ==/UserScript== 
/*- The @grant directive is needed to work around a design change 
    introduced in GM 1.0. It restores the sandbox. 
*/ 
function GM_main() { 
    //-- Note that :contains() is case-sensitive. 
    var buyItBtn = $("a:contains('Send me this thing')"); 
    buyItBtn.attr ("target", "_blank"); 
    buyItBtn[0].click(); 
} 

addJS_Node (null, null, GM_main); 

function addJS_Node (text, s_URL, funcToRun, runOnLoad) { 
    var D         = document; 
    var scriptNode       = D.createElement ('script'); 
    if (runOnLoad) { 
     scriptNode.addEventListener ("load", runOnLoad, false); 
    } 
    scriptNode.type       = "text/javascript"; 
    if (text)  scriptNode.textContent = text; 
    if (s_URL)  scriptNode.src   = s_URL; 
    if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()'; 

    var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement; 
    targ.appendChild (scriptNode); 
} 
+0

謝謝,我實際上能夠使用你給出的3行代碼而沒有任何問題(換句話說,我不需要做注入) –

+0

這很有趣,如果可以的話,看看Fluid + Greasekit是否包括jQuery自動(好),或者如果它自動運行頁面範圍內的腳本(非常糟糕)。 –

+0

令人困惑的是,我剛剛嘗試過,並且在您的答案工作中都沒有提供**選項。 (當我嘗試它並且它工作時,我喝醉了嗎?) –

相關問題