N
Newton
I'm having some issues with a greasemonkey script i've made (nothing
serious, and you'll notice that by the mess). I made it to learn
javascript properly at first but it ended handy and now i'm addicted to
it.. However, it doesn't quite work like i'd expect it to (and like it
used to with older versions) I realise that it may be a
greasemonkey-specific question, please bare with me if it is. I figured
some of you guys may have used it before considering it uses JS.
Problem: The first time i load the page it works perfectly (albeit
somewhat slowly; i bet there's fasters ways to do this.). However as
soon as i try another page within the same firefox session the script
seems to be called an indefinite amount of time. I have no idea why, i
tried some other way (that i know of) mainly associating the function
with the load event and not putting the code within the anonymous
function. They all came back with the same problem.
Unfortunately it can't be tested unless you're a newzbin.com prenium
member. I'm hoping it's something obvious about the javascript. If you
guys need to test, let me know and i'll mirror a test page.
Any help would be apreciated at this point, thanks in advance!
Here's the victim:
<pre>
// ==UserScript==
// @name Newton's Newzbin Mods
// @description Make various modifications to newzbin website.
// @include http://*newzbin.com*
// ==/UserScript==
(function() {
window.getElementsByClassName = function(clsName) {
var i, matches=new Array();
var els=document.getElementsByTagName('*');
for(i=0; i<els.length; i++) {
if(els.item(i).className==clsName) {
matches.push(els.item(i));
}
}
return matches;
}
window.Left = function(str, n) {
if (n <= 0)
return "";
else if (n > String(str).length)
return str;
else
return String(str).substring(0,n);
}
window.hideFunctionBar = function() {
var els=getElementsByClassName("invisible");
var htmlString;
for(i=0; i<els.length; i++) {
htmlString = Left(els.innerHTML, 50);
GM_log(htmlString.indexOf("["));
if (htmlString.indexOf("[") == 22)
els.style.display="none";
}
}
/*window.hideshows = function() {
if (hideShow == "hide") {
hideShow = "show";
document.getElementById('hideshow').innerHTML = 'S<br />H<br />O<br />W';
forminput = getElementsByClassName("forminput")[0];
forminput.style.display = "none";
} else {
hideShow = "hide";
document.getElementById('hideshow').innerHTML = 'H<br />I<br />D<br />E';
forminput = getElementsByClassName("forminput")[0];
forminput.style.display = "block";
}
}*/
var forminput = getElementsByClassName("forminput")[0];
if (!forminput) {return;}
var header = document.getElementById("newzBin");
getElementsByClassName("logo")[0].style.display = "none";
forminput.style.position = "fixed";
forminput.style.zindex = 700;
forminput.style.top = 0;
forminput.style.left = 0;
forminput.style.width = header.offsetWidth - 140 + "px";
forminput.style.marginLeft = "140px";
var tr = '<tr><td colspan="3">' +
'[<a href="/media/help/editor_buttons.html" onclick="openwin(href);
return false">?</a>]' +
'<span style="padding: 1px; border: 1px solid gray">' +
'<select name="tl" >' +
'<option value="1" >1</option>' +
'<option value="2" >2</option>' +
'<option value="3" >3</option>' +
'<option value="4" >4</option>' +
'<option value="5" >5</option>' +
'</select>' +
'<input type="submit" name="tag" value="Tag" />' +
'<input type="submit" name="tag_view" value="Tag & View" />' +
'</span>' +
' ' +
'<span style="padding: 1px; border: 1px solid gray">' +
'<input type="submit" name="hide" value="Hide" /> for ' +
'<input type="text" name="hideduration" value="60" size="2" /> mins' +
'</span>' +
' ' +
'<span style="padding: 1px; border: 1px solid gray">' +
'<input type="submit" name="junk" value="Junk" />' +
'<input type="submit" name="unjunk" value="unJunk" />' +
'</span>' +
' ' +
'<span style="padding: 1px; border: 1px solid gray">' +
'<input type="submit" name="msgid" value="Message-IDs" />' +
'</span>' +
'</td>' +
'<td class="Right" colspan="5">' +
'[<a href="/media/help/select_links.html" onclick="openwin(href);
return false">?</a>] ' +
'<a href="javascript:checkAll(\'FileActions\')">all</a> ' +
'<a href="javascript:invert(\'FileActions\')">inv</a> ' +
'<a href="javascript:uncheckAll(\'FileActions\')">none</a> ' +
'<a href="javascript:checkRanges(\'FileActions\')">range</a>' +
'</td></tr>';
forminput.innerHTML += tr;
var OSHeight = header.offsetHeight - forminput.offsetHeight;
header.innerHTML = '<div style="margin-top:' + forminput.offsetHeight +
'px;>' + header.innerHTML + '</div>';
hideFunctionBar();
})();</pre>
serious, and you'll notice that by the mess). I made it to learn
javascript properly at first but it ended handy and now i'm addicted to
it.. However, it doesn't quite work like i'd expect it to (and like it
used to with older versions) I realise that it may be a
greasemonkey-specific question, please bare with me if it is. I figured
some of you guys may have used it before considering it uses JS.
Problem: The first time i load the page it works perfectly (albeit
somewhat slowly; i bet there's fasters ways to do this.). However as
soon as i try another page within the same firefox session the script
seems to be called an indefinite amount of time. I have no idea why, i
tried some other way (that i know of) mainly associating the function
with the load event and not putting the code within the anonymous
function. They all came back with the same problem.
Unfortunately it can't be tested unless you're a newzbin.com prenium
member. I'm hoping it's something obvious about the javascript. If you
guys need to test, let me know and i'll mirror a test page.
Any help would be apreciated at this point, thanks in advance!
Here's the victim:
<pre>
// ==UserScript==
// @name Newton's Newzbin Mods
// @description Make various modifications to newzbin website.
// @include http://*newzbin.com*
// ==/UserScript==
(function() {
window.getElementsByClassName = function(clsName) {
var i, matches=new Array();
var els=document.getElementsByTagName('*');
for(i=0; i<els.length; i++) {
if(els.item(i).className==clsName) {
matches.push(els.item(i));
}
}
return matches;
}
window.Left = function(str, n) {
if (n <= 0)
return "";
else if (n > String(str).length)
return str;
else
return String(str).substring(0,n);
}
window.hideFunctionBar = function() {
var els=getElementsByClassName("invisible");
var htmlString;
for(i=0; i<els.length; i++) {
htmlString = Left(els.innerHTML, 50);
GM_log(htmlString.indexOf("["));
if (htmlString.indexOf("[") == 22)
els.style.display="none";
}
}
/*window.hideshows = function() {
if (hideShow == "hide") {
hideShow = "show";
document.getElementById('hideshow').innerHTML = 'S<br />H<br />O<br />W';
forminput = getElementsByClassName("forminput")[0];
forminput.style.display = "none";
} else {
hideShow = "hide";
document.getElementById('hideshow').innerHTML = 'H<br />I<br />D<br />E';
forminput = getElementsByClassName("forminput")[0];
forminput.style.display = "block";
}
}*/
var forminput = getElementsByClassName("forminput")[0];
if (!forminput) {return;}
var header = document.getElementById("newzBin");
getElementsByClassName("logo")[0].style.display = "none";
forminput.style.position = "fixed";
forminput.style.zindex = 700;
forminput.style.top = 0;
forminput.style.left = 0;
forminput.style.width = header.offsetWidth - 140 + "px";
forminput.style.marginLeft = "140px";
var tr = '<tr><td colspan="3">' +
'[<a href="/media/help/editor_buttons.html" onclick="openwin(href);
return false">?</a>]' +
'<span style="padding: 1px; border: 1px solid gray">' +
'<select name="tl" >' +
'<option value="1" >1</option>' +
'<option value="2" >2</option>' +
'<option value="3" >3</option>' +
'<option value="4" >4</option>' +
'<option value="5" >5</option>' +
'</select>' +
'<input type="submit" name="tag" value="Tag" />' +
'<input type="submit" name="tag_view" value="Tag & View" />' +
'</span>' +
' ' +
'<span style="padding: 1px; border: 1px solid gray">' +
'<input type="submit" name="hide" value="Hide" /> for ' +
'<input type="text" name="hideduration" value="60" size="2" /> mins' +
'</span>' +
' ' +
'<span style="padding: 1px; border: 1px solid gray">' +
'<input type="submit" name="junk" value="Junk" />' +
'<input type="submit" name="unjunk" value="unJunk" />' +
'</span>' +
' ' +
'<span style="padding: 1px; border: 1px solid gray">' +
'<input type="submit" name="msgid" value="Message-IDs" />' +
'</span>' +
'</td>' +
'<td class="Right" colspan="5">' +
'[<a href="/media/help/select_links.html" onclick="openwin(href);
return false">?</a>] ' +
'<a href="javascript:checkAll(\'FileActions\')">all</a> ' +
'<a href="javascript:invert(\'FileActions\')">inv</a> ' +
'<a href="javascript:uncheckAll(\'FileActions\')">none</a> ' +
'<a href="javascript:checkRanges(\'FileActions\')">range</a>' +
'</td></tr>';
forminput.innerHTML += tr;
var OSHeight = header.offsetHeight - forminput.offsetHeight;
header.innerHTML = '<div style="margin-top:' + forminput.offsetHeight +
'px;>' + header.innerHTML + '</div>';
hideFunctionBar();
})();</pre>