views:

82

answers:

1

I found a GreaseMonkey script on Userscripts which corrects spelling and some grammar which I'm trying to improve for use on Reddit etc. I've had some help from there improving it, and this is my current version which does work quite well.

There is, however, a problem in that it capitalises italics, bold and links. I would like to have the script ignore all child nodes, or at least those which are em (italic), strong (bold) or a (link). I've tried a lot of searching and reading, but I've not yet found a way to do this. It seems that for other purposes everyone wants their script to work on children as well.

I imagine there are different ways of doing this - perhaps prevent it including them in the first place, strip them out straight after that, or prevent the replacement loop working on them if they meet some criteria. Unfortunately I'm not very experienced in javascript, hence why I'm asking here.

A: 

try changing your xpath from

//div[@class='md']//text()

to

//div[@class='md']//*[not(self::em or self::strong or self::a)]/text()

this should prevent all em, strong, and a nodes from being changed.

ax
I just tested that on:http://www.reddit.com/r/GreaseMonkey/comments/9yehr/im_trying_to_get_a_greasemonkey_script_that/c0f1kwhUnfortunately it doesn't exclude them. I tried some variations too without any success.
Little_Kitty
i just updated my answer with an xpath that works for me on http://www.reddit.com/r/GreaseMonkey/comments/9yehr/im_trying_to_get_a_greasemonkey_script_that/c0f1kwh .
ax
That's brilliant! I've been reading for weeks trying to find a solution to this, and you've solved it really quickly. I've not seen that syntax before though, do you know of a good site which explains it? (Google removes the colons when searching).
Little_Kitty
the google query that helped me is "xpath exclude elements" (and the first hit is on SO) :)
ax