fixed sets... added support for user tags
[FlickrHacks.git] / _greasemonkey_ / flickrgeoinfototag.user.js
blob5fa0330ce39f54520baf2474917ee4f87be60f37
1 // ==UserScript==
2 // @name        Flickr Geo Info To Tag
3 // @namespace   http://6v8.gamboni.org/
4 // @description Provide a button to transform geographic information provided by flickr map to usual tags.
5 // @version        0.1
6 // @identifier  http://6v8.gamboni.org/IMG/js/flickrgeoinfototag.user.js
7 // @date           2006-08-28
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         //update information
46         var SCRIPT = {
47                 name: "Flickr Geo Info To Tag",
48                 namespace: "http://6v8.gamboni.org/",
49                 description: "Provide a button to transform geographic information provided by flickr map to usual tags.",
50                 identifier: "http://6v8.gamboni.org/IMG/js/flickrgeoinfototag.user.js",
51                 version: "0.1",                                                         // version
52                 date: (new Date("2006-08-28"))          // update date
53                 .valueOf()
54         };
55         
56         
57         function M8_log() {
58                 if(unsafeWindow.console)
59                         unsafeWindow.console.log(arguments);
60                 else
61                         GM_log(arguments);
62         }
64         function getObjectMethodClosure11(object, method,arg1) {
65                 return function(arg) {
66                         return object[method](arg,arg1); 
67                 }
68         }       
70         var flickrgeoinfototag = function() {this.init();}
72         flickrgeoinfototag.prototype = {
74                 init: function() {
75                         var moreLot = document.evaluate(
76                                                                                  "//td[@class='RHS']/ul//li/a[@class='Plain']",
77                                                                                  document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
78                                                                                  );
79                         for(var i = 0; i < moreLot.snapshotLength; i++) { 
80                                 var map = moreLot.snapshotItem(i);
81                                 if(map.innerHTML == 'map') {
82                                         var ul = map.parentNode.appendChild(document.createElement('ul'));
83                                         var coord = map.getAttribute('onclick');
84                                         var matches;
85                                         if(matches = /new YGeoPoint\(([0-9.-]+),([0-9.-]+)\)/.exec(coord)) {
86                                                 var lat = matches[1];
87                                                 var lon = matches[2];
88                                                 var li1 = ul.appendChild(document.createElement('li'));
89                                                 li1.className = 'Stats';
90                                                 var a1 = li1.appendChild(document.createElement('a'));
91                                                 a1.href="javascript:;";
92                                                 a1.className = 'Plain';
93                                                 a1.appendChild(document.createTextNode('Add Geotags'));
94                                                 a1.addEventListener('click',getObjectMethodClosure11(this,'addtag',"geotagged geo:lon="+lon+" geo:lat="+lat),false);
95                                         }
96                                         var html = map.parentNode.getElementsByTagName('b').item(0);
97                                         if(html && html.innerHTML) {
98                                                 var tags = html.textContent.split(',');
99                                                 var tut = '';
100                                                 for each(t in tags) {
101                                                                 tut += '"'+t.replace(/(^\s+|\s+$)/,'')+'" ';
102                                                         }
103                                                 var li2 = ul.appendChild(document.createElement('li'));
104                                                 li2.className = 'Stats';
105                                                 var a2 = li2.appendChild(document.createElement('a'));
106                                                 a2.href="javascript:;";
107                                                 a2.className = 'Plain';
108                                                 a2.appendChild(document.createTextNode('Add Place Tags'));
109                                                 a2.addEventListener('click',getObjectMethodClosure11(this,'addtag',tut),false);
110                                         }
111                                         
112                                         break;
113                                 }
114                         }
115                 },
117                 addtag: function(evt,tags) {
118                         unsafeWindow.tagrs_addTag(unsafeWindow.page_photo_id,tags);
119                 }
120         }
121         //======================================================================
122         // launch
123         try {
124                 window.addEventListener("load", function () {
125                                                                         try {
126                                                                                 
127                                                                                 // update automatically (http://userscripts.org/scripts/show/2296)
128                                                                                 win.UserScriptUpdates.requestAutomaticUpdates(SCRIPT);
129                                                                         } catch (ex) {} 
130                                                                         
131                                                                         var flickrgp = new flickrgeoinfototag();
132                 }, false);
133         } catch (ex) {}
134 })();