source: comics/PiledHigherAndDeeper/comic.js @ 1:4e64bf1747ce

Revision 1:4e64bf1747ce, 3.2 KB checked in by lukacu, 14 years ago (diff)

Core project and comics migration

Line 
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
28var ANCHOR_RE = new RegExp("archive\\_print\\.php\\?comicid=(\\d*)");
29   
30var NEXT_RE = new RegExp("<a\\ href\\=archive\\.php\\?comicid\\=(\\d*)><img[^>]*next");
31   
32var PREV_RE = new RegExp("<a\\ href\\=archive\\.php\\?comicid\\=(\\d*)><img[^>]*prev");
33
34var PATTERN_RE = new RegExp("http\\://www\\.phdcomics\\.com/comics/archive/phd([^\\.]*)\\.gif");
35
36/*
37 * Function title(id) should return a title for the comic strip with the given id.
38 */
39function title(id) {
40
41    return id;
42
43}
44
45/*
46 * Function image(id) should return a URL of an image for the comic strip with the given id.
47 */
48function image(id) {
49               
50    s = get("http://www.phdcomics.com/comics/archive.php?comicid=" + id);
51   
52    if (s.length == 0) return null;
53   
54    f = PATTERN_RE.exec(s);
55
56    if (f) {
57        return "http://www.phdcomics.com/comics/archive/phd" + f[1] + ".gif";
58    } else 
59        return null;
60       
61}
62
63/*
64 * Function previous(id) should return the id of a comic strip that is prior to the comic strip
65 * with a given id or null if there is no such comic.
66 */
67function previous(id) {
68    s = get("http://www.phdcomics.com/comics/archive.php?comicid=" + id);
69   
70    p = PREV_RE.exec(s);
71   
72    if (p) {
73        return p[1];
74    }
75   
76    return null;
77
78}
79
80/*
81 * Function next(id) should return the id of a comic strip that is next to the comic strip
82 * with a given id or null if there is no such comic.
83 */
84function next(id) {
85
86    s = get("http://www.phdcomics.com/comics/archive.php?comicid=" + id);
87   
88    p = NEXT_RE.exec(s);
89   
90    if (p) {
91        return p[1];
92    }
93   
94    return null;
95}
96
97/*
98 * Function first() should return the id of the first comic strip or null if that information
99 * cannot be obtained for this comic.
100 */
101function first() {
102   
103    return 1;
104}
105
106/*
107 * Function newest() should return the id of the most recent comic strip or null if that information
108 * cannot be obtained for this comic.
109 */
110function newest() {
111   
112    s = get("http://www.phdcomics.com/comics.php");
113   
114    m = ANCHOR_RE.exec(s);
115
116    if (m) {
117        return m[1];
118    }
119   
120    return null; 
121
122}
123
124/*
125 * if the information is present you can also implement the following functionality currently
126 * supported by WebStrips (uncoment the functions)
127 */
128
129/*
130 * Function link(id) should return an url pointing to the page where the comic strip with a
131 * given id was retrieved from.
132 */
133
134function link(id) {
135    return "http://www.phdcomics.com/comics/archive.php?comicid=" + id;
136}
137
138
Note: See TracBrowser for help on using the repository browser.