1

此页面加载时,我想模拟send me this thing在新窗口(或新选项卡)中打开按钮时自动单击按钮

  • send me this thing这样的任何页面上都只会有一个按钮

做什么的?

这适用于 Fluid.app 上的Greasekit,类似于 Greasemonkey。

4

1 回答 1

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 ();

但是,请注意现代弹出窗口阻止程序会阻止这一点,我不知道嵌入在您的 Fluid 版本中的 webkit。告诉您的弹出窗口阻止程序允许这些特定的弹出窗口。

另外,因为这是 Greasekit,你需要注入上面的代码,所以完整的用户脚本会是这样的:

// ==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);
}
于 2013-10-25T02:17:51.013 回答