Better GreasyFork Code Reader + JS Beautifier

Show the Codes page of any script on GreasyFork With all code lines background in white and beautify them if you want. With this script, you can also Beautify your UserScripts before publishing them.

Installer dette script?
Skaberens foreslåede script

Du vil måske også kunne lide Better GreasyFork Forum

Installer dette script
  1. // ==UserScript==
  2. // @name Better GreasyFork Code Reader + JS Beautifier
  3. // @namespace BetterGreasyCodeReader
  4. // @version 18
  5. // @description Show the Codes page of any script on GreasyFork With all code lines background in white and beautify them if you want. With this script, you can also Beautify your UserScripts before publishing them.
  6. // @author hacker09
  7. // @include https://greasyfork.org/*/script_versions/new
  8. // @include https://greasyfork.org/*/scripts/*/versions/new
  9. // @icon https://t2.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=https://greasyfork.org/&size=64
  10. // @exclude https://greasyfork.org/*/script_versions/new?language=css
  11. // @include /^https:\/\/greasyfork\.org\/(?:[^\/]+\/)scripts\/(?:[^\/]+\/)code/
  12. // @require https://update.greasyfork.org/scripts/483495/js-beautify.js
  13. // @run-at document-end
  14. // @grant none
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19. const JS_Beautifier_Options = { //Beginning of the "Your Selected Options (JSON):" Content
  20. "indent_size": "2",
  21. "indent_char": " ",
  22. "max_preserve_newlines": "5",
  23. "preserve_newlines": true,
  24. "keep_array_indentation": false,
  25. "break_chained_methods": false,
  26. "indent_scripts": "normal",
  27. "brace_style": "collapse",
  28. "space_before_conditional": true,
  29. "unescape_strings": false,
  30. "jslint_happy": false,
  31. "end_with_newline": false,
  32. "wrap_line_length": "0",
  33. "indent_inner_html": false,
  34. "comma_first": false,
  35. "e4x": false,
  36. "indent_empty_lines": false
  37. }; //End of the "Your Selected Options (JSON):" Content
  38.  
  39. var LiCurrentISCode; //Makes the variable global
  40. //******************************************************************************************************************************************************************
  41. if (location.href.match(/^https:\/\/greasyfork\.org\/(?:[^\/]+\/)scripts\/(?:[^\/]+\/)code/)) //If the user is reading a code page
  42. { //Starts the if condition
  43. LiCurrentISCode = true; //Set the variable as true
  44. window.onload = (function() { //Starts the setTimeout function
  45. if (LiCurrentISCode) { //Run only on the Code page
  46. const Lines = document.querySelectorAll("pre.linenums.prettyprinted li"); //Create a variable to hold the total Code Lines
  47. for (var i = Lines.length; i--;) { //Starts the for condition
  48. Lines[i].setAttribute("style", "background: none;box-shadow: -1px 1px 2px rgba(255, 211, 0, 0.2);"); //Remove the grey line background and add a zebbra line effect
  49. } //Finishes the for condition
  50. } //Finishes the if condition
  51. }); //Finishes the setTimeout function
  52. } //Finishes the if condition
  53. //******************************************************************************************************************************************************************
  54. document.querySelector("#script-feedback-suggestion") !== null ? document.querySelector("#script-feedback-suggestion").insertAdjacentHTML('beforeend', "<input type='checkbox' class='Beautify'><label>Beautify JS Codes</label>") : document.querySelector("label.checkbox-label").insertAdjacentHTML('afterEnd', "<input type='checkbox' class='Beautify'><label>Beautify JS Codes</label>"); //Add the input check box on the page
  55. var CodeBackup, CodeTextElement, SourceEditorCheck, IsNewScriptPage; //Makes these variables global
  56.  
  57. if (LiCurrentISCode !== true) { //If the li element doesn't exist
  58. LiCurrentISCode = false; //Set the variable as false
  59. } //Finishes the if condition
  60.  
  61. if (location.href.match('versions/new') !== null) { //Run only on the Post new script page
  62.  
  63. document.querySelector("#enable-source-editor-code").onclick = function() { //When the checkbox is clicked
  64. if (document.querySelector("#enable-source-editor-code").checked === true) { //If the SourceEditor is enabled
  65. document.querySelector("input.Beautify").disabled = true; //Disable the Beautifier button
  66. } //Finishes the if condition
  67. else { //Starts the else condition
  68. document.querySelector("input.Beautify").disabled = false; //Enable the Beautifier button
  69. } //Finishes the else condition
  70. }; //Finishes the onclick listener
  71.  
  72. SourceEditorCheck = document.querySelector("#enable-source-editor-code").checked === false; //Define the SourceEditorCheck variable as false
  73. CodeTextElement = document.querySelector("#script_version_code").value; //Store the CodeTextElement to a variable
  74. IsNewScriptPage = true; //Set the variable as true
  75. } //Finishes the if condition
  76.  
  77. document.querySelector("input.Beautify").onclick = function() { //When the checkbox is clicked
  78. if (LiCurrentISCode) { //Run only on the Code page
  79. CodeTextElement = document.querySelector("ol.linenums").innerText; //Store the CodeTextElement to a variable
  80. SourceEditorCheck = true; //Define the SourceEditorCheck variable as true
  81. } //Finishes the if condition
  82.  
  83. if (IsNewScriptPage) { //Run only on the Post new script page
  84. SourceEditorCheck = document.querySelector("#enable-source-editor-code").checked === false; //Define the SourceEditorCheck variable as false
  85. CodeTextElement = document.querySelector("#script_version_code").value; //Store the CodeTextElement to a variable
  86. } //Finishes the if condition
  87.  
  88. if (document.querySelector("input.Beautify").checked && SourceEditorCheck) { //Check if the Beautify checkbox is being checked and the syntax-highlighting source editor checkbox isn't checked
  89. CodeBackup = CodeTextElement; //Backup the actual script codes
  90. const BeautifiedCodes = js_beautify(CodeTextElement, JS_Beautifier_Options); //Add the beautified codes to a variable
  91. LiCurrentISCode !== true ? document.querySelector("#script_version_code").value = BeautifiedCodes : document.querySelector("ol.linenums").innerText = BeautifiedCodes; //Replaces the UnBeautified codes with the Beautified Codes
  92. } else { //Starts the else condition
  93. LiCurrentISCode !== true ? document.querySelector("#script_version_code").value = CodeBackup : document.querySelector("ol.linenums").innerText = CodeBackup; //If the checkbox is being unchecked, return the old UnBeautified Codes
  94. } //Finishes the else condition
  95. }; //Finishes the onclick listener
  96. })();