2 // @name Flickr Refer Comment
3 // @namespace http://6v8.gamboni.org/
4 // @description Auto comment the place where you come from
6 // @identifier http://6v8.gamboni.org/IMG/js/flickrrefercomment.user.js
8 // @creator Pierre Andrews (mortimer.pa@free.fr)
9 // @include http://*flickr.com/photos/*/*
10 // @exclude http://*flickr.com/photos/*/*#preview
11 // @exclude http://*flickr.com/photos/organize*
14 // --------------------------------------------------------------------
15 // Copyright (C) 2006 Pierre Andrews
17 // This program is free software; you can redistribute it and/or
18 // modify it under the terms of the GNU General Public License
19 // as published by the Free Software Foundation; either version 2
20 // of the License, or (at your option) any later version.
22 // This program is distributed in the hope that it will be useful,
23 // but WITHOUT ANY WARRANTY; without even the implied warranty of
24 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 // GNU General Public License for more details.
27 // The GNU General Public License is available by visiting
28 // http://www.gnu.org/copyleft/gpl.html
30 // Free Software Foundation, Inc.
31 // 51 Franklin Street, Fifth Floor
32 // Boston, MA 02110-1301
40 name
: "Flickr Refer Comment",
41 namespace: "http://6v8.gamboni.org/",
42 description
: "auto comment the place where you come from",
43 identifier
: "http://6v8.gamboni.org/IMG/js/flickrrefercomment.user.js",
44 version
: "1.7", // version
45 date
: (new Date(2008, 05, 30)) // update date
54 var RANDOM
= FELLOW
+1;
57 var PHOTOPHLOW
= MAP
+1;
59 var FlickrReferComment = function() {
62 FlickrReferComment
.prototype = {
64 M8_log: function(msg
) {
65 if(unsafeWindow
.console
&& unsafeWindow
.console
.log
) {
66 unsafeWindow
.console
.log(msg
);
72 var referrer
= document
.referrer
;
75 if(referrer
.indexOf(document
.location
.pathname
) >= 0) return //no need to add the comment if you just commented...
77 if(referrer
.indexOf('/discuss/') >= 0 && referrer
.indexOf('/groups/') >= 0) {
78 //we come from a group discussion
79 this.resolveGroupName(DISCUSS
,referrer
,referrer
);
80 } else if(referrer
.indexOf('/groups/') >= 0) {
81 if(referrer
.indexOf('/map') >= 0) {
82 //we come from a group map
83 this.resolveGroupName(MAP
,referrer
,referrer
);
85 //we come from a group
86 this.resolveGroupName(POOL
,referrer
,referrer
);
88 } else if(referrer
.indexOf('/photos/friends') >= 0) {
89 //we come from our contacts' last photos
90 this.insertComment("Seen in my contacts' photos.",'');
91 } else if(referrer
.indexOf('/photos/tags') >= 0) {
92 this.insertComment("Seen in a tag search.",referrer
);
93 } else if(matches
= /\/tags\/([^\/]+)\/?/.exec(referrer
)) {
94 this.insertComment("Seen amongst other photos with the tag: "+matches
[1]+".",referrer
);
95 } else if(referrer
.indexOf('/favorites') >= 0) {
96 //we come from our favorites
97 this.insertComment("Seen in someone's favorites.",referrer
);
98 } else if(referrer
.indexOf('/archives') >= 0) {
99 //we come from our favorites
100 this.insertComment("Seen in your archives.",referrer
);
101 } else if(document
.location
.hash
== "#in/nearby") {
102 //we come from a nearby photo
103 this.insertComment("Seen next to a nearby photo",referrer
);
104 } else if(matches
= /\/sets\/([0-9]+)(\/map)?\/?/.exec(referrer
)) {
105 if(matches
[2] == '/map') {
107 this.resolveSetName(matches
[1],referrer
,MAP
);
110 this.resolveSetName(matches
[1],referrer
,SET
);
112 } else if(matches
= /\/in\/set-([^\/]*\/?)/.exec(document
.location
.pathname
)) {
113 //we come from another photo in the same set.
114 var set_url
= document
.location
.pathname
;
115 set_url
= set_url
.replace(/photos\/([^\/]+)\/.*/,'http://www.flickr.com/photos/$1/sets/'+matches
[1]);
116 this.resolveSetName(matches
[1],set_url
);
117 } else if((referrer
.indexOf('/photos/') >= 0) && (matches
= /(\/in\/pool-([^\/]*)\/?)/.exec(document
.location
.pathname
))) {
118 if(referrer
.indexOf('/in/pool-') < 0)
119 referrer
+= matches
[1];
120 //we come from a photo feed
121 this.resolveGroupName(FELLOW
,"http://www.flickr.com/groups/"+matches
[2],referrer
);
122 } else if(matches
= /\/photos\/([^\/]+)(\/map|\/[0-9]+|\/page[0-9]+)?\/?$/.exec(referrer
) || document
.location
.pathname
.indexOf("/in/photostream") >= 0) {
123 if(matches
[2] == '/map') {
124 //we come from a map of the user photos
125 this.insertComment("Seen on a map of your photos.",referrer
);
127 var re
= new RegExp("/photos/("+matches
[1]+"|"+unsafeWindow
.nextprev_currentContextID
.replace('stream','')+")/");
128 if(document
.location
.pathname
.indexOf("/in/photostream") >= 0 || re
.test(document
.location
.pathname
)) {
129 //we come from the same user photo feed
130 this.insertComment("Seen on your photo stream.",referrer
);
132 //we come from someone else feed, it was therefore found in a comment.
133 this.insertComment("Seen in some comments.",referrer
);
136 } else if(referrer
.indexOf('/map') >= 0) {
137 //we come from one of the maps
138 this.insertComment("Seen on a map.",referrer
);
140 // Modifications by: Marcos Kuhns (http://www.kuhnsfam.com/)
141 else if(referrer
.indexOf('/places') >= 0) {
142 //we come from places
143 matches
= /\/places\/(([^\/]+)\/?)*/.exec(referrer
);
144 if(matches
&& matches
[2]) {
145 this.insertComment("Seen on photos taken in "+decodeURI(matches
[2]).replace('+', ' ')+".",referrer
);
147 this.insertComment("Seen on the places page.",referrer
);
149 } else if(referrer
.indexOf('/cameras') >= 0) {
150 matches
= /\/cameras\/([^\/]+)\/([^\/]+)\/?/.exec(referrer
);
151 if(matches
&& matches
.length
> 1) {
152 var make
= matches
[1].replace(/_
/g
,' ');
153 var model
= matches
[2].replace(/_
/g
,' ');
154 this.insertComment("Seen on the "+make
+" "+model
+" camera finder.");
156 } else if(referrer
.indexOf('/interesting') >= 0 && referrer
.indexOf('/explore') >= 0) {
157 //we come from one of the interesting calendar
158 this.insertComment("Seen in the interestingness archives.",referrer
);
159 } else if(referrer
.indexOf('http://www.raum-fuer-notizen.de/explore/index.php?username=') >= 0) {
160 //we come from the individual explore page
161 this.insertComment("Seen on my individual explore page.",referrer
);
162 } else if(referrer
.indexOf('/explore') >= 0) {
163 //we come from the explore page
164 this.insertComment("Seen on the explore page.",referrer
);
165 } else if(referrer
.indexOf('/search') >= 0) {
166 //we come from a search
167 this.insertComment("Found in a search.",referrer
);
168 } else if(referrer
.indexOf('/photos_comments.gne') >= 0) {
169 //we come from recent comments
170 this.insertComment("Seen in my recent comments.",'');
171 } else if(referrer
.indexOf('interestingby.isaias.com.mx/pm.php') >= 0) {
172 //we come from the popular finder at isaias
173 this.insertComment("Found in your popular shots.",referrer
);
174 } else if(referrer
.indexOf('bloglines.com/') >= 0) {
175 //we come from a rss reader site
176 this.insertComment("Seen on a rss aggregator.","http://www.bloglines.com");
177 } else if(referrer
.indexOf('google.com/reader') >= 0) {
178 //we come from a rss reader site
179 this.insertComment("Seen on a rss aggregator.","http://www.google.com/reader");
180 } else if(referrer
.indexOf('krazydad.com/gustavog/FlickRandom.pl?group=') >= 0) {
181 var groupid
= referrer
.replace(/http:\/\/(www.)?krazydad.com\/gustavog\/FlickRandom.pl\?group=/,'');
182 this.resolveGroupName(RANDOM
,groupid
,referrer
);
183 } else if(referrer
.indexOf('krazydad.com/gustavog/FlickRandom.pl') >= 0) {
184 this.insertComment("Seen in a FlickrRandom selection of photos.",referrer
);
185 } else if(referrer
.indexOf('flagrantdisregard.com/flickr/random.php') >= 0) {
186 this.insertComment("Seen in FD's random photo browser.",referrer
);
187 } else if(referrer
.indexOf('flagrantdisregard.com/flickr/fortune.php') >= 0) {
188 this.insertComment("Seen in FD's fortune teller.",referrer
);
189 } else if(referrer
.indexOf('flagrantdisregard.com/flickr/scout.php') >= 0) {
190 this.insertComment("Seen in Flickr explore scout.",referrer
);
191 } else if(referrer
.indexOf('houserdesign.com/flickr') >= 0) {
192 this.insertComment("Seen on FlickrLeech.",referrer
);
193 } else if(referrer
.indexOf('maps.yuan.cc/') >= 0) {
194 this.insertComment("Seen on Yuan.CC Maps.",referrer
);
195 } else if(referrer
.indexOf('webdev.yuan.cc/') >= 0) {
196 this.insertComment("Seen on LfVr.",referrer
);
197 } else if(referrer
.indexOf('blog.flickr.com') >= 0) {
198 this.insertComment("Seen on Flickr Blog.",referrer
);
199 } else if(referrer
.indexOf('utata.org/spotlights') >= 0) {
200 this.insertComment("Seen in the Utata spotlight.",referrer
);
201 } else if(referrer
.indexOf('netomer.de/flickrtools/inspector') >= 0) {
202 this.insertComment("Seen on Flickr Inspector.",referrer
);
203 } else if(referrer
== "http://www.flickr.com/" || referrer
== "http://flickr.com/" ||
204 referrer
== "http://www.flickr.com" || referrer
== "http://flickr.com") {
205 this.insertComment("Seen on my Flickr home page.",'');
206 } else if(referrer
== "http://philmccluskey.com/projects/flickrfox/") {
207 this.insertComment("Discovered using FlickrFox.",referrer
);
208 } else if(referrer
.indexOf("http://16.gmodules.com/ig/") >= 0) {
209 this.insertComment("Seen in my contacts' photos.",'');
210 } else if(referrer
.indexOf("www.drewmyersphoto.net/flickr_scripts/cie/") >= 0) {
211 this.insertComment("Seen in my contacts' Explore photos.",referrer
);
212 } else if(referrer
.indexOf("www.drewmyersphoto.net/flickr_scripts/ycrf/") >= 0) {
213 this.insertComment("Seen in my contacts' favorites.",referrer
);
214 } else if(referrer
.indexOf("flexplore.raum-fuer-notizen.de/flexplore") >= 0) {
215 this.insertComment("Seen on flexplore.",referrer
);
217 //cases for photoflow
218 else if(referrer
.indexOf('http://www.photophlow.com/flickr/group/') >= 0) {
219 var groupid
= referrer
.replace(/http:\/\/www.photophlow.com\/flickr\/group\//,'');
220 groupid
= groupid
.replace(/inner\//,'');
221 this.resolveGroupName(PHOTOPHLOW
,"http://www.flickr.com/groups/"+groupid
,referrer
);
223 else if(referrer
.indexOf('http://www.photophlow.com/flickr/user/') >= 0) {
224 var userid
= referrer
.replace(/http:\/\/www.photophlow.com\/flickr\/user\//,'');
225 userid
= userid
.replace(/inner\//,'');
226 this.resolveUserName(PHOTOPHLOW
,"http://www.flickr.com/people/"+userid
,referrer
);
229 else if(referrer
.indexOf('flickr.com') < 0) {
230 if(matches
= /http:\/\/(www.)?([^\/]+).*/.exec(referrer
)) {
231 this.insertComment("Seen on "+matches
[2],referrer
);
233 this.insertComment("Seen on the Web.",referrer
);
236 //we have no referer, but we can still try to guess
237 if(matches
= /\/in\/pool-([^\/]*)\/?/.exec(document
.location
.pathname
)) {
238 //we come from a group feed or something
239 this.resolveGroupName(POOL
,"http://www.flickr.com/groups/"+matches
[1],"http://www.flickr.com/groups/"+matches
[1]+'/pool');
240 } else if(matches
= /\/in\/set-([^\/]*\/?)/.exec(document
.location
.pathname
)) {
242 var set_url
= document
.location
.pathname
;
243 set_url
= set_url
.replace(/photos\/([^\/]+)\/.*/,'http://www.flickr.com/photos/$1/sets/'+matches
[1]);
244 this.resolveSetName(matches
[1],set_url
,SET
);
247 //Fix by Marco Bernardini
248 else if(matches
= /\/photos\/([^\/]+)(\/map|\/[0-9]+)?\/?$/.exec(document
.location
.pathname
) || document
.location
.pathname
.indexOf("/in/photostream") >= 0) {
249 if(matches
[2] == '/map') {
250 //we come from a map of the user photos
251 this.insertComment("Seen on a map of your photos.",'');
253 var re
= new RegExp("/photos/("+matches
[1]+"|"+unsafeWindow
.nextprev_currentContextID
.replace('stream','')+")/");
254 if(re
.test(document
.location
.pathname
) || document
.location
.pathname
.indexOf("/in/photostream") >= 0) {
255 //we come from the same user photo feed
256 this.insertComment("Seen on your photo stream.",'');
258 //we come from someone else feed, it was therefore found in a comment.
259 this.insertComment("Seen in some comments.",'');
267 insertComment: function(comment
, url
) {
270 html
= '<a href="'+url
+'" title="Seen on...">'+comment
+'</a>';
271 html
= "\n\n--\n<i>"+html
+"</i>"+
272 ' <em>(<a href="http://6v8.gamboni.org/Flickr-Add-referer-into-comments.html">?</a>)</em>';
273 var thisTextAreas
= document
.getElementsByTagName('textarea');
274 var thisTextArea
= null;
275 for(var t
=0;t
<thisTextAreas
.length
;t
++) {
276 if(thisTextAreas
[t
].name
== 'message') {
277 thisTextArea
= thisTextAreas
[t
]; break;
282 if(thisTextArea
.value
.indexOf(html
) < 0)
283 thisTextArea
.value
+= html
;
284 thisTextArea
.selectionStart
= thisTextArea
.selectionEnd
= 0;
288 resolveUserName: function(type
,userurl
,referrer
) {
289 //Trick to do it using the flickr API with authentication already embeded in the page.
292 flickr_urls_lookupUser_onLoad: function(success
, responseXML
, responseText
, params
){
294 var usernames
= responseXML
.getElementsByTagName('username');
295 var username
= usernames
[0].firstChild
.nodeValue
;
298 msg
= "Discovered in "+username
+"'s";
299 if(msg
.indexOf('photoflow') < 0 || msg
.indexOf('Photoflow') < 0) {
303 referrer
= referrer
.replace(/inner\//,'');
307 self
.insertComment(msg
,referrer
);
309 GM_log("error looking for user "+referrer
+':' + responseText
+'.');
312 unsafeWindow
.F
.API
.callMethod('flickr.urls.lookupUser', {
318 resolveGroupName: function(type
,groupurl
,referrer
) {
319 //Trick to do it using the flickr API with authentication already embeded in the page.
322 flickr_urls_lookupGroup_onLoad: function(success
, responseXML
, responseText
, params
){
324 var groupnames
= responseXML
.getElementsByTagName('groupname');
325 var groupname
= groupnames
[0].firstChild
.nodeValue
;
327 var msg
= 'Seen in the group<b>"'+groupname
+'"</b>';
330 msg
= 'Seen on a map of '+groupname
+' photos.';
333 msg
= 'Seen in a discussion of the group <b>"'+groupname
+'"</b>';
336 msg
= "Seen next to a fellow photo of the group <b>\""+groupname
+"\"</b>.";
339 msg
= "Discovered in the "+groupname
;
340 if(msg
.indexOf('photophlow') < 0 && msg
.indexOf('Photophlow') < 0) {
341 msg
+= " photophlow";
344 referrer
= referrer
.replace(/inner\//,'');
348 self
.insertComment(msg
,referrer
);
351 this.M8_log("error looking for group"+referrer
+':' + responseText
+'.');
353 flickr_groups_getInfo_onLoad:function(success
, responseXML
, responseText
, params
){
355 var names
= responseXML
.getElementsByTagName('name');
356 var name
= names
[0].firstChild
.nodeValue
;
358 self
.insertComment("Seen in random photos from "+name
,referrer
);
361 this.M8_log("error looking for group"+groupurl
+':' + responseText
+'.');
367 unsafeWindow
.F
.API
.callMethod('flickr.groups.getInfo', {
376 unsafeWindow
.F
.API
.callMethod('flickr.urls.lookupGroup', {
382 resolveSetName: function(id
,referrer
,type
) {
383 //Trick to do it using the flickr API with authentication already embeded in the page.
386 flickr_photosets_getInfo_onLoad: function(success
, responseXML
, responseText
, params
){
388 var titles
= responseXML
.getElementsByTagName('title');
389 var title
= titles
[0].firstChild
.nodeValue
;
393 msg
= 'Seen on a map of your '+title
+' set.';
397 msg
= 'Seen in your '+title
+' set.';
400 self
.insertComment(msg
,referrer
);
405 unsafeWindow
.F
.API
.callMethod('flickr.photosets.getInfo', {
412 //======================================================================
414 // var flickrgp = new FlickrReferComment();
415 //======================================================================
418 window
.addEventListener("load", function () {
421 // update automatically (http://userscripts.org/scripts/show/2296)
422 win
.UserScriptUpdates
.requestAutomaticUpdates(SCRIPT
);
425 var flickrgp
= new FlickrReferComment();