Flickr - AUTO ShowAllGroups (Photo Page) v.3.0

Auto Expand all groups on photo page (author of the Library: Brock Adams , fork decembre)

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