[1] | 1 | /* |
---|
| 2 | * A template for JavaScript comic plugin for WebStrips |
---|
| 3 | * |
---|
| 4 | * License: |
---|
| 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or (at |
---|
| 9 | * your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, but |
---|
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
| 14 | * Public License for more details. |
---|
| 15 | * |
---|
| 16 | * http://www.opensource.org/licenses/gpl-license.php |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License along |
---|
| 19 | * with this program; if not, write to the Free Software Foundation, |
---|
| 20 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 21 | * |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | /* |
---|
| 25 | * place any global variables and support functions here ... |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | var IMAGE_RE = new RegExp("<img src\\=\"http\\://sinfest\\.net/comikaze/comics/(\\d{4}-\\d{2}-\\d{2})\\.gif\""); |
---|
| 30 | |
---|
| 31 | var TITLE_RE = new RegExp("comikaze/comics/\\d{4}-\\d{2}-\\d{2}\\.gif\" alt=\"([^\"]*)\""); |
---|
| 32 | |
---|
| 33 | var ANCHOR_RE = new RegExp("href\\=\"http://sinfest\\.net/archive_page\\.php\\?comicID\\=(\\d+)\"><img src\\=\"images\\/prev_a\\.gif\""); |
---|
| 34 | |
---|
| 35 | var ARCHIVE_RE = new RegExp("option value=\"(\\d{1,4})\"> \\[\\d+\\] ([^<]+)<", "g"); |
---|
| 36 | |
---|
| 37 | var newestId = null; |
---|
| 38 | |
---|
| 39 | /* |
---|
| 40 | * Function title(id) should return a title for the comic strip with the given id. |
---|
| 41 | */ |
---|
| 42 | function title(id) { |
---|
| 43 | |
---|
| 44 | i = parseInt(id); |
---|
| 45 | |
---|
| 46 | s = get("http://sinfest.net/archive_page.php?comicID=" + i); |
---|
| 47 | |
---|
| 48 | m = TITLE_RE.exec(s); |
---|
| 49 | |
---|
| 50 | if (m) |
---|
| 51 | return m[1]; |
---|
| 52 | |
---|
| 53 | return id; |
---|
| 54 | |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /* |
---|
| 58 | * Function image(id) should return a URL of an image for the comic strip with the given id. |
---|
| 59 | */ |
---|
| 60 | function image(id) { |
---|
| 61 | |
---|
| 62 | i = parseInt(id); |
---|
| 63 | |
---|
| 64 | s = get("http://sinfest.net/archive_page.php?comicID=" + i); |
---|
| 65 | |
---|
| 66 | m = IMAGE_RE.exec(s); |
---|
| 67 | |
---|
| 68 | if (m) |
---|
| 69 | return "http://sinfest.net/comikaze/comics/" + m[1] + ".gif"; |
---|
| 70 | |
---|
| 71 | return id; |
---|
| 72 | |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | /* |
---|
| 76 | * Function previous(id) should return the id of a comic strip that is prior to the comic strip |
---|
| 77 | * with a given id or null if there is no such comic. |
---|
| 78 | */ |
---|
| 79 | function previous(id) { |
---|
| 80 | |
---|
| 81 | i = parseInt(id); |
---|
| 82 | |
---|
| 83 | if (i < 2) |
---|
| 84 | return null; |
---|
| 85 | |
---|
| 86 | return i - 1; |
---|
| 87 | |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | /* |
---|
| 91 | * Function next(id) should return the id of a comic strip that is next to the comic strip |
---|
| 92 | * with a given id or null if there is no such comic. |
---|
| 93 | */ |
---|
| 94 | function next(id) { |
---|
| 95 | |
---|
| 96 | i = parseInt(id); |
---|
| 97 | print(i); |
---|
| 98 | if (newestId == null) |
---|
| 99 | newest(); |
---|
| 100 | |
---|
| 101 | if (newestId != null) { |
---|
| 102 | j = parseInt(newestId); |
---|
| 103 | if (j == i) |
---|
| 104 | return null; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | return i + 1; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | /* |
---|
| 111 | * Function first() should return the id of the first comic strip or null if that information |
---|
| 112 | * cannot be obtained for this comic. |
---|
| 113 | */ |
---|
| 114 | function first() { |
---|
| 115 | |
---|
| 116 | return 1; |
---|
| 117 | |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /* |
---|
| 121 | * Function newest() should return the id of the most recent comic strip or null if that information |
---|
| 122 | * cannot be obtained for this comic. |
---|
| 123 | */ |
---|
| 124 | function newest() { |
---|
| 125 | |
---|
| 126 | s = get("http://www.sinfest.net/index.php"); |
---|
| 127 | |
---|
| 128 | m = ANCHOR_RE.exec(s); |
---|
| 129 | |
---|
| 130 | if (m) { |
---|
| 131 | newestId = m[1]; |
---|
| 132 | return m[1]; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | return null; |
---|
| 136 | |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | /* |
---|
| 140 | * if the information is present you can also implement the following functionality currently |
---|
| 141 | * supported by WebStrips (uncoment the functions) |
---|
| 142 | */ |
---|
| 143 | |
---|
| 144 | /* |
---|
| 145 | * Function link(id) should return an url pointing to the page where the comic strip with a |
---|
| 146 | * given id was retrieved from. |
---|
| 147 | */ |
---|
| 148 | |
---|
| 149 | function link(id) { |
---|
| 150 | return "http://sinfest.net/archive_page.php?comicID=" + id; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | /* |
---|
| 155 | * Function archive(id) should process the archive data from the comic strip with the given id on |
---|
| 156 | * and return the possible new comics using archiveInsert(id, title) and archiveAppend(id, title) |
---|
| 157 | * functions that will only be allowed to call if the archive function is invoked. |
---|
| 158 | * |
---|
| 159 | * archiveInsert(id, title) - inserts the archive entry at the beginning of the newly generated archive |
---|
| 160 | * segment (The last call to this function will insert an entry to the start of the new segment). |
---|
| 161 | * |
---|
| 162 | * archiveAppend(id, title) - inserts the archive entry at the end of the newly generated archive |
---|
| 163 | * segment (The last call to this function will insert an entry to the end of the new segment and thus |
---|
| 164 | * to the end of archive). |
---|
| 165 | */ |
---|
| 166 | |
---|
| 167 | function archive(id) { |
---|
| 168 | s = get("http://www.sinfest.net/archive.php"); |
---|
| 169 | |
---|
| 170 | ARCHIVE_RE.lastIndex = 0; |
---|
| 171 | |
---|
| 172 | i = parseInt(id); |
---|
| 173 | |
---|
| 174 | while (m = ARCHIVE_RE.exec(s)) { |
---|
| 175 | |
---|
| 176 | archiveInsert(m[1], m[2]); |
---|
| 177 | |
---|
| 178 | j = parseInt(m[1]); |
---|
| 179 | |
---|
| 180 | if (id != null && i == j) |
---|
| 181 | break; |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | |
---|