473,383 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Greasemonkey user script: Infinite loop?

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[i].innerHTML, 50);
GM_log(htmlString.indexOf("["));
if (htmlString.indexOf("[") == 22)
els[i].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 &amp; View" />' +
'</span>' +
'&nbsp;' +
'<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>' +
'&nbsp;' +
'<span style="padding: 1px; border: 1px solid gray">' +
'<input type="submit" name="junk" value="Junk" />' +
'<input type="submit" name="unjunk" value="unJunk" />' +
'</span>' +
'&nbsp;' +
'<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>]&nbsp;&nbsp;' +
'<a href="javascript:checkAll(\'FileActions\')">all</a>&nbsp;&nbsp;' +
'<a href="javascript:invert(\'FileActions\')">inv</a>&nbsp;&nbsp;' +
'<a href="javascript:uncheckAll(\'FileActions\')">none </a>&nbsp;&nbsp;' +
'<a href="javascript:checkRanges(\'FileActions\')">ran ge</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>
Sep 21 '05 #1
2 5778
Newton wrote:
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: [...]

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">' +
[... large slab of concatenated HTML removed ...]
href="javascript:invert(\'FileActions\')">inv</a>&nbsp;&nbsp;' +
'<a
href="javascript:uncheckAll(\'FileActions\')">none </a>&nbsp;&nbsp;' +
'<a href="javascript:checkRanges(\'FileActions\')">ran ge</a>' +
'</td></tr>';
forminput.innerHTML += tr;


Without testing anything, and ignoring many minor transgressions, I'd
say your major problem is trying to modify a table using innerHTML.

Create an element factory for your A, TD and TR elements and add them
using DOM. There have been many recent posts attempting to modify
tables using innerHTML, do a search.

While you're at it, how about getting rid of the A elements with
javascript pseudo-protocol href attributes? Try an appropriately styled
div or span with an onclick instead.

[...]

--
Rob
Sep 21 '05 #2
Newton <ne**********@gmail.com.removeANTISPAMme> writes:

Small comment:
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) {
Remember that the class attribute is a space separated sequence of
class names, not necessarily a single one. For that reason, I would
do:

var clsNameRE = new RegExp("\\b"+clsName+"\\b",""); for(i=0; i<els.length; i++) {
if(clsNameRE.test(els.item(i).className)) {


/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Sep 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
27
by: Scott | last post by:
I've been trying to come up with a way to ensure user input is coming from the form on my site, and not auto-submitted from elsewhere, and I don't want to use the "enter the code shown in the...
1
by: jeffrey4 | last post by:
I'm trying to write a script (my first) that loops through some table rows and gets some data from another page using gm_xmlhttprequests. It works if I keep the loop to one, but if I try and loop...
2
by: 9icj4u613jeqrx8 | last post by:
Hi, I need some help with IE browser programming (in .NET). I'm trying to add a button to the IE toolbar, and on the click of the button open a popup window with a remote URL. Secondly, I'm...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
1
by: steevan16 | last post by:
Hi, Not sure if I am in the right section. Just have a query about manipulating excel spreadsheet using vbscript. I am developing a vbscript which runs on client xp machines to retrieve certain...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.