所以,我有這樣的腳本,將搶THIS頁假表的鏈接(在「X」是一個已登錄的用戶頁面上的鏈接)...Greasemonkey按鈕點擊處理程序不起作用?
所以我試圖用一個彈出循環的事情,布洛克幫助我爲另一個腳本...鏈接正確添加到'linksToOpen'數組(或添加按鈕,偵聽器和'openLinksInSequence'函數之前)...一切似乎都很好,我沒有錯誤信息...但我的按鈕不工作!
// ==UserScript==
// @name Unicreatures Accoplishment Checker
// @namespace http://trueidiocy.us
// @description Marks off completed accomplishments
// @include http://unicreatures.com/accomplishments.php
// @include http://www.unicreatures.com/accomplishments.php
// @include http://unicreatures.com/accomplishments.php?
// @include http://www.unicreatures.com/accomplishments.php?
// @version 1
// @grant GM_addStyle
// ==/UserScript==
var mytable = document.getElementById('right').getElementsByTagName('table')[4];
var links=mytable.getElementsByTagName('a');
var i;
var linksToOpen = [];
var mywin2 = null;
var zNode = document.createElement ('div');
zNode.innerHTML = '<button id="checkButton" type="button">'
+ 'Check Accomplishments</button>'
;
zNode.setAttribute ('id', 'checkButton');
mytable.parentNode.insertBefore(zNode, mytable);
function checkAccomplishments (zEvent) {
for(i=0;i < links.length;i++) {
if (links[i].href.indexOf('family') > -1) {
linksToOpen.push (links[i].href);
links[i].innerHTML="*";
}
}
alert(linksToOpen)
openLinksInSequence();
};
function openLinksInSequence() {
if (mywin2) {
mywin2.close();
mywin2 = null;
}
if (linksToOpen.length) {
var link = linksToOpen.shift();
mywin2 = window.open (link, "my_win2");
mywin2.addEventListener ('load', openLinksInSequence, false);
}
}
checkButton.addEventListener ("click", checkAccomplishments, true);
那麼,爲什麼我的按鈕不工作?
你有幾個問題,但最值得注意的是,你的div的'id'設置爲與你的按鈕相同。而您試圖將事件偵聽器添加到未定義的對象。 DOM元素不顯示爲JS變量。在設置事件偵聽器之前,您必須'var checkButton = document.getElementById(「checkButton」);'' – mafafu
但......但......但是......我做了它只是喜歡我的工作腳本......大聲笑......我會看看這些問題......謝謝 –
@mafafu這樣做了......謝謝...如果你添加這個答案,我會接受它 –