update version number and date
[FlickrHacks.git] / _greasemonkey_ / flickrsurf.user.js
blobf744da1ab043529ff354d1680d50cbfa0596054c
1 // ==UserScript==
2 // @name        Flickr surf
3 // @namespace   http://6v8.gamboni.org/
4 // @description Links to the surf page from a photo
5 // @version        0.1
6 // @identifier  http://6v8.gamboni.org/IMG/js/flickrsurf.user.js
7 // @date           2006-05-23
8 // @creator        Pierre Andrews (mortimer.pa@free.fr)
9 // @include http://*flickr.com/photos/*
10 // ==/UserScript==
12 // --------------------------------------------------------------------
14 // This is a Greasemonkey user script.
16 // To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
17 // Then restart Firefox and revisit this script.
18 // Under Tools, there will be a new menu item to "Install User Script".
19 // Accept the default configuration and install.
21 // --------------------------------------------------------------------
22 // Copyright (C) 2006 Pierre Andrews
23 // 
24 // This program is free software; you can redistribute it and/or
25 // modify it under the terms of the GNU General Public License
26 // as published by the Free Software Foundation; either version 2
27 // of the License, or (at your option) any later version.
28 // 
29 // This program is distributed in the hope that it will be useful,
30 // but WITHOUT ANY WARRANTY; without even the implied warranty of
31 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32 // GNU General Public License for more details.
33 // 
34 // The GNU General Public License is available by visiting
35 //   http://www.gnu.org/copyleft/gpl.html
36 // or by writing to
37 //   Free Software Foundation, Inc.
38 //   51 Franklin Street, Fifth Floor
39 //   Boston, MA  02110-1301
40 //   USA
43 (function () {
45         var doclocation = new String(document.location);
46         if(doclocation.match(/\/surf\/?$/)) {
47                 var previous = document.evaluate("/html/body/div[@id='Main']/table/tbody/tr/td[2]/a",
48                                                                                   document.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null
49                                                                                   ).singleNodeValue;
50                 var next = document.evaluate("/html/body/div[@id='Main']/table/tbody/tr/td[4]/a",
51                                                                                   document.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null
52                                                                                   ).singleNodeValue;
53                 if(previous) {
54                         var skipBack = document.evaluate("/html/body/div[@id='Main']/table/tbody/tr/td[1]/a[2]",
55                                                                                   document.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null
56                                                                                   ).singleNodeValue;
57                         if(skipBack) {
58                                 var skipLogo = skipBack.previousSibling;
59                                 var back = skipBack.parentNode.insertBefore(document.createElement('a'),skipLogo);
60                                 back.parentNode.insertBefore(document.createTextNode(String.fromCharCode('8249')+' '),back);
61                                 skipBack.parentNode.insertBefore(document.createElement('br'),skipLogo);
62                                 back.href = previous.href+"/surf";
63                                 back.innerHTML = "Previous";
64                         }
65                 }
67                 if(next) {
68                         var skipFor = document.evaluate("/html/body/div[@id='Main']/table/tbody/tr/td[5]/a[2]",
69                                                                                   document.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null
70                                                                                   ).singleNodeValue;
71                         if(skipFor) {
72                                 var forw = skipFor.parentNode.insertBefore(document.createElement('a'),skipFor);
73                                 skipFor.parentNode.insertBefore(document.createTextNode(' '+String.fromCharCode('8250')),skipFor);
74                                 skipFor.parentNode.insertBefore(document.createElement('br'),skipFor);
75                                 forw.href = next.href+"/surf";
76                                 forw.innerHTML = "Next";
77                         }
78                 }
79         } else {
80                 var slideshow = document.evaluate("/html/body/div[@id='Main']/table[@id='Photo']/tbody/tr/td[2]/div[2]/table/tbody/tr/td[3]/div/div/div[contains(@id,'slideshowLink_stream')]",                              
81                                                                                   document.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null
82                                                                                   ).singleNodeValue;
83                 if(slideshow) {
84                         var div = slideshow.appendChild(document.createElement('div'));
85                         div.className = 'showLink';
86                         div.style.display = 'block';
87                         var rootLocation = new String(document.location);
88                         rootLocation = rootLocation.replace(/(http:\/\/(www.)?flickr.com\/photos\/[^\/]+\/[0-9]+)\/?.*$/i,"$1");
89                         div.innerHTML = '<a href="'+rootLocation+'/surf/" title="surf from that photo">Surf</a>';
90                 }
91         }
93         
94 })();