Advertisement
decembre

GM - Flickr Buddy Interesting by P. Andrews - TWEAK- 2017

Aug 16th, 2016
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name    Flickr Buddy Interesting  by Pierre Andrews (Mortimer) - TWEAK Localize - 2017
  3. // @namespace   http://6v8.gamboni.org/
  4. // @description Quick access to user's interesting photos from the Buddy Icon Menu
  5. // @version        0.5
  6. // @identifier  http://6v8.gamboni.org/IMG/js/flickrbuddyinteresting.user.js
  7. // @date           2009-04-17
  8. // @creator        Pierre Andrews (mortimer.pa@free.fr)
  9. // @contributor    Stephen Fernandez ( http://steeev.freehostia.com )
  10. // @contributor    Ricardo Mendonca Ferreira
  11. //
  12. // @include http://*flickr.com*
  13. // @include http*://*flickr.com/*
  14.  
  15. // @exclude http://*flickr.com/groups/
  16. // @exclude http*://*flickr.com/groups
  17.  
  18. // @exclude     http*://services.addons.mozilla.org/*
  19.  
  20. // @grant       none
  21.  
  22. // ==/UserScript==
  23.  
  24. // --------------------------------------------------------------------
  25. //
  26. // This is a Greasemonkey user script.
  27. //
  28. // To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
  29. // Then restart Firefox and revisit this script.
  30. // Under Tools, there will be a new menu item to "Install User Script".
  31. // Accept the default configuration and install.
  32. //
  33. // --------------------------------------------------------------------
  34. // Copyright (C) 2006 Pierre Andrews
  35. //
  36. // This program is free software; you can redistribute it and/or
  37. // modify it under the terms of the GNU General Public License
  38. // as published by the Free Software Foundation; either version 2
  39. // of the License, or (at your option) any later version.
  40. //
  41. // This program is distributed in the hope that it will be useful,
  42. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  43. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  44. // GNU General Public License for more details.
  45. //
  46. // The GNU General Public License is available by visiting
  47. //   http://www.gnu.org/copyleft/gpl.html
  48. // or by writing to
  49. //   Free Software Foundation, Inc.
  50. //   51 Franklin Street, Fifth Floor
  51. //   Boston, MA  02110-1301
  52. //   USA
  53.  
  54. debugger;
  55.  
  56. (function () {
  57.  
  58.     //update information
  59.     var SCRIPT = {
  60.         name: "Flickr Buddy Interesting",
  61.         namespace: "http://6v8.gamboni.org/",
  62.         description: "Quick access to user's interesting photos from the Buddy Icon Menu",
  63.         identifier: "http://6v8.gamboni.org/IMG/js/flickrbuddyinteresting.user.js",
  64.         version: "0.5",                             // version
  65.         date: (new Date("2009-04-17"))      // update date
  66.         .valueOf()
  67.     };
  68.  
  69.  
  70.     function $x1(xpath) {
  71.         return document.evaluate(
  72.                                  xpath,
  73.                                  document,
  74.                                  null,
  75.                                  XPathResult.FIRST_ORDERED_NODE_TYPE, null
  76.                                  ).singleNodeValue;
  77.     }
  78.  
  79.  
  80.     /***********************************************************************
  81.      * Flickr Localisation (changes TAMPERMONKEY : line 83>85 )
  82.      **********************************************************************/
  83.  
  84.         // LOCALISATION TWEAKED
  85.     //FlickrLocalisation, script to help localise user script for Flickr
  86.     //version 0.2
  87.     //release 26 Jun 2007
  88.     //author: Pierre Andrews
  89.  
  90.     // --------------------------------------------------------------------
  91.     // Copyright (C) 2007 Pierre Andrews
  92.     // This script can be redistributed under the terms of the GNU LGPL, without
  93.     // modification of this licence and copyright notice. Attribution to the author should be
  94.     // kept at least in the source of the scripts.
  95.     // For reference: http://6v8.gamboni.org/Localising-Flickr-Greasemonkey.html
  96.     //
  97.     // This program is free software; you can redistribute it and/or
  98.     // modify it under the terms of the GNU Lesser General Public License
  99.     // as published by the Free Software Foundation;
  100.     //
  101.     // This program is distributed in the hope that it will be useful,
  102.     // but WITHOUT ANY WARRANTY; without even the implied warranty of
  103.     // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  104.     // GNU General Public License for more details.
  105.     //
  106.     // The GNU Lesser General Public License is available by visiting
  107.     //   http://www.gnu.org/copyleft/lgpl.html
  108.     // or by writing to
  109.     //   Free Software Foundation, Inc.
  110.     //   51 Franklin Street, Fifth Floor
  111.     //   Boston, MA  02110-1301
  112.     //   USA
  113.  
  114.  
  115.     var FlickrLocaliser = function(locals) {
  116.         this.init(locals);
  117.     }
  118.     FlickrLocaliser.prototype = {
  119.         selectedLang: undefined,
  120.         localisations: undefined,
  121.         getLanguage: function() {
  122.             if(!this.selectedLang) {
  123.                 var langA = document.evaluate(
  124. //"//p[@class='LanguageSelector']//a[contains(@class,'selected')]",
  125. // TWEAK DECEMBRE
  126. // PB Localisation example :
  127. // FIXED for HELP Forum - https://www.flickr.com/help/forum/88857/?search=sans
  128. //"//p[@class='.ui-dropdown.simple-drop.drop-up']//a[contains(@class,'selected')]",
  129. ".//*[@id='foot']/footer/div/div[1]/div/ul/li[10]/div//a[contains(@class,'selected')]",
  130.                                  document,
  131.                                  null,
  132.                                  XPathResult.FIRST_ORDERED_NODE_TYPE, null
  133.                                  ).singleNodeValue;
  134.                 if (!langA) { // new photo page layout
  135.                     var langA = document.evaluate(
  136.                                 "//div[@id='foot-lang']//a[contains(@class,'selected')]",
  137.                                 document,
  138.                                 null,
  139.                                 XPathResult.FIRST_ORDERED_NODE_TYPE, null
  140.                                 ).singleNodeValue;
  141.                 }
  142.                 if(langA) {
  143.                     var matches = /\/change_language.gne\?lang=([^&]+)&.*/.exec(langA.href);
  144.                     if(matches && matches[1]) {
  145.                         this.selectedLang = matches[1];
  146.                         return this.selectedLang;
  147.                     }
  148.                 }
  149.                 return false;
  150.             } else return this.selectedLang;
  151.         },
  152.  
  153.         init: function(locals) {
  154.             this.localisations = locals;
  155.         },
  156.  
  157.         localise: function(string, params) {
  158.             if(this.localisations && this.getLanguage()) {
  159.                 var currentLang = this.localisations[this.selectedLang];
  160.                 if(!currentLang) currentLang = this.localisations[this.localisations.defaultLang];
  161.                 var local = currentLang[string];
  162.                 if(!local) {
  163.                     local = this.localisations[this.localisations.defaultLang][string];
  164.                 }
  165.                 if(!local) return string;
  166.                 for(arg in params) {
  167.                     var rep = new RegExp('@'+arg+'@','g');
  168.                     local = local.replace(rep,params[arg]);
  169.                 }
  170.                 local =local.replace(/@[^@]+@/g,'');
  171.                 return local;
  172.             } else return undefined;
  173.         }
  174.  
  175.     }
  176.  
  177.     /*****************************Flickr Localisation**********************/
  178.  
  179.  
  180.     var localiser =  new FlickrLocaliser({
  181.             'en-us' : {
  182.                 'pool_interesting' : 'Pool Interestingness',
  183.                 'quick_interesting' : 'Quick Interestingness',
  184.                 'close' : 'Close'
  185.             },
  186.             'fr-fr' : {
  187.                 'pool_interesting' : 'Interestingness du Groupe',
  188.                 'quick_interesting' : 'Interestingness Rapide',
  189.                 'close' : 'Fermer'
  190.             },
  191.             'it-it' : {
  192.                 'pool_interesting' : 'Interestingness del Gruppo',
  193.                 'quick_interesting' : 'Interestingness Rapida',
  194.                 'close' : 'Chiudi'
  195.             },
  196.             defaultLang: 'en-us'
  197.         });
  198.  
  199.     function M8_log() {
  200.         if(unsafeWindow.console)
  201.             unsafeWindow.console.log(arguments);
  202.         else
  203.             GM_log(arguments);
  204.     }
  205.  
  206.     /*
  207.       Xpath trickery, from:
  208.       http://ecmanaut.blogspot.com/2006/07/expressive-user-scripts-with-xpath-and.html
  209.     */
  210.     function $x( xpath, root )
  211.         {
  212.             var doc = root ? root.evaluate?root:root.ownerDocument : document;
  213.             var got = doc.evaluate( xpath, root||doc, null, 0, null ), next;
  214.             var result = [];
  215.             while( next = got.iterateNext() )
  216.                 result.push( next );
  217.             return result;
  218.         }
  219.  
  220.  
  221.     function foreach( xpath, cb, root )
  222.     {
  223.         var nodes = $x( xpath, root ), e = 0;
  224.         for( var i=0; i<nodes.length; i++ )
  225.             e += cb( nodes[i], i ) || 0;
  226.         return e;
  227.     }
  228.  
  229.  
  230.  
  231.     function getObjectMethodClosure(object, method) {
  232.         return function(arg) {
  233.             return object[method](arg);
  234.         }
  235.     }
  236.  
  237.     /*
  238.       LightWeightBox - Thom Shannon
  239.       http://www.ts0.com
  240.       V 1.0 2006
  241.       BSD License
  242.     */
  243.  
  244.     var LightWeightBoxOn=false;
  245.     var LightWeightBox = function(ele){
  246.         this.ele = ele;
  247.         this.backgroundColor = '#CCC';
  248.         this.opacity = 0.5;
  249.     }
  250.     with (LightWeightBox){
  251.         prototype.Render = function(){
  252.             if (!LightWeightBoxOn){
  253.                 bgDiv = document.createElement('div');
  254.                 bgDiv.innerHTML = ''
  255.                 bgDiv.style.backgroundColor = this.backgroundColor;
  256.                 bgDiv.style.position='fixed';
  257.                 bgDiv.style.height='100%';
  258.                 bgDiv.style.width='100%';
  259.                 bgDiv.style.top=0;
  260.                 bgDiv.style.left='0';
  261.                 bgDiv.style.opacity=this.opacity;
  262.                 this.ele.style.position='fixed';
  263.                 this.bgDiv=bgDiv;
  264.                 document.body.appendChild(this.bgDiv);
  265.                 document.body.appendChild(this.ele);
  266.                 this.CheckSize();
  267.                 LightWeightBoxOn = true;
  268.                 var oSelf=this;
  269.                 this.sizeCheck = setInterval(function(){oSelf.CheckSize();},20);
  270.             }
  271.         }
  272.         prototype.CheckSize = function(){
  273.             if (this.ele.offsetHeight!=this.currentHeight) {
  274.                 this.offsetTop = (self.innerHeight/2)-(this.ele.offsetHeight/2);
  275.                 this.ele.style.top = this.offsetTop+'px';
  276.                 this.currentHeight=this.ele.offsetHeight;
  277.             }
  278.             if (this.ele.offsetWidth!=this.currentWidth) {
  279.                 this.offsetLeft = (self.innerWidth/2)-(this.ele.offsetWidth/2);
  280.                 this.ele.style.left = this.offsetLeft+'px';
  281.                 this.currentWidth=this.ele.offsetWidth;
  282.             }
  283.         }
  284.  
  285.         prototype.Close=function(oSelf){
  286.             document.body.removeChild(oSelf.bgDiv);
  287.             document.body.removeChild(oSelf.ele);
  288.             LightWeightBoxOn = false;
  289.         }
  290.     }
  291.  
  292.  
  293.  
  294.     var flickrbuddyinteresting = function() {this.init();}
  295.  
  296.     flickrbuddyinteresting.prototype = {
  297.         init: function() {
  298.             var menu = document.getElementById('personmenu_contacts_link');
  299.             if(menu) {
  300.                 var link =document.createElement('a');
  301.                 link.setAttribute('class','block');
  302.                 link.setAttribute('id','tag_person_link');
  303.                 link.setAttribute('href','javascript:;');
  304.                 link.addEventListener('click',getObjectMethodClosure(this,'showInteresting'),true);
  305.                 link.textContent=localiser.localise('quick_interesting');
  306.  
  307.                 menu.parentNode.insertBefore(link,menu.nextSibling);
  308.             }
  309.  
  310. // decembre CONTACTS page - OK
  311.             //var who = getElementsByClassName('Icon');
  312.             //var menu = getElementsByClassName('personmenu-sep-bottom');
  313.  
  314. // <head>
  315. // <title>Who calls you a contact? | Contacts | flickr.com</title>
  316.  
  317. // <td class="contact-list-bicon">
  318. // <a rel="contact" href="/photos/muhammetsen/">
  319. // <img class="BuddyIconX" width="24" height="24" border="0" alt="senmuhammet" src="https://farm8.staticflickr.com/7122/buddyicons/135724433@N06.jpg?1462861443#135724433@N06">
  320.  
  321. // div id="person_hover" style="left: 242px; top: 107px; display: block;">
  322. // <div id="person_hover_shadow" class="shadowDark"></div>
  323. // <div id="person_hover_inner">
  324. // <a id="person_hover_link" href="https://www.flickr.com/photos/muhammetsen/" style="display: block;">
  325. // <img id="hover_img135458416@N03" class="person_hover_img">
  326. // <img id="hover_img135724433@N06" class="person_hover_img" src="https://farm8.staticflickr.com/7122/buddyicons/135724433@N06.jpg?1462861443#135724433@N06" style="display: block; visibility: visible;" title="">
  327.  
  328.             var title = document.getElement('Who');
  329.             if(title) {
  330.                 var link =document.createElement('a');
  331.                 link.setAttribute('class','block');
  332.                 link.setAttribute('id','tag_person_link');
  333.                 link.setAttribute('href','javascript:;');
  334.                 link.addEventListener('click',getObjectMethodClosure(this,'showInteresting'),true);
  335.                 link.textContent=localiser.localise('quick_interesting');
  336.  
  337.                 menu.parentNode.insertBefore(link,menu.nextSibling);
  338.             }
  339.            
  340. // decembre TEST PHOTO PAGE
  341.             //var who = getElementsByClassName('Icon');
  342.             //var menu = getElementsByClassName('personmenu-sep-bottom');
  343.             var userinfo = document.getElement('personCardMessageClick');
  344.             if(userinfo) {
  345.                 var link =document.createElement('a');
  346.                 link.setAttribute('class','block');
  347.                 link.setAttribute('id','tag_person_link');
  348.                 link.setAttribute('href','javascript:;');
  349.                 link.addEventListener('click',getObjectMethodClosure(this,'showInteresting'),true);
  350.                 link.textContent=localiser.localise('quick_interesting');
  351.  
  352.                 menu.parentNode.insertBefore(link,userinfo.nextSibling);
  353.             }          
  354. // END TEST PHOTO PAGE
  355.  
  356. // POOLS - NOT WORKING ?
  357.            
  358.             if(document.location.href.match(/\/groups\//) && unsafeWindow.document.getElementById('SubNav')) {
  359.                 psi=$x1('//p[@class="LinksNewP"]');
  360.                 psi.innerHTML+=' <img src="/images/subnavi_dots.gif" alt="" height="11" width="1"> ';
  361.                 var link =document.createElement('a');
  362.                 link.setAttribute('class','block');;
  363.                 link.setAttribute('href','javascript:;');
  364.                 link.addEventListener('click',getObjectMethodClosure(this,'showInteresting'),true);
  365.                 link.textContent=localiser.localise('pool_interesting');
  366.                 psi.appendChild(link);
  367.  
  368.             }
  369. // END POOLS - NOT WORKING ?
  370.  
  371. // PROFILE - NOT WORKING ?
  372.             var menu2 = document.getElementById('button-bar');
  373.             if(profile) {
  374.                 var link =document.createElement('a');
  375.                 link.setAttribute('class','block');
  376.                 link.setAttribute('id','tag_person_link');
  377.                 link.setAttribute('href','javascript:;');
  378.                 link.addEventListener('click',getObjectMethodClosure(this,'showInteresting'),true);
  379.                 link.textContent=localiser.localise('quick_interesting');
  380.  
  381.                 menu2.parentNode.insertBefore(link,menu2.nextSibling);
  382.             }
  383. // END - PROFILE - NOT WORKING ?
  384.  
  385.         },
  386.  
  387.         showInteresting: function(ev) {
  388.             // create a block element of some kind
  389.             var boxEle = document.createElement('div');
  390.             var ul = boxEle.appendChild(document.createElement('ul'));
  391.             // style it up with a class or inline
  392.             boxEle.className = 'popup';
  393.             // create something to act as a close button
  394.             btnClose = document.createElement('a');
  395.             btnClose.href='javascript:;';
  396.             btnClose.innerHTML=localiser.localise('close');
  397.             // add close button to block element
  398.             boxEle.appendChild(btnClose);
  399.             // create box with block element
  400.             var lwBox = new LightWeightBox(boxEle);
  401.             // optional bg color and opacity
  402.             boxEle.style.paddingTop= '20px';
  403.             boxEle.style.width= (75*5+20)+'px';
  404.             boxEle.style.height= (75*5+40)+'px';
  405.             boxEle.style.backgroundColor = '#333';
  406.             // attach close event and add your own code
  407.             btnClose.addEventListener('click',function(){
  408.                     // you have to pass box object into event
  409.                     // because of the js event scoping
  410.                     lwBox.Close(lwBox);
  411.                     // false to cancel link
  412.                     return false;
  413.                 },true);
  414.             btnClose.setAttribute('style','background-color:#CCC;');
  415.  
  416.             ul.setAttribute('style','margin:0;padding:0;list-style-type:none;');
  417.             var self = this;
  418.             var listener = {
  419.                 flickr_photos_search_onLoad: function(success, responseXML, responseText, params){
  420.                     try{
  421.                         var rsp = responseText.replace(/jsonFlickrApi\(/,'');
  422.                         rsp = eval('('+rsp);
  423.                         if(rsp.stat == 'ok') {
  424.                             var i=0;
  425.                             var html = '';
  426.                             for(i=0;i<rsp.photos.photo.length;i++) {
  427.                                 var photo = rsp.photos.photo[i];
  428.                                 html += '<li style="margin:0;padding:0;display:inline;"><a href="https://www.flickr.com/photos/'+photo.owner+'/'+photo.id+'/"><img title="&quot;' + photo.title + '&quot; by ' +  photo.ownername + '" src="https://farm'+photo.farm+'.static.flickr.com/'+photo.server+'/'+photo.id+'_'+photo.secret+'_s.jpg" width="75" height="75"/></a></li>';
  429.                             }
  430.                             ul.innerHTML = html;
  431.                             // render it!
  432.                             lwBox.Render();
  433.                         } else
  434.                             M8_log("Error2 "+responseText);
  435.                     } catch (e) {
  436.                         M8_log("Error1 "+responseText);
  437.                         M8_log(e);
  438.                     }
  439.                 }
  440.             };
  441. // TWEAKED 25 > 150 or 250 pics
  442.             var block = ev.target.parentNode;
  443.             var matches = /mail\/write\/\?to=([^"]*)"/.exec(block.innerHTML);
  444.                                                      if(matches)
  445.                                                          unsafeWindow.F.API.callMethod('flickr.photos.search', {
  446.                                                                  user_id: matches[1], sort: 'interestingness-desc', page:1, per_page: 253,
  447.                                                                      format: 'json', extras: 'owner_name'
  448.                                                                      }, listener);
  449.  
  450.                                                      if(ev.target.textContent==localiser.localise('pool_interesting')) {
  451.                                                          thegroupid=unsafeWindow.document.getElementById('SubNav').innerHTML.split('\/buddyicons\/')[1].split('\.jpg')[0];
  452.                                                          unsafeWindow.F.API.callMethod('flickr.photos.search', {
  453.                                                                  group_id: thegroupid , sort: 'interestingness-desc', page:1, per_page: 253,
  454.                                                                      format: 'json', extras: 'owner_name'
  455.                                                                      }, listener);
  456.                                                      }
  457.                                                      }
  458.                                                     }
  459.             //======================================================================
  460.             // launch
  461.             try {
  462.                 window.addEventListener("load", function () {
  463.                         try {
  464.  
  465.                             // update automatically (http://userscripts.org/scripts/show/2296)
  466.                             win.UserScriptUpdates.requestAutomaticUpdates(SCRIPT);
  467.                         } catch (ex) {}
  468.  
  469.                         var flickrgp = new flickrbuddyinteresting();
  470.                     }, false);
  471.             } catch (ex) {}
  472.         })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement