Advertisement
decembre

GM - Flickr Buddy Interesting - MATCH - TWEAK 2020 - NO TAMPERMONKEY (Why?) / OK VIOLENTMONKEY

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