Userscripts show includes

Show includes for scripts on userscripts.org

  1. // Recent changes
  2. // 1.0.5 Added script update checker
  3. // 1.0.6 Minor fix
  4. // 1.1.0 Added "Stop update" button to the userscripts.com main menu while updating
  5. // 1.1.1 Bug fix in update checker
  6. // 1.1.2 Bug fix in update checker
  7. // 1.1.3 Bug fix in node handling
  8. // 1.1.4 Update checker is now only available for logged in user due to ads display problem
  9. // 1.2.0 Update checker is now also working for not logged in users
  10. // 1.2.1 Bugfix for empty search results
  11. // 1.2.2 Fix for the userscripts.org update (all source lines are indented now)
  12. // 1.3.0 Script is handling the new ad on the userscripts source page
  13. // 1.4.0 Clicking into the userscripts.org search textbox suspends the update
  14. // 1.4.1 Now includes version 0.6.0 of SVC Script Version Checker
  15. // 1.4.2 Minor bugfix
  16. // 1.4.3 Fix for new userscripts.org design ... ad has been added at the bottom of the source page
  17. // 1.4.4 Bugfix: Update is stopped before you leave the /scripts page so using the back button will not execute two parallel updates
  18. // 1.5.0 Taking new userscript.org design into account
  19. //
  20. // ==UserScript==
  21. // @name Userscripts show includes
  22. // @namespace http://userscripts.org/users/75950
  23. // @description Show includes for scripts on userscripts.org
  24. // @include http://userscripts.org/scripts
  25. // @include http://userscripts.org/scripts?*
  26. // @include http://userscripts.org/scripts/search?*
  27. // @version 1.5.0
  28. // ==/UserScript==
  29.  
  30. var theScripts = Array();
  31. var theLinks = Array();
  32. var theScriptMeats = Array();
  33. var currentscript = 0;
  34. var scriptcount = 0;
  35. var oldHeading;
  36. var newMenuEntry;
  37. var theMainMenu;
  38. var activeSuspend=false;
  39.  
  40. function DoRequest() {
  41. GM_xmlhttpRequest({
  42. method: 'GET',
  43. url: 'http://userscripts.org/scripts/review/'+theScripts[currentscript],
  44. headers: {
  45. 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
  46. 'Accept': 'text/html',
  47. },
  48. onload: function(responseDetails) {
  49. var newelem=document.createElement('div');
  50. newelem.innerHTML=responseDetails.responseText;
  51. newelem.style.display='none';
  52. if(newelem.getElementsByClassName('ad')[0]!=undefined) newelem.getElementsByClassName('ad')[0].innerHTML='';
  53. if(newelem.getElementsByClassName('ad bottom')[0]!=undefined) newelem.getElementsByClassName('ad bottom')[0].innerHTML='';
  54. document.getElementsByTagName('body')[0].appendChild(newelem);
  55. newelem=document.getElementById('source');
  56. insertIncludes(newelem.innerHTML);
  57. newelem.parentNode.removeChild(newelem);
  58. }
  59. });
  60. }
  61.  
  62. function insertIncludes(theSource) {
  63. if(!activeSuspend) {
  64. var theMeat = document.createElement('p');
  65. theMeat.innerHTML='<b>Includes</b>';
  66. theScriptMeat[currentscript].appendChild(theMeat);
  67. var theLines = theSource.split('\n');
  68. for(i=0; i<theLines.length; i++) {
  69. theLines[i]=theLines[i].replace(/^\s+|\s+$/, "");
  70. if(theLines[i].indexOf('// @include')==0) {
  71. // insert a paragraph for each include line
  72. var theMeat = document.createElement('p');
  73. theMeat.innerHTML=theLines[i].substring(11).replace(/^\s+|\s+$/, "");
  74. theScriptMeat[currentscript].appendChild(theMeat);
  75. }
  76. }
  77. currentscript++;
  78. if(currentscript<scriptcount) {
  79. var theHeading=document.getElementById('content').getElementsByTagName('th')[0];
  80. theHeading.innerHTML=oldHeading+' (Updating script '+(currentscript+1)+' of '+scriptcount+')';
  81. DoRequest();
  82. } else {
  83. SuspendUpdate();
  84. }
  85. }
  86. }
  87.  
  88. function SuspendUpdate() {
  89. var theHeading=document.getElementById('content').getElementsByTagName('th')[0];
  90. theHeading.innerHTML=oldHeading;
  91. theMainMenu.removeChild(newMenuEntry);
  92. document.getElementsByName('q')[0].removeEventListener('click',HandleTextboxClick, false);
  93. }
  94.  
  95. function HandleTextboxClick(event) {
  96. currentscript=scriptcount;
  97. activeSuspend=true;
  98. SuspendUpdate();
  99. event.stopPropagation();
  100. event.preventDefault();
  101. }
  102.  
  103. window.addEventListener(
  104. 'load',
  105. function () {
  106. document.getElementsByName('q')[0].addEventListener('click',HandleTextboxClick, false);
  107. theLinks = document.getElementsByClassName('title');
  108. scriptcount = theLinks.length;
  109. if(scriptcount>0) {
  110. theScriptMeat = document.getElementsByClassName('script-meat');
  111. for(i=0; i<scriptcount; i++) {
  112. theScripts.push(theLinks[i].href.substring(36));
  113. }
  114. var theHeading=document.getElementById('content').getElementsByTagName('th')[0];
  115. oldHeading=theHeading.innerHTML;
  116. theHeading.innerHTML=oldHeading+' (Updating script '+(currentscript+1)+' of '+scriptcount+')';
  117. theMainMenu = document.getElementById('mainmenu');
  118. newMenuEntry = document.createElement('li');
  119. newMenuEntry.innerHTML = '<a id="stopupdate" href="#" rel="nofollow">Stop update</a>';
  120. theMainMenu.appendChild(newMenuEntry);
  121. newMenuEntry.addEventListener('click',
  122. function(event) {
  123. event.preventDefault();
  124. currentscript=scriptcount;
  125. activeSuspend=true;
  126. SuspendUpdate();
  127. }, false);
  128. DoRequest();
  129. }
  130. },
  131. true);
  132.  
  133. window.addEventListener(
  134. 'unload',
  135. function () {
  136. currentscript=scriptcount;
  137. activeSuspend=true;
  138. SuspendUpdate();
  139. },
  140. true);