Recent posts by itsjareds

Subscribe to Recent posts by itsjareds 47 posts found

Sep 15, 2008
itsjareds 47 posts

Topic: Script development / Namespace is not working?

Thanks -- I remember reading that but I guess I forgot. Too bad the namespace does not work for this reason too.

 
Sep 14, 2008
itsjareds 47 posts

Topic: Script development / Namespace is not working?

I need to have my users update my script every time I release a new one, so I created an auto-updater. It works fine, but my only problem now is it creates a new userscript when I install the new one.

I think I am using the namespace right, can anyone see what's wrong? This is the metadata for my older and newer version:

Old version:

// ==UserScript==
// @name Spogg Improvement Pack v1.3.0
// @namespace http://itsjareds.scienceontheweb.net/misc/sip/
// @version 1.3.0
// @author KnifeySpooney
// @description Adds features to the online community Spogg.
// @include http://*.spogg.com/*
// ==/UserScript==

New version:

// ==UserScript==
// @name Spogg Improvement Pack v1.3.1
// @namespace http://itsjareds.scienceontheweb.net/misc/sip/
// @version 1.3.1
// @author KnifeySpooney
// @description Adds features to the online community Spogg.
// @include http://*.spogg.com/*
// ==/UserScript==

And yes, both of the files are in http://itsjareds.scienceontheweb.net/misc/sip/ .

 
Sep 14, 2008
itsjareds 47 posts

Topic: Script development / url

I love using this site for testing javascript regular expressions - http://www.regexpal.com

 
Aug 18, 2008
itsjareds 47 posts

Topic: Script development / Scripts do everything twice

I had this problem so added a check to my script
if (window != window.top) return;

Thanks, it started happening again and that fixed it.

 
Aug 17, 2008
itsjareds 47 posts

Topic: Script development / Scripts do everything twice

Are you running Firebug and is the console active for that site ? If yes, try disable console as FB can cause this "double load" behaviour.

Thanks, that seemed to do it.

 
Aug 17, 2008
itsjareds 47 posts

Topic: Script development / Monitoring page JS?

You could put at the end of each script:
GM_log("Greasemonkey script [your script here] executed.");

Is this what you meant? If you have a lot of scripts installed, this may be a problem.

 
Aug 17, 2008
itsjareds 47 posts

Topic: Script development / Writing to File

Not directly without making your script a FF extension. Otherwise, any web page could do this to you, and there's obviously security issues there.

 
Aug 17, 2008
itsjareds 47 posts

Topic: Ideas and script requests / Set wmode="transparent" for flash players. Please.

Lol. Difference made.

 
Aug 17, 2008
itsjareds 47 posts

Topic: Ideas and script requests / how to remove <meta bla bla bla > tag ??

To write it yourself, try this:

var metas = document.getElementsByTagName("meta");

for (var a=0; a<metas.length; a++) {
  if (metas[a].http-equiv.match(/refresh/))
    document.getElementsByTagName("head")[0].removeChild(metas[a]);
}

Not been tested, but should work. Someone please correct me if I'm wrong.

 
Aug 17, 2008
itsjareds 47 posts

Topic: Script development / Getting headers of a script?

How can I get the headers of a script with a function inside the same script?

By headers I mean this text:

// ==UserScript==
// @name Blah
// @namespace Blah
// @description Blah
// @include Blah
// ==/UserScript==

I need to get some info called @version, how can I do this?

Edit: Also, I would like to know how to check if another script is installed. Thanks!

 
Aug 14, 2008
itsjareds 47 posts

Topic: Script development / Scripts do everything twice

Sorry for the late reply.. lost track of this thread. Needs to be a "Search your posts" option.
Could the script be running on two frames in the window?
Nope, there aren't any frames on this site.

Are you using FF3?
Yes, v3.0.1
 
Aug 11, 2008
itsjareds 47 posts

Topic: Script development / How to catch any error?

How can I catch an error and give custom feedback in the error console?

I know there is try and catch(), but how could I write it to, instead of stopping the complete script on an error, give an error message in the console about that one thing?

 
Aug 11, 2008
itsjareds 47 posts

Topic: Script development / Scripts do everything twice

My scripts are doing everything twice.. I made sure by putting GM_log("this is a test") at the head of my script, and each time I load a page, that message comes up twice.

There aren't two of my scripts or anything, just one. I'm not sure if this is slowing it down or not. Does anyone else see this?

 
Jul 28, 2008
itsjareds 47 posts

Topic: Script development / Getting previous node

