2 // @name Flickr Exif Info
3 // @namespace http://6v8.gamboni.org/
4 // @description Select which exif info you want to see on the photo page
6 // @identifier http://6v8.gamboni.org/IMG/js/flickrexifinfo.user.user.js
8 // @creator Pierre Andrews (mortimer.pa@free.fr)
9 // @include http://*flickr.com/photos/*/*
10 // @include http://*flickr.com/photo_exif.gne?id=*
11 // @exclude http://*flickr.com/photos/organize*
14 // --------------------------------------------------------------------
16 // This is a Greasemonkey user script.
18 // To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
19 // Then restart Firefox and revisit this script.
20 // Under Tools, there will be a new menu item to "Install User Script".
21 // Accept the default configuration and install.
23 // --------------------------------------------------------------------
24 // Copyright (C) 2006 Pierre Andrews
26 // This program is free software; you can redistribute it and/or
27 // modify it under the terms of the GNU General Public License
28 // as published by the Free Software Foundation; either version 2
29 // of the License, or (at your option) any later version.
31 // This program is distributed in the hope that it will be useful,
32 // but WITHOUT ANY WARRANTY; without even the implied warranty of
33 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 // GNU General Public License for more details.
36 // The GNU General Public License is available by visiting
37 // http://www.gnu.org/copyleft/gpl.html
39 // Free Software Foundation, Inc.
40 // 51 Franklin Street, Fifth Floor
41 // Boston, MA 02110-1301
47 //This is an array to help in different conversion of the raw data.
48 // you can map a exif value name as displayed by flickr
50 // - it's real name in the EXIF info
52 // - the name of the EXIF info defining the unit
53 // - a replacement regexp for when you add this info in the tags (%u in in the replacement will be replaced by the unit if any)
54 // see the existing values to understand more.
57 'Image Width': {map:'Pixel X-Dimension',direct_unit:'pixel'},
58 'Image Height': {map:'Pixel Y-Dimension',direct_unit:'pixel'},
59 'Y-Resolution': {indirect_unit:'Resolution Unit'},
60 'X-Resolution': {indirect_unit:'Resolution Unit'},
61 'ISO Speed' : {addtag:{regexp:/([0-9]+)/,replacement:'iso:$1'}},
62 'Focal Length' : {addtag:{regexp:/([0-9]+) mm/,replacement:'$1mm'}},
63 'Exposure' : {addtag:{regexp:/.*\(([\/0-9]+)\)/,replacement:'$1s'}},
67 //conversion for the units, I have no idea what the 0 and 1 stands for, but 2 is for dpi apparently :D
68 var UNITS = new Array('?','?','dpi');
73 name: "Flickr Exif Info",
74 namespace: "http://6v8.gamboni.org/",
75 description: "Select which exif info you want to see on the photo page",
76 identifier: "http://6v8.gamboni.org/IMG/js/flickrexifinfo.user.js",
77 version: "0.3", // version
78 date: (new Date("2006-08-28")) // update date
82 function getObjectMethodClosure11(object, method,arg1) {
83 return function(arg) {
84 return object[method](arg,arg1);
89 if(unsafeWindow.console)
90 unsafeWindow.console.log(arguments);
95 var flickrexifinfo = function() {this.init();}
97 flickrexifinfo.prototype = {
98 config: GM_getValue('ExifInfoConfig'),
101 if(document.location.pathname.indexOf("photo_exif.gne") >= 0) {
102 this.showConfigurationBoxes();
108 showConfigurationBoxes: function() {
109 var infos = document.evaluate(
110 "//table[@id='Inbox']/tbody/tr/td[1]/b",
111 document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
112 for(var i = 0; i < infos.snapshotLength; i++) {
113 var exif = infos.snapshotItem(i);
114 var name = exif.innerHTML.replace(/:$/,'');
115 var check = document.createElement('input');
116 check.type = 'checkbox';
117 check.addEventListener('change',getObjectMethodClosure11(this,'addToConf',name),false);
119 check.checked = true;
120 check.disabled = true;
121 } else if(this.config && (this.config.indexOf(','+name+',') >= 0)) {
122 check.checked = true;
124 var td = document.createElement('td');
125 td.style.width = '13px';
126 td.appendChild(check);
127 exif.parentNode.parentNode.insertBefore(td,exif.parentNode);
131 addToConf: function(event, name) {
132 var newConfig = this.config;
133 if(!newConfig) newConfig = ',';
134 if(event.target.checked) {
135 newConfig += name+',';
137 newConfig = newConfig.replace(','+name+',',',');
139 this.config = newConfig;
141 GM_setValue('ExifInfoConfig',this.config);
144 showMoreExif: function() {
145 var moreLot = document.evaluate(
146 "//td[@class='RHS']/ul//li/a[@class='Plain']",
147 document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
149 for(var i = 0; i < moreLot.snapshotLength; i++) {
150 var more = moreLot.snapshotItem(i);
151 if(more.innerHTML == "More properties") {
152 var photoid = more.href.replace(/http:\/\/(www.)?flickr.com\/photo_exif.gne\?id=([0-9]+)/,'$2');
153 if(this.config.length > 1) {
154 var ul = document.createElement('ul');
158 flickr_photos_getExif_onLoad: function(success, responseXML, responseText, params){
159 var rsp = responseText.replace(/<\?xml.*\?>/,'');
161 var finds = self.config.split(',');
162 for(var i=0;i<finds.length;i++) {
164 var mapping = MAPPING[finds[i]];
170 ex = rsp..exif.(@label == finds[i]);
172 ex = rsp..exif.(@label == map);
174 if(new String(ex.clean).length > 0)
178 if(new String(ex).length > 0) {
181 unit = mapping.direct_unit;
182 if(!unit && mapping.indirect_unit) {
183 unit = UNITS[parseInt(rsp..exif.(@label == mapping.indirect_unit).raw)];
186 var li = ul.appendChild(document.createElement('li'));
187 li.className = 'Stats';
188 li.innerHTML = '<b>'+finds[i]+':</b> '+ex;
189 if(unit && new String(unit).length > 0)
190 li.innerHTML += ' '+unit;
191 if(document.getElementById('tagadderlink')) {
192 var addtag = li.appendChild(document.createElement('a'));
193 addtag.innerHTML = ' [+]';
194 addtag.title ="add this as a tag";
195 addtag.href="javascript:;";
196 addtag.setAttribute('style','text-decoration:none;color: #C9C9C9;');
197 addtag.addEventListener('click',getObjectMethodClosure11(self,'addtag',new Array(photoid,finds[i],ex,unit)),false);
202 more.parentNode.appendChild(ul);
203 var li = document.createElement('li');
204 li.className = 'Stats';
205 li.appendChild(more);
210 unsafeWindow.F.API.callMethod('flickr.photos.getExif', {
220 addtag: function(evt,args) {
223 var value = new String(args[2]);
225 var mapping = MAPPING[title];
226 if(mapping && mapping.addtag) {
227 value = value.replace(mapping.addtag.regexp,mapping.addtag.replacement);
228 if(unit) value.replace(/%u/g,unit);
230 unsafeWindow.tagrs_addTag(id,value);
233 //======================================================================
236 window.addEventListener("load", function () {
239 // update automatically (http://userscripts.org/scripts/show/2296)
240 win.userScriptUpdates.requestAutomaticUpdates(SCRIPT);
243 var flickrgp = new flickrexifinfo();