2 // @name Flickr Pool Date
3 // @namespace http://6v8.gamboni.org/
4 // @description Show when the photo was added to the group pool
6 // @identifier http://6v8.gamboni.org/IMG/js/flickrpooldate.user.user.js
8 // @creator Pierre Andrews (mortimer.pa@free.fr)
9 // @include http://*flickr.com/groups/*/pool*
13 // --------------------------------------------------------------------
15 // This is a Greasemonkey user script.
17 // To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
18 // Then restart Firefox and revisit this script.
19 // Under Tools, there will be a new menu item to "Install User Script".
20 // Accept the default configuration and install.
22 // --------------------------------------------------------------------
23 // Copyright (C) 2006 Pierre Andrews
25 // This program is free software; you can redistribute it and/or
26 // modify it under the terms of the GNU General Public License
27 // as published by the Free Software Foundation; either version 2
28 // of the License, or (at your option) any later version.
30 // This program is distributed in the hope that it will be useful,
31 // but WITHOUT ANY WARRANTY; without even the implied warranty of
32 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 // GNU General Public License for more details.
35 // The GNU General Public License is available by visiting
36 // http://www.gnu.org/copyleft/gpl.html
38 // Free Software Foundation, Inc.
39 // 51 Franklin Street, Fifth Floor
40 // Boston, MA 02110-1301
48 name: " Flickr Pool Date",
49 namespace: "http://6v8.gamboni.org/",
50 description: "Show when the photo was added to the group pool",
51 identifier: "http://6v8.gamboni.org/IMG/js/flickrpooldate.user.user.js",
52 version: "0.4", // version
53 date: (new Date("2006-10-06")) // update date
59 if(unsafeWindow.console)
60 unsafeWindow.console.log(arguments);
66 function getObjectMethodClosure(object, method) {
68 return object[method]();
72 var FlickrPoolDate = function() {this.init();}
74 FlickrPoolDate.prototype = {
80 var matches = /\/page([0-9]+)\/?$/.exec(document.location.pathname);
82 this.page = matches[1];
87 flickr_urls_lookupGroup_onLoad: function(success, responseXML, responseText, params){
89 var rsp = responseText.replace(/<\?xml.*\?>/,'');
91 self.group_id = rsp.group.@id;
97 unsafeWindow.F.API.callMethod('flickr.urls.lookupGroup', {
101 this.waitForGroupId();
104 waitForGroupId: function() {
109 flickr_groups_pools_getPhotos_onLoad: function(success, responseXML, responseText, params){
111 var rsp = responseText.replace(/<\?xml.*\?>/,'');
114 self.insertDates(rsp);
116 M8_log(responseText);
121 group_id:this.group_id,
126 if(matches = /\/pool\/([0-9]+@N[0-9]{2})\/?/.exec(document.location.pathname)) {
127 params['user_id'] = matches[1];
129 if(matches = /\/pool\/tags\/([^\/]+)/.exec(document.location.pathname)) {
130 params['tags'] = matches[1];
131 params['per_page'] = 24;
133 unsafeWindow.F.API.callMethod('flickr.groups.pools.getPhotos',params, listener);
135 setTimeout(getObjectMethodClosure(this,'waitForGroupId'),1000);
139 formatDate: function(seconds) {
140 var now = new Date();
141 now = now.getTime()+now.getTimezoneOffset() * 60*1000;
142 var when = (now/1000) - seconds;
143 var days = parseInt(when/(3600*24));
145 var date = new Date(seconds*1000);
146 return "on "+date.toLocaleDateString();
150 ret = days + ' day'+((days>1)?'s':'');
151 var rest = when - days*3600*24;
152 if(when%(3600*24) > 0) {
155 ret += parseInt(rest/3600)+' h';
157 ret = "less than an hour";
159 ret = "less than an hour";
164 insertDates: function(photos) {
165 var images = document.evaluate(
166 "//div/p[contains(@class,'PoolList')]/a/img",
167 document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
168 for(var i = 0; i < images.snapshotLength; i++) {
169 var image = images.snapshotItem(i);
170 var matches = /\/([0-9]+)_/.exec(image.src);
172 var photo = photos..photo.(@id == matches[1]);
174 var date = this.formatDate(photo.@dateadded);
175 var div = image.parentNode.parentNode.appendChild(document.createElement('div'));
176 var abbr = document.createElement('abbr');
177 abbr.title = new Date(photo.@dateadded*1000).toLocaleString();
178 abbr.setAttribute('style','font-size:90%;color: #6C6C6C;');
179 abbr.appendChild(document.createTextNode('posted '+ date));
180 div.appendChild(abbr);
188 //======================================================================
191 window.addEventListener("load", function () {
194 // update automatically (http://userscripts.org/scripts/show/2296)
195 win.UserScriptUpdates.requestAutomaticUpdates(SCRIPT);
198 var flickrgp = new FlickrPoolDate();