Oracle iAcademy suckless

Basic Syntax Highlighting and Auto-Completion. Enter key intelligently Auto-completes or Auto-Runs the query. Table names completion NYI.

  1. // ==UserScript==
  2. // @name Oracle iAcademy suckless
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.2
  5. // @description Basic Syntax Highlighting and Auto-Completion. Enter key intelligently Auto-completes or Auto-Runs the query. Table names completion NYI.
  6. // @author You
  7. // @match https://iacademy.oracle.com/*
  8. // @require https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.21.0/codemirror.js
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.21.0/addon/hint/show-hint.js
  10. // @require https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.21.0/addon/hint/sql-hint.js
  11. // @require https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.21.0/mode/sql/sql.js
  12. // @require https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.21.0/addon/selection/active-line.js
  13. // @require https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.21.0/addon/edit/matchbrackets.js
  14. // ==/UserScript==
  15.  
  16. // Like this? Share with your class! Send them a link to:
  17. // https://greasyfork.org/en/scripts/25355-oracle-iacademy-suckless
  18.  
  19. // Know javascript? Please Takeover! I wrote this on the last day of class, there is lots of room for improvement!
  20. // Post your forks on greasyfork and send me a link in feedback. I will redirect people to the most up-to-date script.
  21.  
  22. function importScript(src) {
  23. var script = document.createElement('script');
  24. script.type = "text/javascript";
  25. script.src = src;
  26. document.body.appendChild(script);
  27. return script;
  28. }
  29. function importCSS(src) {
  30. var script = document.createElement('link');
  31. script.type = "text/css";
  32. script.rel='stylesheet';
  33. script.href = src;
  34. document.head.appendChild(script);
  35. return script;
  36. }
  37. importCSS("https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.21.0/codemirror.css");
  38. importCSS("https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.21.0/addon/hint/show-hint.css");
  39.  
  40. importCSS("https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.21.0/theme/neonsyntax.css");
  41. //importScript();
  42.  
  43. // Wait a second or lineNumber will develop a overlaping problem
  44. setTimeout(function() {
  45.  
  46. var ExcludedIntelliSenseTriggerKeys =
  47. {
  48. "8": "backspace",
  49. "9": "tab",
  50. "13": "enter",
  51. "16": "shift",
  52. "17": "ctrl",
  53. "18": "alt",
  54. "19": "pause",
  55. "20": "capslock",
  56. "27": "escape",
  57. "33": "pageup",
  58. "34": "pagedown",
  59. "35": "end",
  60. "36": "home",
  61. "37": "left",
  62. "38": "up",
  63. "39": "right",
  64. "40": "down",
  65. "45": "insert",
  66. "46": "delete",
  67. "91": "left window key",
  68. "92": "right window key",
  69. "93": "select",
  70. "107": "add",
  71. "109": "subtract",
  72. "110": "decimal point",
  73. "111": "divide",
  74. "112": "f1",
  75. "113": "f2",
  76. "114": "f3",
  77. "115": "f4",
  78. "116": "f5",
  79. "117": "f6",
  80. "118": "f7",
  81. "119": "f8",
  82. "120": "f9",
  83. "121": "f10",
  84. "122": "f11",
  85. "123": "f12",
  86. "144": "numlock",
  87. "145": "scrolllock",
  88. "186": "semicolon",
  89. "187": "equalsign",
  90. "188": "comma",
  91. "189": "dash",
  92. "190": "period",
  93. "191": "slash",
  94. "192": "graveaccent",
  95. "220": "backslash",
  96. "222": "quote"
  97. };
  98.  
  99.  
  100. var RunBtn = document.getElementsByClassName('aButton hotButton')[0];
  101. var RunSQL_Cmd;
  102. if (RunBtn.textContent == 'Run') {
  103. RunSQL_Cmd = RunBtn.onclick;
  104. }
  105. var SQL_Box = document.getElementById('P1003_SQL_COMMAND1');
  106. CodeMirror.commands.autocomplete = function(cm) {
  107. CodeMirror.showHint(cm, CodeMirror.hint.sql);
  108. };
  109. var SQL_Mirror = CodeMirror.fromTextArea(SQL_Box, {
  110. mode: "text/x-sql",
  111. //theme: "neonsyntax",
  112. lineWrapping: true,
  113. lineNumbers: true,
  114. styleActiveLine: true,
  115. extraKeys: {
  116. "Ctrl-Space": "autocomplete"
  117. },
  118. matchBrackets: true,
  119. });
  120. SQL_Mirror.on("keyup", function(editor, event) {
  121. var __Cursor = editor.getDoc().getCursor();
  122. var __Token = editor.getTokenAt(__Cursor);
  123.  
  124. if (!editor.state.completionActive &&
  125. !ExcludedIntelliSenseTriggerKeys[(event.keyCode || event.which).toString()] &&
  126. (__Token.type == "tag" || __Token.string == " " || __Token.string == "<" || __Token.string == "/" ))
  127. {
  128. CodeMirror.commands.autocomplete(editor, null, { completeSingle: false });
  129. } else if (event.keyCode == 13 && event.shiftKey === false) {
  130. RunSQL_Cmd();
  131. // TODO eat the enter keypress
  132. }
  133. });
  134. SQL_Mirror.setSize(SQL_Box.style.width, '100%');
  135. SQL_Mirror.on("change", function(cm, change) { cm.save(); });
  136.  
  137.  
  138.  
  139. }, 1000);