-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xkcd.com: include srcset
attribute of comic images so that 2x-resolution versions load when relevant
#131
Comments
Getting WCR to select Image B over Image A if B exists isn't too difficult. Had to do something similar for grabbing nav buttons for FurAffinity last year. (There are two nav buttons for it, one for gallery, and one for comics using the built in comic nav) The problem is grabbing the srcset and then correctly implementing it. I had just done something similar with TwoKinds, since many pages have secret extras hidden (mostly sketches) as a link attached to the comic image. I was able to grab the href info, and then convert it into a image was relatively simple enough. However, when trying to implement something similar for XKCD, there becomes a problem.
That 2x is however the problem. There are ways for xpath to tourniquet the extra bits off, usually by "substring-before" and "substring-after". However, I so far ( after half hour or so), I have had little luck in getting those to work within WCR. I suspect it's because of the use of quotation marks and apostrophes, as they are the only two quotation/container characters XPath has, and they are both are already being used. So it is may be possible, but I am having trouble in doing so. I figured I would atleast put this info down here incase someone else wanted to try their hand at it. |
The Request: anka-213#131 So what does it do? It adds in a button! What does this button do? Why it lets you toggle between the normal and the hidden srcset 2x resolution image! This should hopefully solve a 4 year old request. I won't go into too much detail, but this was a result of working about two weeks of doing something very similar for the Inhuman Webcomic and successfully implementing it. The hard part was to actually get it to properly preload the pages. But eitherway, tweaked it a little, largely just changing the regex capture rules as well as several variable names, and now it's setup for xkcd's 2x. I do not think anything I've done in the personal branch will run into any issues revolving "lack of" for this commit. Though i suppose I'll find out soon.
Well it's been several years and I ended up tackling this. Would you mind checking this dev branch to see how it works out for you? https://github.com/SoraHjort/webcomic_reader/blob/Fixes-and-Additions/webcomic_reader.user.js
Edit: xpath and regex updated to take in account of hyperlinked comic pages. |
Background – xkcd offers multiple images using
srcset
xkcd uses the
srcset
HTML attribute to detect and serve different images based on my display’s pixel density. My browser chooses to load higher-resolution images when possible because my computer has a HiDPI/Retina display that can show the full detail of the higher resolution within the same space.When I load https://xkcd.com/2161/ without Webcomic Reader, the image I see on my computer’s screen is https://imgs.xkcd.com/comics/an_apple_a_day_2x.png, the “2x” resolution version. Though the
src
of the image refers to https://imgs.xkcd.com/comics/an_apple_a_day.png, the lower-resolution version, my browser prefers the version in thesrcset
for my screen.This is the HTML for the
img
of xkcd #2161, including thesrcset
attribute:Problem – this script loads the wrong image on my screen
With Webcomic Reader enabled, on https://xkcd.com/2161/, I see https://imgs.xkcd.com/comics/an_apple_a_day.png, the lower-resolution version. This makes for a worse reading experience because the lower-resolution image is blurrier on my screen.
The
img
tag put on the page by Webcomic Reader looks like this. It has nosrcset
attribute. (It is also missing thealt
attribute.)The description for
paginas[i]
in the code says that theimg
selector “gets the <img> element containing the desired image (not just the src, but the whole <img>)”. But this is not happening in this case. The “whole<img>
” is missing two attributes that were on the originalimg
.Notes for the solution
Webcomic Reader should preserve any
srcset
attributes it find onimg
s.Some pages on xkcd, such as https://xkcd.com/3/, don’t have a
srcset
attribute and offer no high-resolution image.xkcd is the site that I notice the problem on, but unless xkcd is selecting the image in an unusual way, other comic sites could be affected. There could be other comics with high-resolution images that people are missing.
This is Webcomic Reader’s current code for xkcd:
webcomic_reader/webcomic_reader.user.js
Lines 955 to 975 in 26a1f6e
The text was updated successfully, but these errors were encountered: