[Help] - Converting Greasmonkey script

General questions about scripts and buttons should be asked here. Development scripts and buttons may also be posted for feedback.

Moderators: Support Staff², Support Staff, AvantGuard, Developer

Post Reply
fatoms
Newbie
Newbie
Posts: 14
Joined: Thu Nov 06, 2008 11:56 pm
Windows Version: Windows 8 64Bit (6.2.9200)
Avant Version: 2013 Build 23
Default engine: IE
IE Version: 10.0.9200.16519
Skin: Monai XP

[Help] - Converting Greasmonkey script

Post by fatoms » Fri Apr 15, 2011 8:47 am

Hi All,

I am attempting to convert a script (full listing at end of post )for use with Avant.

The start I have gives me (alerts to help me debug):

(function (){
var subreggix = /self./i;
alert (subreggix)
var matches=0;
alert (matches)
var xpath = "//p[@class='title']/span[@class='domain']";
alert (xpath)
})();

When I add either of the next line so that I have
(function (){
var subreggix = /self./i;
alert (subreggix)
var matches=0;
alert (matches)
var xpath = "//p[@class='title']/span[@class='domain']";
alert (xpath)
var rows = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
alert (rows)
})();

I do not get the alert alert (rows)

Can anyone offer any guidance on why this might be?

Dominic

ORIGINAL SCRIPT:
// ==UserScript==
// @name Self-Post Filter
// @namespace http://reddit.com
// @description Automatically hides self-post stories
// @include http://reddit.com/*
// @include http://*.reddit.com/*
// @exclude http://reddit.com/user/*
// @exclude http://*.reddit.com/user/*
// @exclude http://reddit.com/info/*
// @exclude http://*.reddit.com/info/*
// @exclude http://reddit.com/r/*/related/*
// @exclude http://*.reddit.com/r/*/related/*
// ==/UserScript==
// Based off of Reddit Content Filter


// Edit this line to include whichever subreddits you want to filter out

var subreggix = /self./i;
var matches=0;
var xpath = "//p[@class='title']/span[@class='domain']";
var rows = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

for (var i = 0; i < rows.snapshotLength; i++) {
var row = rows.snapshotItem(i);
var text = row.childNodes[1].innerHTML;
if (subreggix.exec(text)) {
row.parentNode.parentNode.parentNode.style.display = 'none';
matches+=1;
}
}

if (matches > 0) {
var tbl = document.getElementById('siteTable'),
div = document.createElement('div'),
msg = '' + matches + ' post(s) were removed from this page';
GM_log(msg);
if (!tbl) return;
div.innerHTML = '<p><i>' + msg + ' (Reddit Content Filter).</i></p>';
tbl.parentNode.insertBefore(div, tbl.nextSibling);
}

END OF ORIGINAL SCRIPT

User avatar
sulpherdragon
Contributor
Contributor
Posts: 222
Joined: Sat Dec 15, 2007 9:51 pm
Windows Version: Windows 7
Avant Version: 2013 Build 23
Default engine: Firefox
IE Version:
Skin:
Contact:

Re: [Help] - Converting Greasmonkey script

Post by sulpherdragon » Mon Apr 18, 2011 4:41 pm

There is a javascript standard, and no one is following it. Thus you get things like this, were code will work in one browser and not in the other.
The reason is because the IE document object model and the Gecko (Firefox) document object model are a little bit different.
Your second rows alert isn't happening because IE is breaking when it sees: document.evaluate.
That function does not exist in IE and you will need a workaround to fix it.
You should search for equivalents, but you might come up with different answers depending on what actual end result your code is attempting to get.

If I get time I'll take a better look at the specific code, but you should look for alternatives to "document.evaluate" in IE.
Image

fatoms
Newbie
Newbie
Posts: 14
Joined: Thu Nov 06, 2008 11:56 pm
Windows Version: Windows 8 64Bit (6.2.9200)
Avant Version: 2013 Build 23
Default engine: IE
IE Version: 10.0.9200.16519
Skin: Monai XP

Re: [Help] - Converting Greasmonkey script

Post by fatoms » Thu Apr 21, 2011 9:32 am

sulpherdragon,

Thanks for the information. Will lookinto what alternatives are available in IE.

Dominic.

Post Reply