waitForKeyElements_mirror

Another mirror of waitForKeyElements

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/498113/1395364/waitForKeyElements_mirror.js

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址