I got it working using what gollum said, I was going to try that later but I had to run.

@RunningBlind: It is searching for any element with the class "mini", which was the <font></font> tag.

Thanks for the help everyone :)

Thanks also to gollum for the DOM Inspector.. will use often

 
Jul 28, 2008
itsjareds 47 posts

Topic: Script development / Getting previous node

bump

 
Jul 27, 2008
itsjareds 47 posts

Topic: Script development / CSS Url Replacement

var rel = document.getElementsByTagName("link");
for (var a=0; a < rel.length; a++) {
  if (rel[a].href == "the default href") {
    rel[a].href = "your url";
  }
}

Although I recommend you use Stylish (download link), it's another Firefox addon that edits stylesheets. You can change any CSS on a page with the !important option.

 
Jul 27, 2008
itsjareds 47 posts

Topic: Script development / Getting previous node

I'm making a user script to remove a link on a page, but surrounding it are two
tags. I also need to get rid of these tags. I tried going about doing it by using previousSibling, but it doesn't work.. at least not the way I'm doing it. This is the HTML I am changing:

<br />
<font class="mini">
<a href="settings.php">edit</a>
</font>
<br />

and this is the JavaScript:

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\\\s)"+searchClass+"(\\\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

var link = getElementsByClass('mini')[0];
link.style.display = "none";
link.previousSibling.style.display = "none";

Does anybody have a better way of doing it?
 
Jul 23, 2008
itsjareds 47 posts

Topic: Script development / Help with smiley replacement?

I tested the regex using RegexPal, and the regular expressions are not the problem. And thanks for the blockquote help

 
Jul 23, 2008
itsjareds 47 posts

Topic: Script development / Help with smiley replacement?

I mean what znerp did, with the green? Or is that not a quote?

 
Jul 22, 2008
itsjareds 47 posts

Topic: Script development / Help with smiley replacement?

Have you done some GM_log(...)'s to find if your getting what you expect from your regex expressions?

I did now that you told me to. It says that for every time it goes through the
for(var i = smileElements.snapshotlength - l; i >= 0; i--) part, it goes through the smileyRegex.lastIndex = 0; part twice.

What page are you testing this against?
Forum: Test: :P*:P* - Spogg.com

 
Jul 22, 2008
itsjareds 47 posts

Topic: Script development / Help with smiley replacement?

no, i changed a few of the smilies and their text emotes

 
Jul 22, 2008
itsjareds 47 posts

Topic: Script development / Help with smiley replacement?

please?

 
Jul 22, 2008
itsjareds 47 posts

Topic: Script development / Help with smiley replacement?

Hi, I am writing a script that replaces text smilies with images using Smilize. It worked right out-of-the-box, but I edited it some (mostly regex) and now it's not working.

Can anyone see what's wrong with this script?


function smilize() {
	try {
/*
	Regular Expressions to match all the smileys.
	// [\(\*\:;8][\w]*[dpo\)\(]?\*?(?![\w])(?![\/\/])
*/
		var smileyRegex = /((\*[\d\w]*\*)|[:;][\w()])/gi;
/*
	Regular Expression to match smiley if it is at the starting of line.
*/
		var smileyAtStartRegex = /^((((?:\*)[:;][\w()](?:\*)|[:;][\w()]))|(\*[\w]*\*))/i;
/*
	Regular Expressions to match individual smileys.
*/
		var smileysRegex = [ /:\)/ , /;\)/ , /:D/i , /:P/i , /:\(/ , /:o/i , /\*ill\*/i , /\*cool\*/i ,
 /\*yawn\*/i , /\*mad\*/i , /\*cry\*/i , /\*blush\*/i , /\*confused\*/i , /\*love\*/i ,
 /\*mean\*/i , /\*glad\*/i ];

/*
	DATA URIs for holding the smiley image data to be embedded into the page.
	Naming convention used is self explanatory.
	DATA URI generation courtesy - http://software.hixie.ch/utilities/cgi/data/data
*/
		var smileys = [ "data:image/gif;base64,R0lGODlhEYYOhETY0gCIT49 ... (large array of data:uris)" ];

/*
	XPath for getting all the text nodes in the html document containing the smileys.
*/
		var smileElements = document.evaluate("//text()[not(ancestor::script) "+
								"and not(ancestor::style) " + 
								"and not(ancestor::textarea) " +
								"and (contains(., ':)' ) " +
								"or contains(., ';)' ) " +
								"or contains(., ':D' ) " +
								"or contains(., ':d' ) " +
								"or contains(., ':P' ) " +
								"or contains(., ':p' ) " +
								"or contains(., ':(' ) " +
								"or contains(., ':o' ) " +
								"or contains(., ':O' ) " +
								"or contains(., '*cool*' ) " +
								"or contains(., '*yawn*' ) " +
								"or contains(., '*cry*' ) " +
								"or contains(., '*love*' ) " +
								"or contains(., '*confused*' ) " +
								"or contains(., '*mad*' ) " +
								"or contains(., '*ill*' ) " +
								"or contains(., '*glad*' ) " +
								"or contains(., '*blush*' ) " +
								"or contains(., '*mean*' ) ) ] ",
							document,
							null,
							XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
							null);

/*
	Beginning traversing through the element nodes that the XPath expression returned.
	I choose to go from last node to first node so as to avoid any discrepancies since
	I will be adding nodes to the document and editing it's structure.
*/
		for(var i = smileElements.snapshotLength - 1;i >= 0; i--) {	
			var elm = smileElements.snapshotItem(i);
			if(smileyRegex.test(elm.nodeValue)) {
				var elmSpan = document.createElement("span");
				elm.parentNode.replaceChild(elmSpan, elm);
				var text = elm.nodeValue;
/*
	Checking if smiley is at the starting of the line.
	If found replace it with appropriate smiley and then alter the 'text' of the element
	node cached to incorporate it having been replaced by an appropriate smiley.
*/
				if(smileyAtStartRegex.test(text)) {
					var smiley = smileyAtStartRegex.exec(text);
					text = text.substring(text.indexOf(smiley)+smiley.length+1);
					var smileyData=getSmiley(smileysRegex, smileys, smiley);
					var elmSmile = document.createElement("img");
					elmSmile.setAttribute("src", smileyData);
					elmSmile.setAttribute("align", "center");
					elmSmile.style.border = "none";
					elmSpan.appendChild(elmSmile);
				}
/*
	Setting the Smiley Regular Expression's lastIndex to 0 to start traversing through
	all the smileys that occur in the text node using 'exec' function.
*/
				smileyRegex.lastIndex = 0;
				for(var match = null, lastLastIndex = 0; (match = smileyRegex.exec(text)); ) {
					elmSpan.appendChild(document.createTextNode(text.substring(lastLastIndex, match.index)+RegExp.$1));
					var smiley = text.substring(match.index,smileyRegex.lastIndex);
					var smileyData=getSmiley(smileysRegex, smileys, smiley);
					var elmSmile = document.createElement("img");
					elmSmile.setAttribute("src", smileyData);
					elmSmile.setAttribute("align", "center");
					elmSmile.style.border = "none";
					elmSpan.appendChild(elmSmile);
					lastLastIndex = smileyRegex.lastIndex;
				}
				elmSpan.appendChild(document.createTextNode(text.substring(lastLastIndex)));
				elmSpan.normalize();
			}
/*
	Case when the smiley at the start is the only smiley in that particular node.
*/
			else if(smileyAtStartRegex.test(elm.nodeValue)) {
				GM_log(elm.nodeValue);
				var elmSpan = document.createElement("span");
				elm.parentNode.replaceChild(elmSpan, elm);
				var smiley = smileyAtStartRegex.exec(elm.nodeValue);
				var smileyData=getSmiley(smileysRegex, smileys, smiley);
				var elmSmile = document.createElement("img");
				elmSmile.setAttribute("src", smileyData);
				elmSmile.setAttribute("align", "center");
				elmSmile.style.border = "none";
				elmSpan.appendChild(elmSmile);
				elmSpan.appendChild(document.createTextNode(elm.nodeValue.substring(elm.nodeValue.indexOf(smiley)+smiley.length+1)));
				elmSpan.normalize();
			}
		}
	} catch (e) {
		GM_log(e);	//Catch and log any errors if encountered during the entire process.
	}
}

/*
	function to get the appropriate smiley from smileys array, by matching the smiley with
	each smileys regular expression.
*/
function getSmiley(smileysRegex, smileys, smiley) {
	for(var j=0;j<smileys>

 
Jul 20, 2008
itsjareds 47 posts

Topic: Script development / Replace text with smilies

Also, is there any way to do all the smilies at once, rather than the same function over and over?

 
Jul 20, 2008
itsjareds 47 posts

Topic: Script development / Replace text with smilies

I can't figure out how to incorporate that into my script. How could I change it to adding an image instead?