Advertisement
decembre

GM - Flickr - Photo Page ShowAllGroups v.2

Apr 10th, 2017
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name     Flickr - Photo Page ShowAllGroups v.2 - TEST OK - Adams (Exclude SET)
  3.  
  4. // @description    - Expand all groups on photo page (author of the Library: Brock Adams , fork decembre)
  5.  
  6.  
  7. // @include     http*://*flickr.com/*
  8. // @exclude    http*://www.flickr.com/photos/*/sets/*
  9.  
  10. // @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  11. // @autor    Brock Adams
  12.  
  13. // @grant    GM_addStyle
  14.  
  15. // ==/UserScript==
  16.  
  17. // FROM a script of Brock Adams (Thanks to him!)
  18. // in stackoverflow :
  19. // http://stackoverflow.com/questions/12252701/how-do-i-click-on-this-button-with-greasemonkey?lq=1
  20. // with :
  21. // https://gist.github.com/raw/2625891/waitForKeyElements.js
  22.  
  23. /*- The @grant directive is needed to work around a major design change
  24.     introduced in GM 1.0.
  25.     It restores the sandbox.
  26. */
  27.  
  28.  
  29. /*--- waitForKeyElements():  
  30.  
  31. FIND IT HERE :
  32. https://gist.github.com/raw/2625891/waitForKeyElements.js
  33.  
  34. A utility function, for Greasemonkey scripts,
  35.     that detects and handles AJAXed content.
  36.  
  37.     Usage example:
  38.  
  39.         waitForKeyElements (
  40.             "div.comments"
  41.             , commentCallbackFunction
  42.         );
  43.  
  44.         //--- Page-specific function to do what we want when the node is found.
  45.         function commentCallbackFunction (jNode) {
  46.             jNode.text ("This comment changed by waitForKeyElements().");
  47.         }
  48.  
  49.     IMPORTANT: This function requires your script to have loaded jQuery.
  50. */
  51. function waitForKeyElements (
  52.     selectorTxt,    /* Required: The jQuery selector string that
  53.                         specifies the desired element(s).
  54.                     */
  55.     actionFunction, /* Required: The code to run when elements are
  56.                         found. It is passed a jNode to the matched
  57.                         element.
  58.                     */
  59.     bWaitOnce,      /* Optional: If false, will continue to scan for
  60.                         new elements even after the first match is
  61.                         found.
  62.                     */
  63.     iframeSelector  /* Optional: If set, identifies the iframe to
  64.                         search.
  65.                     */
  66. ) {
  67.     var targetNodes, btargetsFound;
  68.  
  69.     if (typeof iframeSelector == "undefined")
  70.         targetNodes     = $(selectorTxt);
  71.     else
  72.         targetNodes     = $(iframeSelector).contents ()
  73.                                            .find (selectorTxt);
  74.  
  75.     if (targetNodes  &&  targetNodes.length > 0) {
  76.         btargetsFound   = true;
  77.         /*--- Found target node(s).  Go through each and act if they
  78.             are new.
  79.         */
  80.         targetNodes.each ( function () {
  81.             var jThis        = $(this);
  82.             var alreadyFound = jThis.data ('alreadyFound')  ||  false;
  83.  
  84.             if (!alreadyFound) {
  85.                 //--- Call the payload function.
  86.                 var cancelFound     = actionFunction (jThis);
  87.                 if (cancelFound)
  88.                     btargetsFound   = false;
  89.                 else
  90.                     jThis.data ('alreadyFound', true);
  91.             }
  92.         } );
  93.     }
  94.     else {
  95.         btargetsFound   = false;
  96.     }
  97.  
  98.     //--- Get the timer-control variable for this selector.
  99.     var controlObj      = waitForKeyElements.controlObj  ||  {};
  100.     var controlKey      = selectorTxt.replace (/[^\w]/g, "_");
  101.     var timeControl     = controlObj [controlKey];
  102.  
  103.     //--- Now set or clear the timer as appropriate.
  104.     if (btargetsFound  &&  bWaitOnce  &&  timeControl) {
  105.         //--- The only condition where we need to clear the timer.
  106.         clearInterval (timeControl);
  107.         delete controlObj [controlKey]
  108.     }
  109.     else {
  110.         //--- Set a timer, if needed.
  111.         if ( ! timeControl) {
  112.             timeControl = setInterval ( function () {
  113.                     waitForKeyElements (    selectorTxt,
  114.                                             actionFunction,
  115.                                             bWaitOnce,
  116.                                             iframeSelector
  117.                                         );
  118.                 },
  119.                 300
  120.             );
  121.             controlObj [controlKey] = timeControl;
  122.         }
  123.     }
  124.     waitForKeyElements.controlObj   = controlObj;
  125. }
  126.  
  127.  
  128.  
  129. //--- Note that contains() is CASE-SENSITIVE.
  130. //waitForKeyElements ("a.simplebutton:contains('follow')", clickOnFollowButton);
  131. // .view-all-contexts-of-type>a
  132. waitForKeyElements (".view-all-contexts-of-type>a", clickOnFollowButton);
  133.  
  134. function clickOnFollowButton (jNode) {
  135.     var clickEvent  = document.createEvent ('MouseEvents');
  136.     clickEvent.initEvent ('click', true, true);
  137.     jNode[0].dispatchEvent (clickEvent);
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement