GEE Font Size

try to take over the world!

当前为 2022-01-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GEE Font Size
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://code.earthengine.google.com/
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant GM_addStyle
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. let buttonBox = document.querySelector('.editor-panel .header div')
  17. let createButton = (title, innerHTML, func) => {
  18. let button = document.createElement('button')
  19. button.classList.add('goog-button')
  20. button.setAttribute('title', title)
  21. button.innerHTML = innerHTML
  22. button.onclick = func
  23. button.style.marginRight = '6px'
  24. buttonBox.insertBefore(button, buttonBox.firstChild)
  25. }
  26.  
  27. let addFontSizeStyle = (size) => {
  28. GM_addStyle(`
  29. .ace_editor {
  30. font-size: ${size}px !important;
  31. }
  32. `)
  33. }
  34. const minSize = 13
  35. const maxSize = 60
  36. addFontSizeStyle(GM_getValue('GEE Font Size', minSize))
  37. let changeFontSize = (operate) => {
  38. return () => {
  39. let box = document.querySelector('.ace_editor')
  40. let size = Number(getComputedStyle(box).fontSize.replace('px', ''))
  41. size = eval(operate)
  42. if (size >= minSize && size <= maxSize) {
  43. GM_setValue('GEE Font Size', size)
  44. addFontSizeStyle(size)
  45. }
  46. }
  47. }
  48. createButton('Decrease Font Size', '-', changeFontSize('size - 1'))
  49. createButton('Increase Font Size', '+', changeFontSize('size + 1'))
  50. })();