另请参阅“如何让 Greasemonkey 一个一个地点击大量链接?” .
由于每个“删除”按钮都会打开一个新页面,因此直接单击将从当前页面导航。因此,请改为打开<iframe>
s 中的链接。
使用 jQuery 让这一切变得更简单、更健壮。这是完整的脚本...
对于一个简单的静态页面:
// ==UserScript==
// @name _Fire lots of delete buttons
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant GM_addStyle
// ==/UserScript==
var deleteLinks = $("a.delete");
deleteLinks.each ( function () {
if (this.href) {
$("body").append (
'<iframe class="gmDelIfr" src="' + this.href + '"></iframe>'
);
}
} );
//-- Use whatever CSS you desire. Like `display: none;`, for example.
GM_addStyle ( " \
iframe.gmDelIfr { \
width: 80%; \
height: 2em; \
margin: 0; \
padding: 0; \
} \
" );
对于 AJAX 驱动的页面:(也适用于静态页面)
// ==UserScript==
// @name _Fire lots of delete buttons
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
waitForKeyElements ("a.delete", clickDeleteLink);
function clickDeleteLink (jNode) {
var thisHref = jNode[0].href;
if (thisHref) {
$("body").append (
'<iframe class="gmDelIfr" src="' + thisHref + '"></iframe>'
);
}
}
//-- Use whatever CSS you desire. Like `display: none;`, for example.
GM_addStyle ( " \
iframe.gmDelIfr { \
width: 80%; \
height: 2em; \
margin: 0; \
padding: 0; \
} \
" );