anka-213 / webcomic_reader

Webcomic Reader userscript at
https://openuserjs.org/scripts/anka-213/Webcomic_Reader
MIT License
120 stars 27 forks source link

Expand `var getNext`/`getBack` to catch "forward"/"backward", not just "next"/"back"? #57

Open OwenAR opened 7 years ago

OwenAR commented 7 years ago

I was trying to get this comic working (this is the first time I've tried to hack in support for a site that I can't get working just by adding it to the list of includes).

I looked at these directions (that's the link built in to the "site settings" dialog, although I don't know if it's out of date or what), and tried getting the unique CSS selectors for the "forward" and "backward" buttons (using Firefox's built-in "inspect element" doohickey).

For instance, I tried the selector for the "FORWARD" link as:

body > center:nth-child(2) > p:nth-child(1) > font:nth-child(1) > font:nth-child(3) > a:nth-child(3)

I also tried monkeying around with regexes and the "XPath" selector.

For instance, I tried the "XPath" and "XPath codition" for the "FORWARD" link as:

//a[.="FORWARD"]

but nothing worked, and I couldn't tell if I was just getting some minor formatting detail wrong that the directions weren't clear enough about or what.

Finally I looked in the script itself and changed these two line:

var getBack = [/<a [^>]*href *= *"([^\"]+)"([^<]|<[^\/]|<\/[^a])*(back(?!ground)|prev)/i, 1];
var getNext = [/<a [^>]*href *= *"([^\"]+)"([^<]|<[^\/]|<\/[^a])*next/i, 1];

to this:

var getBack = [/<a [^>]*href *= *"([^\"]+)"([^<]|<[^\/]|<\/[^a])*(back(?!ground)|prev|BACKWARD)/i, 1];
var getNext = [/<a [^>]*href *= *"([^\"]+)"([^<]|<[^\/]|<\/[^a])*(next|FORWARD)/i, 1];

And it works now.

I would share the exact custom settings I have now for the site, but when I try the "export" option it just gives me this:

{"confpag":"cs:http://www.pasteldefender.com/to%20save%20her%20","last":{"url":"http://www.pasteldefender.com/to%20save%20her%20001.html","title":"Pastel Defender Heliotrope"}}

which doesn't seem complete?

Like, I changed "Image" from "Default" to "Beginning of source" with "images/tsh", but that info isn't in there at all.

(EDIT: I mean, I guess technically "back" already matches anything with "backward" as far as I can tell from how the regex is used, but yeah.)

anka-213 commented 7 years ago

Currently, the custom settings for a site is written in the console (press Ctrl-Shift-J to open) when you visit a site. I should add that to the gui as well, but I haven't gotten to it.

The "back" regex tests if the string "back" is a part of the string, so that should include "backward", but I'll add "forward" to the "next" regex.