2 // @name Flickr More Sparkles
3 // @namespace http://6v8.gamboni.org/
4 // @description Add Sparkle lines for stats of individual photos
6 // @identifier http://6v8.gamboni.org/IMG/js/flickr_more_sparkles.user.js
8 // @creator Pierre Andrews (mortimer.pa@free.fr)
9 // @include *flickr.com/photos/*
10 // @exclude *flickr.com/photos/*/alltags*
11 // @exclude *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) 2008 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
49 name: "Flickr More Sparkles",
50 namespace: "http://6v8.gamboni.org/",
51 description: "Add Sparkle lines for stats of individual photos",
52 identifier: "http://6v8.gamboni.org/IMG/js/flickr_more_sparkles.user.js",
53 version: "0.1", // version
54 date: (new Date("2008-12-10")) // update date
59 /***********************************************************************
61 **********************************************************************/
63 var FlickrLocaliser = function(locals) {
66 FlickrLocaliser.prototype = {
67 selectedLang: undefined,
68 localisations: undefined,
69 getLanguage: function() {
70 if(!this.selectedLang) {
71 var langA = $x1("//p[@class='LanguageSelector']//a[contains(@class,'selected')]");
73 var matches = /\/change_language.gne\?lang=([^&]+)&.*/.exec(langA.href);
74 if(matches && matches[1]) {
75 this.selectedLang = matches[1];
76 return this.selectedLang;
80 } else return this.selectedLang;
83 init: function(locals) {
84 this.localisations = locals;
87 localise: function(string, params) {
88 if(this.localisations && this.getLanguage()) {
89 var currentLang = this.localisations[this.selectedLang];
90 if(!currentLang) currentLang = this.localisations[this.localisations.defaultLang];
91 var local = currentLang[string];
92 if(!local) return string;
94 var rep = new RegExp('@'+arg+'@','g');
95 local = local.replace(rep,params[arg]);
97 local =local.replace(/@[^@]+@/g,'');
99 } else return undefined;
104 /*****************************Flickr Localisation**********************/
109 if(unsafeWindow.console)
110 unsafeWindow.console.log(arguments);
116 Xpath trickery, from:
117 http://ecmanaut.blogspot.com/2006/07/expressive-user-scripts-with-xpath-and.html
119 function $x( xpath, root )
121 var doc = root ? root.evaluate?root:root.ownerDocument : document;
122 var got = doc.evaluate( xpath, root||doc, null, 0, null ), next;
124 while( next = got.iterateNext() )
130 function $x1(xpath, root) {
131 var doc = root ? root.evaluate?root:root.ownerDocument : document;
132 return document.evaluate(
136 XPathResult.FIRST_ORDERED_NODE_TYPE, null
140 function foreach( xpath, cb, root )
142 var nodes = $x( xpath, root ), e = 0;
143 for( var i=0; i<nodes.length; i++ )
144 e += cb( nodes[i], i ) || 0;
150 function getObjectMethodClosure(object, method) {
151 return function(arg) {
152 return object[method](arg);
157 var flickrmoresparkles = function() {this.init();}
159 flickrmoresparkles.prototype = {
161 localiser: new FlickrLocaliser({
162 'en-us' : {'photo_stats': 'Photo stats'},
167 makeSpark: function(url, insert, withLink) {
171 onload:function(details) {
172 var start = details.responseText.indexOf("F.photoViews = {");
173 var end = details.responseText.indexOf("</script>",start);
174 var code = details.responseText.substring(start,end).replace("F.photoViews = {","").replace("foreGraph:","");
175 code = code.substring(0,code.lastIndexOf("]"))+"]";
176 var evaled = eval(code);
180 for(i=0;i<evaled.length;i++) {
181 var val = parseInt(evaled[i].views);
192 values=values.substring(1);
193 var imgtxt = "<img src=\"http://chart.apis.google.com/chart?"
195 + "&chds="+min+','+max
200 + "&chm=o,990000,0,60,4"
202 + "&chxs=0,990000,11,0,_|1,990000,1,0,_|2,990000,1,0,_"
203 + "&chxl=0:|"+val+"|1:||2:||"
207 insert.innerHTML += "<a href="+url+">"+imgtxt+"</a>";
209 insert.innerHTML +=imgtxt;
218 var statIT = $x1("//td[@class='RHS']/ul/li[3]/a");
219 if(!statIT || statIT.innerHTML != "Photo stats") {
220 statIT = $x1("//td[@class='RHS']/ul/li[2]/a");
222 if(statIT && statIT.innerHTML == "Photo stats") {
223 var url = statIT.href;
224 this.makeSpark(url,statIT);
225 } else if(document.title == "Flickr: Your Photostream"){
227 foreach("//p[@class='Activity']",function(el) {
228 var ael = $x1("a",el);
229 self.makeSpark(ael.href+"/stats",el,true);
235 //======================================================================
238 window.addEventListener("load", function () {
241 // update automatically (http://userscripts.org/scripts/show/2296)
242 win.UserScriptUpdates.requestAutomaticUpdates(SCRIPT);
245 var flickrgp = new flickrmoresparkles();