Greasy Fork is available in English.

docsReady

A JavaScript to run script when docs is ready

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/29782/603586/docsReady.js

  1. // ==UserScript==
  2. // @name docsReady
  3. // @namespace xuyiming.open@outlook.com
  4. // @description A JavaScript to run script when docs is ready
  5. // @author xymopen
  6. // @version 1.0.1
  7. // @grant none
  8. // @license BSD 2-Clause
  9. // @homepageURL https://github.com/xymopen/JS_Misc/blob/master/docsReady.js
  10. // @updateURL https://raw.githubusercontent.com/xymopen/JS_Misc/master/docsReady.js
  11. // ==/UserScript==
  12.  
  13. function domReady( onReady, contextWindow ) {
  14. var excuted = false;
  15.  
  16. function onDelayedReady( event ) {
  17. if ( !excuted ) {
  18. excuted = true;
  19. onReady( event );
  20. }
  21. }
  22.  
  23. if ( !contextWindow ) {
  24. contextWindow = window;
  25. }
  26.  
  27. if ( "interactive" == contextWindow.document.readyState ) {
  28. onReady();
  29. } else {
  30. contextWindow.document.addEventListener( "DOMContentLoaded", onDelayedReady );
  31. }
  32.  
  33. // In case DOMContentLoaded was not supported or not emitted or missed
  34. allReady( onDelayedReady, contextWindow );
  35. }
  36.  
  37. function allReady( onReady, contextWindow ) {
  38. if ( !contextWindow ) {
  39. contextWindow = window;
  40. }
  41.  
  42. if ( "complete" == contextWindow.document.readyState ) {
  43. onReady();
  44. } else {
  45. contextWindow.addEventListener( "load", onReady );
  46. }
  47. }
  48.  
  49. function frameReady( onReady, contextFrame ) {
  50. if ( "complete" == contextFrame.contentDocument.readyState ) {
  51. onReady();
  52. }
  53.  
  54. contextFrame.addEventListener( "load", onReady );
  55. }