update version number and date
[FlickrHacks.git] / _greasemonkey_ / flickrpooldetails.user.js
blob188728b6392802a239c6d6cf34cef43538f36693
1 // ==UserScript==
2 // @name        FlickrPoolDetails
3 // @namespace   http://6v8.gamboni.org/
4 // @description This script brings the "detailed view" feature to the group pool pages.
5 // @version        0.1
6 // @identifier  http://6v8.gamboni.org/IMG/js/flickrpooldetails.user.js
7 // @date           2006-12-04
8 // @creator        Pierre Andrews (mortimer.pa@free.fr)
9 // @include http://www.flickr.com/groups/sciencegroup/pool/*
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         //update information
46         var SCRIPT = {
47                 name: "FlickrPoolDetails",
48                 namespace: "http://6v8.gamboni.org/",
49                 description: "This script brings the 'detailed view' feature to the group pool pages.",
50                 identifier: "http://6v8.gamboni.org/IMG/js/flickrpooldetails.user.js",
51                 version: "0.1",                                                         // version
52                 date: (new Date("2006-12-04"))          // update date
53                 .valueOf()
54         };
55         
56 function ce(tag,name){
57     element = document.createElement(tag);
58     element.setAttribute('name',name);
59   return element;
60 };      
62         function M8_log() {
63                 if(unsafeWindow.console)
64                         unsafeWindow.console.log(arguments);
65                 else
66                         GM_log(arguments);
67         }
69         function getObjectMethodClosure(object, method) {
70                 return function(arg) {
71                         return object[method](arg); 
72                 }
73         }
75         var flickrpooldetails = function() {this.init();}
77         flickrpooldetails.prototype = {
79                 init: function() {
80                         if(document.location.hash == '#detail') this.showPoolDetails();
81                         this.insertButton();
82                 },
84                 insertButton: function() {
85                         var links = document.evaluate(
86                                                                                  "//td[@class='Section']/p[@class='Links']",
87                                                                                  document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null
88                                                   ).singleNodeValue;
89                         if(links) {
90                                 links.innerHTML += '<img width="1" height="11" src="/images/subnavi_dots.gif" alt=""/>';
91                                 var a1=document.createElement('A');
92                                 a1.setAttribute('href','javascript:;');
93                                 var txt1=document.createTextNode('Detail View');
94                                 a1.appendChild(txt1);
95                                 links.appendChild(a1);
96                                 a1.addEventListener('click',getObjectMethodClosure(this,'showPoolDetails'));
97                         }
98                 },
99                 
100                 showPoolDetails: function(arg) {
101                         document.location.hash = '#detail';
102                         M8_log("ICI");
103                         var shots = document.evaluate(
104                                                                                                  "/html/body/div[@id='Main']/div[1]//img",
105                                                                                                  document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);  // Get all group
106                         
107                         var self = this;
108                         var listener = {
109                                 flickr_photos_getInfo_onLoad: function(success, responseXML, responseText, params){
110                                         if(success) {
111                                                 M8_log(responseText);
112                                                 /*self.photo[photo_id*1] = eval('('+responseText+')');
113                                                   if(self.received++ > shots.snapshotLength) {
114                                                   self.done();
115                                                   }*/
116                                         } else
117                                         GM_log("error looking for group" + responseText);
118                                 }
119                         };
120                         for(var i = 0; i < shots.snapshotLength; i++) { 
121                                 var image = shots.snapshotItem(i);
122                                 var matches = /\/([0-9]+)_(.*?)[_.]/.exec(image.src);
123                                 if(matches) {
124                                         id = matches[1]*1;
125                                         secret = matches[2]+'';
126                                         
127                                         
128                                 }                               
129                         }
130                                         unsafeWindow.F.API.callMethod('flickr.groups.pool.getInfo', {}, listener);
131                 },
133                 done: function() {
134                         M8_log(this.photos);
135                         /*                      var subNavs = document.getElementById("SubNav");
136                                                 var table1=document.createElement('TABLE');
137                         table1.setAttribute('width','100%');
138                         table1.setAttribute('cellspacing','0');
139                         var tbody1=document.createElement('TBODY');
140                         table1.appendChild(tbody1);
141                         
142                         var shots = document.evaluate(
143                                                                                                  "/html/body/div[@id='Main']/div[1]//img",
144                                                                                                  document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);  // Get all group
145                         var tr1 = document.createElement('TR');
146                         tr1.setAttribute('valign','bottom')
147                         tbody1.appendChild(tr1);
148                         for(var i = 0; i < shots.snapshotLength; i++) { 
149                                 var image = shots.snapshotItem(i);
150                                 var matches = /\/([0-9]+)_/.exec(image.src);
151                                 if(matches) {
152                                         photo_id = matches[1];
153                                         photo = this.photos[photo_id*1];
154                                         var td1=document.createElement('TD');
155                                         tr1.appendChild(td1);
156                                         var div1=document.createElement('DIV');
157                                         div1.className='StreamView';
158                                         div1.innerHTML ='<p class="Photo">'+
159 '<a href="">'+
160 '<img width="240" height="180" alt="" src="http://static.flickr.com/1/127194972_8e6cbc4b37_m.jpg"/>'+
161 '</a>'+
162 '</p>'+
163 '<div class="Desc">'+
164 '<div id="description_div127194972" style="width: 240px;" title="Click to edit">'+
165 'See where this photo was taken at Yuan.CC Maps . Added to the Cream of the Crop pool as'+
166 '<a href="/photos/mortimer/127194972/">...</a>'+
167 '</div>'+
168 '</div>'+
169 '<p class="Privacy">'+
170 '<a title="Set privacy permissions for this photo" href="/photo_settings.gne?id=127194972&photos_url=%2Fphotos%2Fmortimer%2Fsets%2F72157594230473349%2Fdetail%2F">'+
171 '<img class="absmiddle" width="15" height="15" alt="This photo is public" src="/images/icon_public.gif"/>'+
172 '</a>'+
173 '<span class="ccIcn ccIcnSmall">'+
174 '<a href="/photo_license.gne?id=127194972">'+
175 '<img class="absmiddle last" width="15" height="15" alt="This photo is licensed" src="/images/icon_creative_commons.gif"/>'+
176 '</a>'+
177 '</span>'+
178 'This photo is'+
179 '<b>public</b>'+
180 '.'+
181 '<a class="Plain" title="Set privacy permissions for this photo" href="/photo_settings.gne?id=127194972&photos_url=%2Fphotos%2Fmortimer%2Fsets%2F72157594230473349%2Fdetail%2F">Change</a>'+
182 '?'+
183 '<br/>'+
184 '</p>'+
185 '<p class="Do">'+
186 'Uploaded on'+
187 '<a class="Plain" href="/photos/mortimer/archives/date-posted/2006/04/12/">Apr 12, 2006</a>'+
188 ' | '+
189 '<a class="Plain" onclick="mini_map_open(this, 127194972, \'/photos/mortimer/127194972/map/\', \'your\', \'http://static.flickr.com/1/127194972_8e6cbc4b37_s.jpg\', new YGeoPoint(49.022223,5.872364), 16, \'Taken in <a><b>HagĂ©ville, Lorraine<\/b><\/a>\'); return false" href="/photos/mortimer/127194972/map/?view=everyones">Map</a>'+
190 ' | '+
191 '<a class="Plain" onclick="delete_photo(127194972); return false;" href="/photo_delete.gne?id=127194972&photos_url=%2Fphotos%2Fmortimer%2Fsets%2F72157594230473349%2Fdetail%2F">Delete</a>'+
192 '</p>'+
193 '<p class="Activity">'+
194 '<b>482</b>'+
195 'views /'+
196 '<a class="Plain" href="/photos/mortimer/127194972/">6 notes</a>'+
197 '/'+
198 '<a class="Plain" href="/photos/mortimer/127194972/">24 comments</a>'+
199 '</p>'+
200 '</div>';
201                                 }
202                                 if(i%3 == 0) {
203                                         tr1 = document.createElement('TR');
204                                         tr1.setAttribute('valign','bottom');
205                                         tbody1.appendChild(tr1);
206                                 }
207                         }
209                         subNavs.parentNode.insertBefore(table1,subNavs.nextSibling);*/
210                 }
211                 
212         }
213         //======================================================================
214         // launch
215         try {
216                 window.addEventListener("load", function () {
217                                                                         try {
218                                                                                 
219                                                                                 // update automatically (http://userscripts.org/scripts/show/2296)
220                                                                                 win.UserScriptUpdates.requestAutomaticUpdates(SCRIPT);
221                                                                         } catch (ex) {} 
222                                                                         
223                                                                         var flickrgp = new flickrpooldetails();
224                 }, false);
225         } catch (ex) {}
226 })();