Greasy Fork is available in English.

GitHub Editor - Change Default Settings

change default settings for the github editor

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

  1. // ==UserScript==
  2. // @name GitHub Editor - Change Default Settings
  3. // @namespace https://greatest.deepsurf.us/users/649
  4. // @version 1.1.21
  5. // @description change default settings for the github editor
  6. // @author Adrien Pyke
  7. // @match *://github.com/*/new/*
  8. // @match *://github.com/*/edit/*
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @grant GM_registerMenuCommand
  12. // @require https://cdn.jsdelivr.net/gh/kufii/My-UserScripts@22210afba13acf7303fc91590b8265faf3c7eda7/libs/gm_config.js
  13. // @require https://cdn.jsdelivr.net/gh/fuzetsu/userscripts@ec863aa92cea78a20431f92e80ac0e93262136df/wait-for-elements/wait-for-elements.js
  14. // ==/UserScript==
  15.  
  16. (() => {
  17. 'use strict';
  18.  
  19. const Config = GM_config([
  20. {
  21. key: 'indentMode',
  22. label: 'Indent mode',
  23. default: 'tab',
  24. type: 'dropdown',
  25. values: [
  26. { value: 'space', text: 'Spaces' },
  27. { value: 'tab', text: 'Tabs' }
  28. ]
  29. },
  30. {
  31. key: 'indentWidth',
  32. label: 'Indent size',
  33. default: 4,
  34. type: 'dropdown',
  35. values: [2, 4, 8]
  36. },
  37. {
  38. key: 'wrapMode',
  39. label: 'Line wrap mode',
  40. default: 'off',
  41. type: 'dropdown',
  42. values: [
  43. { value: 'off', text: 'No wrap' },
  44. { value: 'on', text: 'Soft wrap' }
  45. ]
  46. }
  47. ]);
  48.  
  49. const updateDropdown = function (dropdown, value) {
  50. dropdown.value = value;
  51. const evt = document.createEvent('HTMLEvents');
  52. evt.initEvent('change', false, true);
  53. dropdown.dispatchEvent(evt);
  54. };
  55.  
  56. const applySettings = function (cfg) {
  57. const indentMode = document.querySelector('.js-code-indent-mode');
  58. const indentWidth = document.querySelector('.js-code-indent-width');
  59. const wrapMode = document.querySelector('.js-code-wrap-mode');
  60.  
  61. if (location.href.match(/^https?:\/\/github.com\/[^/]*\/[^/]*\/new\/.*/u)) {
  62. // new file
  63. updateDropdown(indentMode, cfg.indentMode);
  64. updateDropdown(indentWidth, cfg.indentWidth);
  65. updateDropdown(wrapMode, cfg.wrapMode);
  66. } else if (
  67. location.href.match(/^https?:\/\/github.com\/[^/]*\/[^/]*\/edit\/.*/u)
  68. ) {
  69. // edit file
  70. // if the file is using space indentation we don't want to change it
  71. if (indentMode.value === 'tab') {
  72. updateDropdown(indentWidth, cfg.indentWidth);
  73. }
  74. updateDropdown(wrapMode, cfg.wrapMode);
  75. }
  76. };
  77.  
  78. GM_registerMenuCommand('GitHub Editor Settings', Config.setup);
  79. const settings = Config.load();
  80.  
  81. waitForElems({
  82. sel: '.CodeMirror-code',
  83. onmatch() {
  84. applySettings(settings);
  85. }
  86. });
  87. })();