Monospacer

Adds a button to make the xkcd forums posting box monospace

当前为 2015-10-09 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Monospacer
  3. // @version 0.1
  4. // @description Adds a button to make the xkcd forums posting box monospace
  5. // @author faubi
  6. // @match forums.xkcd.com/posting.php*
  7. // @match fora.xkcd.com/posting.php*
  8. // @match forums3.xkcd.com/posting.php*
  9. // @match echochamber.me/posting.php*
  10. // @grant none
  11. // @namespace https://greasyfork.org/users/17542
  12. // ==/UserScript==
  13.  
  14. var isMonospace = false;
  15.  
  16. button = document.createElement('input');
  17. button.type = 'button';
  18. button.classList.add('button2');
  19. button.value = 'monospace';
  20. button.title = 'Toggle monospace font';
  21.  
  22. postform = document.getElementById('postform');
  23. postAction = postform.action;
  24.  
  25. function toggleMonospace() {
  26. isMonospace = !isMonospace;
  27. document.getElementById('message').style['font-family'] = isMonospace ? 'monospace' : '';
  28. if (isMonospace){
  29. postform.action = postAction + '&monospace=1';
  30. } else {
  31. postform.action = postAction;
  32. }
  33. }
  34.  
  35. button.addEventListener('click', toggleMonospace);
  36.  
  37. if (document.location.search.indexOf('monospace=1') !== -1) {
  38. toggleMonospace();
  39. }
  40.  
  41. document.getElementById('format-buttons').appendChild(button);
  42.