當this page負荷,我想自動模擬點擊send me this thing
按鈕,同時有它在新窗口中打開(或新標籤)使用JavaScript在給定的按鈕,點擊並讓它在新窗口中
-
打開
- 在這樣的任何頁面上只會有一個
send me this thing
按鈕
什麼?
這是用於Greasekit的Fluid.app,與Greasemonkey類似。
當this page負荷,我想自動模擬點擊send me this thing
按鈕,同時有它在新窗口中打開(或新標籤)使用JavaScript在給定的按鈕,點擊並讓它在新窗口中
send me this thing
按鈕這是用於Greasekit的Fluid.app,與Greasemonkey類似。
該按鈕是一個鏈接,該頁面使用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);
}
謝謝,我實際上能夠使用你給出的3行代碼而沒有任何問題(換句話說,我不需要做注入) –
這很有趣,如果可以的話,看看Fluid + Greasekit是否包括jQuery自動(好),或者如果它自動運行頁面範圍內的腳本(非常糟糕)。 –
令人困惑的是,我剛剛嘗試過,並且在您的答案工作中都沒有提供**選項。 (當我嘗試它並且它工作時,我喝醉了嗎?) –
你有過連接監聽器按鈕的過程控制? – plalx