Advertisement
fweng322

Plasma 5 comics plasmoid: Snoopy main.es

Dec 14th, 2017
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. /***************************************************************************
  2. * Copyright (C) 2008-2017 Matthias Fuchs <mat69@gmx.net> *
  3. * *
  4. * This program is free software; you can redistribute it and/or modify *
  5. * it under the terms of the GNU General Public License as published by *
  6. * the Free Software Foundation; either version 2 of the License, or *
  7. * (at your option) any later version. *
  8. * *
  9. * This program is distributed in the hope that it will be useful, *
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  12. * GNU General Public License for more details. *
  13. * *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program; if not, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
  18. ***************************************************************************/
  19.  
  20. //NOTE only this part needs to be changed to support different comics
  21. const author = "Charles M. Schulz";
  22. const websitePart = "peanuts"; //e.g. the "garfield" in "http://www.gocomics.com/garfield/"
  23. const comicName = "Peanuts"; //needed to find the most recent strip, the name that is displayed next to the "by comic author" on the website
  24. const firstIdentifier = "1950-10-02";
  25. const shopUrl = "";
  26.  
  27. const infos = {
  28. "User-Agent": "Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.6 (like Gecko)",
  29. "Accept": "text/html, image/jpeg, image/png, text/*, image/*, */*",
  30. "Accept-Encoding": "functionlate",
  31. "Accept-Charset": "iso-8859-15, utf-8;q=0.5, *;q=0.5",
  32. "Accept-Language": "en",
  33. "Host": "gocomics.com",
  34. "referrer": "http://www.gocomics.com/",
  35. "Connection": "Keep-Alive"
  36. }
  37.  
  38. function init()
  39. {
  40. comic.comicAuthor = author;
  41. comic.firstIdentifier = firstIdentifier;
  42. comic.websiteUrl = "http://www.gocomics.com/" + websitePart + '/';
  43. comic.shopUrl = shopUrl;
  44.  
  45. comic.requestPage(comic.websiteUrl, comic.User, infos);
  46. }
  47.  
  48. function pageRetrieved(id, data)
  49. {
  50. //find lastIdentifier
  51. if (id == comic.User) {
  52. var exp = new RegExp("data-url=\"" + comic.websiteUrl + "(\\d{4}/\\d{2}/\\d{2})" + "\"");
  53. var match = exp.exec(data);
  54. if (match != null) {
  55. comic.lastIdentifier = date.fromString(match[1], "yyyy/MM/dd");
  56. comic.websiteUrl += comic.identifier.toString("yyyy/MM/dd");
  57. comic.requestPage(comic.websiteUrl, comic.Page, infos);
  58. } else {
  59. print("Could not find last identifier.");
  60. comic.error();
  61. return;
  62. }
  63. }
  64.  
  65. //find comic strip and next/previous identifier
  66. if (id == comic.Page) {
  67. var exp = new RegExp("\<a role=\'button\' href=\'/" + websitePart + "/(\\d{4}/\\d{2}/\\d{2})\' class=\'fa gc-comic-nav__button fa-caret-right sm js-next-comic");
  68. var match = exp.exec(data);
  69. if (match != null) {
  70. comic.nextIdentifier = date.fromString(match[1], "yyyy/MM/dd");
  71. }
  72.  
  73. exp = new RegExp("\<a role=\'button\' href=\'/" + websitePart + "/(\\d{4}/\\d{2}/\\d{2})\' class=\'fa gc-comic-nav__button fa-caret-left sm js-previous-comic");
  74. match = exp.exec(data);
  75. if (match != null) {
  76. comic.previousIdentifier = date.fromString(match[1], "yyyy/MM/dd");
  77. }
  78.  
  79. // try large strip first
  80. exp = new RegExp("data-image=\"([^\"]+)\"");
  81. match = exp.exec(data);
  82. if (match != null) {
  83. comic.requestPage(match[1], comic.Image, infos);
  84. } else {
  85. // no large strip, try small one
  86. exp = new RegExp("\<picture class=\"img-fluid item-comic-image\"\>\<img [.]* src=\"([^\"]+)\" /\>\</picture\>");
  87. match = exp.exec(data);
  88. if (match != null) {
  89. comic.requestPage(match[1], comic.Image, infos);
  90. } else {
  91. print("Could not find comic image.");
  92. comic.error();
  93. return;
  94. }
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement