[英]My Greasemonkey script is not finding the elements (links) on the page?
[英]Click many links, in one page, with a Greasemonkey script?
我是3個網站的管理員,我的工作是刪除不需要的項目,通常單擊每個標記為“刪除”的項目。 我想使過程自動化。 試圖使用一些自動化程序(宏記錄器),但它們是靜態的。
我不是Greasemonkey編碼員,並且感謝有人可以給我一個從哪里開始的想法,
網址格式:
<a class="delete" href="http://www.domain.com/#!/item/delete/{id}">Delete</a>
我想在有class="delete"
地方單擊Delete鏈接。
每頁包含20個鏈接。
單擊“刪除”鏈接時,頁面不會刷新,jQuery。
var all = document.getElementsByClassName("delete");
for(var i=0; i<all.length; i++) {
var deleteUrl = all[i].href;
var ifr = document.createElement("IFRAME");
document.body.appendChild(ifr);
ifr.src = deleteUrl;
}
您可以在瀏覽器的JavaScript控制台中運行類似上述的簡單腳本,也可以將其設置為書簽。
另請參見“如何使Greasemonkey一次單擊許多鏈接?” 。
由於每個“刪除”按鈕都會打開一個新頁面,因此直接單擊將從當前頁面導航。 因此,改為在<iframe>
打開鏈接。
使用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; \
} \
" );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.