
xkcd
Source (link to git-repo or to original if based on someone elses unmodified work):
Description:
xkcd (http://xkcd.com/) plugin for plasma comic. Last changelog:
2.0
Thanks to Mike Vastola for his updates to make the comic work again.
To reduce the risk for issues in the future Mike changed the code to use XKCD's JSON API.
Ratings & Comments
18 Comments
8 8 great
Thanks for this addon. It's worked for the longest time. I've been running into issues for a while now though, and I tried @TuxmAL's patch, but it didn't work (the regex still wasn't parsing correctly). I played with the code a bit (okay, a lot) and changed things to use XKCD's JSON API instead, which makes parsing much easier and hopefully also makes this more resilient to website changes. I'm not sure if this is still being maintained, but if so, feel free to incorporate my changes. I could fork, but it would be nicer to fix things for long-time users of this comic addin instead. See: https://gist.github.com/mvastola/6d937854f2202091afc2fbb2f7253ef6
Hi Mike, the patch from @TuxmAL actually worked for me today. Anyhow I like the idea of parsing the JSON, hope it is more robust so it gets used here on the main branch. Thanks to you both!
Thank you very much for your patch! I applied it and it works again now. Your solution seems way more robust than what I had there. :)
And sorry for the long delay.
Some changes in xkcd.com site, has broken xkcd comics again. To restore the functionality please add this patch to the downloaded version: ``` 35c35 < var re = new RegExp("Permanent link to this comic: https://xkcd.com/(\\d )/"); --- > var re = new RegExp("https://xkcd.com/(\\d )/"); 86c86 < var re = new RegExp("Image URL \\(for hotlinking/embedding\\): (https://imgs\.xkcd\.com/comics/. )"); --- > var re = new RegExp('"(https://imgs\.xkcd\.com/comics/. )"'); ```
Thank you for the information. I am sorry that it took me so long to react.
You're welcome!
Broken, please fix :)
Hi, I've noted a change in xkcd.com site, gone full https now. Here are the fixes needed to patch the code: 33c33 < var re = new RegExp("Permanent link to this comic: http://xkcd.com/(\\d+)/"); --- > var re = new RegExp("Permanent link to this comic: https://xkcd.com/(\\d+)/"); 47c47 < comic.requestPage("http:" + match[1], comic.Image); --- > comic.requestPage("https:" + match[1], comic.Image); a couple of fix again makes ' and " in additionalText looks like quote and double quote: 56c56,57 < comic.additionalText = match[2]; --- > var additionalTxt = match[2]; > comic.additionalText = additionalTxt.replace(/&#quot;/g, "\"").replace(/'/g, "'"); thanks!
ops! last patch is 56c56,57 < comic.additionalText = match[2]; --- > var additionalTxt = match[2]; > comic.additionalText = additionalTxt.replace(/&#quot;/g, "\"").replace(/&'/g, "'");
ugh! Last replace contains / & # 3 9 ;/ (remove spaces between chars).
Thanks for your work! I updated the comic.
You are welcome! Thanks for your work, it has been a good source to learn comics plugin!
The original code does not handle empty "title" and "alt" tags to well. This patch fixes that as well:http://download.amadyne.net/xkcd-main-2015-04.patch Quote:
--- main.es 2009-02-01 03:40:16.000000000 +0100
+++ main_new.es 2015-04-02 08:26:04.215609602 +0200
@@ -41,10 +41,10 @@
}
}
if (id == comic.Page) {
- var re = new RegExp("<img src=\"(http://imgs.xkcd.com/comics/[^\"]+)\"");
+ var re = new RegExp("<img src=\"(//imgs\.xkcd\.com/comics/[^\"]+)\"");
var match = re.exec(data);
if (match != null) {
- comic.requestPage(match[1], comic.Image);
+ comic.requestPage("http:" + match[1], comic.Image);
} else {
comic.error();
return;
@@ -49,12 +49,15 @@
comic.error();
return;
}
-
//find the tooltip and the strip title of the comic
- re = new RegExp("src=\"http://imgs.xkcd.com/comics/.+\" title=\"([^\"]+)\" alt=\"([^\"]+)\"");
+ re = new RegExp("<img src=\"(//imgs\.xkcd\.com/comics/[^\"]+)\" title=\"([^\"]+)\"");
+ match = re.exec(data);
+ if (match != null) {
+ comic.additionalText = match[2];
+ }
+ re = new RegExp("<img src=\"(//imgs\.xkcd\.com/comics/[^\"]+)\".+alt=\"([^\"]+)\"");
match = re.exec(data);
if (match != null) {
- comic.additionalText = match[1];
comic.title = match[2];
}
}
Thanks for the patch. :) I updated xkcd using your changes.
xkcd.com has updated the image link to no longer contain "http:" Quote:
--- main_new.es 2015-04-01 17:35:10.992105603 +0200
+++ main.es 2009-02-01 03:40:16.000000000 +0100
@@ -41,10 +41,10 @@
}
}
if (id == comic.Page) {
- var re = new RegExp("<img src=\"(//imgs.xkcd.com/comics/[^\"]+)\"");
+ var re = new RegExp("<img src=\"(http://imgs.xkcd.com/comics/[^\"]+)\"");
var match = re.exec(data);
if (match != null) {
- comic.requestPage("http:" + match[1], comic.Image);
+ comic.requestPage(match[1], comic.Image);
} else {
comic.error();
return;
Please have a look at KDE bug #333063 https://bugs.kde.org/show_bug.cgi?id=333063 For some comics this great plugin crashes the Plasma Desktop.