- Fixed a bunch of bugs for existing paginations
[FlickrHacks.git] / _greasemonkey_ / flickrmoveadditionalinfo.user.js
blob8213c69e876ce40b09d15217f8276de785bf4169
1 // ==UserScript==
2 // @name        Flickr Move Additional Info
3 // @namespace   http://6v8.gamboni.org/
4 // @description Move photos additional informations on top of the group/set list
5 // @version        0.3
6 // @identifier  http://6v8.gamboni.org/IMG/js/flickrmoveadditionalinfo.user.user.js
7 // @date           2006-01-29
8 // @creator        Pierre Andrews (mortimer.pa@free.fr)
9 // @include http://*flickr.com/photos/*/*
10 // @exclude *flickr.com/photos/*/alltags*
11 // @exclude http://*flickr.com/photos/organize*
12 // ==/UserScript==
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
25 // 
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.
30 // 
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.
35 // 
36 // The GNU General Public License is available by visiting
37 //   http://www.gnu.org/copyleft/gpl.html
38 // or by writing to
39 //   Free Software Foundation, Inc.
40 //   51 Franklin Street, Fifth Floor
41 //   Boston, MA  02110-1301
42 //   USA
45 (function () {
47         //update information
48         var SCRIPT = {
49                 name: "Move Additional Info",
50                 namespace: "http://6v8.gamboni.org/",
51                 description: "Move photos additional informations on top of the group/set list",
52                 identifier: "http://6v8.gamboni.org/IMG/js/flickrmoveadditionalinfo.user.js",
53                 version: "0.3",                                                         // version
54                 date: (new Date("2006-01-29"))          // update date
55                 .valueOf()
56         };
57         
58         
59         function M8_log() {
60                 if(unsafeWindow.console)
61                         unsafeWindow.console.log(arguments);
62                 else
63                         GM_log(arguments);
64         }
65         
66         function getObjectMethodClosure(object, method) {
67                 return function(arg) {
68                         return object[method](arg); 
69                 }
70         }
72         /*
73           Xpath trickery, from:
74           http://ecmanaut.blogspot.com/2006/07/expressive-user-scripts-with-xpath-and.html
75          */
76         function $x( xpath, root )
77                 {
78                         var doc = root ? root.evaluate?root:root.ownerDocument : document;
79                         var got = doc.evaluate( xpath, root||doc, null, 0, null ), next;
80                         var result = [];
81                         while( next = got.iterateNext() )
82                                 result.push( next );
83                         return result;
84                 }
86         function $x1(xpath,root) {
87                 var doc = root ? root.evaluate?root:root.ownerDocument : document;
88                 return document.evaluate( xpath,                              
89                                                                         root||doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null
90                                                                         ).singleNodeValue;              
91         }
93         function foreach( xpath, cb, root )
94         {
95                 var nodes = $x( xpath, root ), e = 0;
96                 for( var i=0; i<nodes.length; i++ )
97                         e += cb( nodes[i], i ) || 0;
98                 return e;
99         }
102         /*
103           E4X trickery, from:
104           http://ecmanaut.blogspot.com/2006/03/e4x-and-dom.html#import_node
105          */
106         function importNode( e4x, doc )
107         {
108                 var me = importNode, xhtml, domTree, importMe;
109                 me.Const = me.Const || { mimeType: 'text/xml' };
110                 me.Static = me.Static || {};
111                 me.Static.parser = me.Static.parser || new DOMParser;
112                 xhtml = <testing xmlns="http://www.w3.org/1999/xhtml" />;
113                 xhtml.test = e4x;
114                 domTree = me.Static.parser.parseFromString( xhtml.toXMLString(),
115                                                                                                         me.Const.mimeType );
116                 importMe = domTree.documentElement.firstChild;
117                 while( importMe && importMe.nodeType != 1 )
118                         importMe = importMe.nextSibling;
119                 if( !doc ) doc = document;
120                 return importMe ? doc.importNode( importMe, true ) : null;
121         }
123         function appendTo( e4x, node, doc )
124         {
125                 return node.appendChild( importNode( e4x, doc || node.ownerDocument ) );
126         }
127         
129         var flickrmoveadditionalinfo = function() {this.init();}
131         flickrmoveadditionalinfo.prototype = {
133                 init: function() {
134                         var before = document.getElementById("otherContexts_div");
135                         if(before) {
136                                 this.move("/html/body/div[@id='Main']/table[@id='Photo']/tbody/tr/td[2]/h4",before);
137                                 this.move("/html/body/div[@id='Main']/table[@id='Photo']/tbody/tr/td[2]/p[1]",before);
138                                 this.move("/html/body/div[@id='Main']/table[@id='Photo']/tbody/tr/td[2]/p[2]",before);
139                                 this.move("/html/body/div[@id='Main']/table[@id='Photo']/tbody/tr/td[2]/ul",before);
140                                 this.move("//div[@id='upload_form_container']",before);
141                                 this.move("//textarea[@id='texty']",before);
142                         }
143                 },
144                 move: function(xpath,to) {
145                         var node = $x1(xpath);
146                         if(node) 
147                                 to.parentNode.insertBefore(node,to);
148                 }
149         }
150         //======================================================================
151         // launch
152         try {
153                 window.addEventListener("load", function () {
154                                                                         try {
155                                                                                 
156                                                                                 // update automatically (http://userscripts.org/scripts/show/2296)
157                                                                                 win.UserScriptUpdates.requestAutomaticUpdates(SCRIPT);
158                                                                         } catch (ex) {} 
159                                                                         
160                                                                         var flickrgp = new flickrmoveadditionalinfo();
161                 }, false);
162         } catch (ex) {}
163 })();