xkcd: Visible comic titles

By Ben Blank Last update Jun 27, 2008 — Installed 1,167 times.

Archived Comments (locked)

in
Subscribe to Archived Comments 12 posts, 8 voices



Jesse Andrews Admin

The following is an archive of comments made before threaded discussions was implemented (November 16th, 2008)

 
Avindra V.G. Scriptwright

Check out my script.

 
Ben Blank Script's Author

Fixed. Using "parent" as a variable name appears to cause some unusual issues with GM 0.8 (perhaps related to the problem reported in ticket 108). Changed the script to use "parentNode" as the variable name instead, works.

 
Ben Blank Script's Author

Sorry for the delay; I just got back from a trip. It's clear that the problem is caused by changes in Greasemonkey 0.8 and am still looking for the right solution. (I don't intend to use unsafeWindow if I can possibly avoid it. Doesn't seem it should be necessary for determining an element's parent node, anyway.)

I'll update the script as soon as I get it worked out.

 
Christopher ... Scriptwright

Adding with (unsafeWindow) { before the parent = comic.parentNode; line (and another closing brace at the end of the file) will make it work again. I'm not sure exactly why that's necessary, and there's probably a better way to do it. Can somebody with better GM skills explain?

 
Katie Molnar User

This script seems to have stopped working for me. Any idea why?

 
Christopher ... Scriptwright

I like it, but I like to read the comic before looking at the title. So I made two changes:

I changed the GM_addStyle line to
GM_addStyle(".comic-title {\n\tcolor: grey; background: grey; padding-left: 2em; padding-right: 2em; font-size: smaller;\n\tfont-style: italic;\n\tfont-variant: normal;\n}\n .comic-title:hover { color: black; background: white }");

That makes the comment text grey-on-grey until you hover over it. (The padding gives some extra space so the cursor doesn't have to cover the text.)

Then I added

comic.title = '';

right after extracting the title, so Firefox won't display the title fragment over the image.

 
Ben Blank Script's Author

Hmm... I'd originally used innerHTML specifically so that HTML would work if he used it, but considering it's extracting the text from an attribute anyway, that would be silly. :-)

I doubt he'd ever include anything malicious in his titles... no, scratch that, he might, just to teach us all a lesson. Besides, if you're going to do something, you ought to at least do it properly, right? Fixed.

 
Ilmari Karonen Scriptwright

You seem to have an escaping bug in this script. The line that reads:

title.innerHTML = comic.title;

should instead read:

title.appendChild(document.createTextNode(comic.title));

That way, it'll work correctly even if the comic title happens to contain HTML tags (which, xkcd being xkcd, wouldn't surprise me at all).

 
Kylor Hele User

Nice one :). Especially with Firefox only showing a fragment of the title, this is nice.

 
Ben Blank Script's Author

Perhaps you have an out-of-date copy of GreaseMonkey? To GM, .tld is "magic" which makes it work with .com, .net, .org, .us, etc. Because xkcd has registered multiple top-level domains (at least xkcd.com and xkcd.net, last I checked), I decided to use it rather than try to find and list them all.

If you don't see the comic titles when you go to xkcd.com, try either updating GreaseMonkey or just add .com to your list of includes:

  1. Open the Tools menu and select Greasemonkey, then Manage User Scripts
  2. Select "xkcd: Visible comic titles" from the list of scripts
  3. In the Included Pages section, click Add
  4. Type "http://xkcd.com/*" and click OK
  5. In the Included Pages section, click Add again
  6. Type "http://www.xkcd.com/*" and click OK
  7. Click OK again to close GreaseMonkey and reload xkcd.com

 
Dan Cooper Scriptwright

why is this using the tld domain? i can't access the site there. use .com please

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel