Sleazy Fork is available in English.

wait_ForKeyElements

等待元素出現,再點擊

Цей скрипт не слід встановлювати безпосередньо. Це - бібліотека для інших скриптів для включення в мета директиву // @require https://update.sleazyfork.org/scripts/529226/1550082/wait_ForKeyElements.js

  1.  
  2. /*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
  3. that detects and handles AJAXed content.
  4.  
  5. Usage example:
  6.  
  7. waitForKeyElements (
  8. "div.comments"
  9. , commentCallbackFunction
  10. );
  11.  
  12. //--- Page-specific function to do what we want when the node is found.
  13. function commentCallbackFunction (jNode) {
  14. jNode.text ("This comment changed by waitForKeyElements().");
  15. }
  16.  
  17. IMPORTANT: This function requires your script to have loaded jQuery.
  18. */
  19. function waitForKeyElements (
  20. selectorTxt, /* Required: The jQuery selector string that
  21. specifies the desired element(s).
  22. */
  23. actionFunction, /* Required: The code to run when elements are
  24. found. It is passed a jNode to the matched
  25. element.
  26. */
  27. bWaitOnce, /* Optional: If false, will continue to scan for
  28. new elements even after the first match is
  29. found.
  30. */
  31. iframeSelector /* Optional: If set, identifies the iframe to
  32. search.
  33. */
  34. ) {
  35. var targetNodes, btargetsFound;
  36.  
  37. if (typeof iframeSelector == "undefined")
  38. targetNodes = $(selectorTxt);
  39. else
  40. targetNodes = $(iframeSelector).contents ()
  41. .find (selectorTxt);
  42.  
  43. if (targetNodes && targetNodes.length > 0) {
  44. btargetsFound = true;
  45. /*--- Found target node(s). Go through each and act if they
  46. are new.
  47. */
  48. targetNodes.each ( function () {
  49. var jThis = $(this);
  50. var alreadyFound = jThis.data ('alreadyFound') || false;
  51.  
  52. if (!alreadyFound) {
  53. //--- Call the payload function.
  54. var cancelFound = actionFunction (jThis);
  55. if (cancelFound)
  56. btargetsFound = false;
  57. else
  58. jThis.data ('alreadyFound', true);
  59. }
  60. } );
  61. }
  62. else {
  63. btargetsFound = false;
  64. }
  65.  
  66. //--- Get the timer-control variable for this selector.
  67. var controlObj = waitForKeyElements.controlObj || {};
  68. var controlKey = selectorTxt.replace (/[^\w]/g, "_");
  69. var timeControl = controlObj [controlKey];
  70.  
  71. //--- Now set or clear the timer as appropriate.
  72. if (btargetsFound && bWaitOnce && timeControl) {
  73. //--- The only condition where we need to clear the timer.
  74. clearInterval (timeControl);
  75. delete controlObj [controlKey]
  76. }
  77. else {
  78. //--- Set a timer, if needed.
  79. if ( ! timeControl) {
  80. timeControl = setInterval ( function () {
  81. waitForKeyElements ( selectorTxt,
  82. actionFunction,
  83. bWaitOnce,
  84. iframeSelector
  85. );
  86. },
  87. 300
  88. );
  89. controlObj [controlKey] = timeControl;
  90. }
  91. }
  92. waitForKeyElements.controlObj = controlObj;
  93. }