Advertisement
decembre

GM - Flickr ShowAllGroups - Profile ONLY - Vispillo - 2017

Jun 30th, 2015
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Flickr - ShowAllGroups - Profile ONLY - vispillo - OK 2017 - HTTPS - NEW REQUIRE - GRANTS
  3. // @namespace      vispillo
  4. // @grant           none
  5. // @include          http*://www.flickr.com/people/*
  6.  
  7. // @require        http://code.jquery.com/jquery-1.4.2.min.js
  8. // @grant       none
  9.  
  10.  
  11. // ==/UserScript==
  12.  
  13. function addGlobalStyle(css) {
  14.   var head, style;
  15.   head = document.getElementsByTagName('head')[0];
  16.   if (!head) {
  17.     return;
  18.   }
  19.   style = document.createElement('style');
  20.   style.type = 'text/css';
  21.   style.innerHTML = css;
  22.   head.appendChild(style);
  23. }
  24.  
  25. jQuery.noConflict();
  26. if (window.location.href.indexOf('flickr.com/people') == -1) {
  27.   addGlobalStyle('#group-placeholder { display:none !important }');
  28.   addGlobalStyle('li.sidebar-context-pool { display:block !important }');
  29.  
  30.   ul = document.getElementById('secondary-contexts');
  31.   all = ul.getElementsByClassName('sidebar-context');
  32.   sets = new Array;
  33.   var sortedKeys = new Array;
  34.   var pools = new Array;
  35.   for (i in all) {
  36.     try {
  37.     if (all[i].getAttribute('data-context-type') != undefined) {
  38.       if (all[i].getAttribute('data-context-type') == 'set') {
  39.         sets.push(all[i]);
  40.       }
  41.     }
  42.     } catch (e) {
  43.     }
  44.   }
  45.   for (i = 0; i < sets.length; i++) {
  46.     pools[sets[i].getElementsByClassName('context-title')[0].getAttribute('title')] = sets[i];
  47.     sortedKeys.push(sets[i].getElementsByClassName('context-title')[0].getAttribute('title'));
  48.   }
  49.   sortedKeys.sort(function(x, y) {
  50.     var a = String(x).toUpperCase();
  51.     var b = String(y).toUpperCase();
  52.     if (a > b) return 1
  53.     if (a < b) return -1
  54.     return 0;
  55.   });
  56.   for (i = 0; i < sortedKeys.length; i++) {
  57.     ul.appendChild(pools[sortedKeys[i]]);
  58.   }
  59.  
  60.   lis = ul.getElementsByClassName('sidebar-context-pool');
  61.   var sortedKeys = new Array;
  62.   var pools = new Array;
  63.   for (i = 0; i < lis.length; i++) {
  64.     pools[lis[i].getElementsByClassName('context-title')[0].getAttribute('title')] = lis[i];
  65.     sortedKeys.push(lis[i].getElementsByClassName('context-title')[0].getAttribute('title'));
  66.   }
  67.   sortedKeys.sort(function(x, y) {
  68.     var a = String(x).toUpperCase();
  69.     var b = String(y).toUpperCase();
  70.     if (a > b) return 1
  71.     if (a < b) return -1
  72.     return 0;
  73.   });
  74.   for (i = 0; i < sortedKeys.length; i++) {
  75.     ul.appendChild(pools[sortedKeys[i]]);
  76.   }
  77. }
  78. else {
  79.   try {
  80.     document.getElementById('show-groups-bottom').setAttribute('style', 'display:none');
  81.     num = document.getElementById('show-groups-top').innerHTML;
  82.     document.getElementById('show-groups-top').parentNode.innerHTML = '(' + num + ')';
  83.   } catch (e) {}
  84.   if (num == 50) {
  85.     nsid = jQuery('img.sn-avatar-ico').attr('src').split('#')[1];
  86.     fetchGroups(nsid)
  87.   }
  88.   else {
  89.     sortProfilePage();
  90.   }
  91. }
  92.  
  93. function fetchGroups(nsid) {
  94.  
  95.   jQuery('#groups span.header-count').html('').append('<img style="height: 8px; width: 16px;" src="https://l.yimg.com/www.flickr.com/images/pulser2.gif" />');
  96.   hash = unsafeWindow.global_auth_hash;
  97.   key = unsafeWindow.global_magisterLudi;
  98.  
  99.   url = 'https://www.flickr.com/services/rest/?method=flickr.people.getPublicGroups&user_id=' + nsid + '&format=json&nojsoncallback=1&api_key=' + key + '&auth_hash=' + hash;
  100.   var existing;
  101.   total = 50;
  102.   jQuery('#groups-page-1 li a').each(function(k, val) {
  103.     existing += jQuery(val).text();
  104.   });
  105.   jQuery.getJSON(url, function(data) {
  106.     if (data.stat == 'ok') {
  107.       jQuery.each(data.groups.group, function(i, val) {
  108.         bgcol = '#fff';
  109.         if (val.admin) {
  110.           // bgcol = '#ddd';
  111.         }
  112.         if (existing.indexOf(val.name) != -1) {
  113.           // jQuery('li:contains("'+val.name.replace(/\)/gi,'\\\\)').replace(/\(/gi,'\\\\(')+'")').css('background-color',bgcol);
  114.         } else {
  115.           jQuery('<li class="" style="background-color:'+bgcol+'"><a href="/groups/' + val.nsid + '/" >' + val.name + '</a><span class="group-info"></span></li>').appendTo('#groups-page-1');
  116.           total++;
  117.         }
  118.       });
  119.       jQuery('#groups span.header-count').html('(' + total + ')')
  120.       sortProfilePage();
  121.     }
  122.   });
  123. }
  124.  
  125. function sortProfilePage() {
  126.   lis = jQuery('#groups-page-1 li');
  127.   var pools = new Array;
  128.   var sortedKeys = new Array;
  129.   lis.each(function(i, val) {
  130.     val.setAttribute('class', '');
  131.     pools[jQuery(val).find('a').text()] = val;
  132.     sortedKeys.push(jQuery(val).find('a').text());
  133.   });
  134.   sortedKeys.sort(function(x, y) {
  135.     var a = String(x).toLowerCase().replace(/^\ +/g, '');
  136.     var b = String(y).toLowerCase().replace(/^\ +/g, '');
  137.     if (a > b) return 1
  138.     if (a < b) return -1
  139.     return 0;
  140.   });
  141.  
  142.   for (i = 0; i < sortedKeys.length; i++) {
  143.     jqli = jQuery(pools[sortedKeys[i]]);
  144.     if (jqli.find('a').length == 1) {
  145.       jqli.append('<a title="Photos by '+document.title.replace(/^Flickr: /,'')+' in group '+jqli.find('a').text()+'" href="'+jqli.find('a').attr('href')+'pool/'+jQuery('img.sn-avatar-ico').attr('src').split('#')[1]+'/">▣</a>');
  146.     }
  147.     jqli.appendTo('#groups-page-1');
  148.   }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement