Mediawiki <br> adder

Adds a button to add <br> in mediawiki form

目前为 2018-07-30 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Mediawiki <br> adder
  3. // @version 0.1.0
  4. // @description Adds a button to add <br> in mediawiki form
  5. // @author kory33
  6. // @match *://*/*
  7. // @namespace https://github.com/kory33
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. function addButton(text, domManipulator) {
  14. const button = document.createElement('button');
  15. const textarea = document.getElementById("wpTextbox1");
  16. document.getElementById("mw-content-text").appendChild(button);
  17. button.innerHTML = text;
  18. button.onclick = () => domManipulator(textarea);
  19. return button;
  20. }
  21.  
  22. function processText(text) {
  23. const lines = text.split("\n");
  24. const shouldAppendBr = line => !(line === "" || line.endsWith(">") || line.endsWith("=="));
  25. const mapper = line => shouldAppendBr(line) ? line + "<br>" : line;
  26. return lines.map(mapper).join("\n");
  27. }
  28.  
  29. window.addEventListener('load', () => {
  30. addButton('Add &lt;br&gt;', (textarea) => {
  31. textarea.value = processText(textarea.value);
  32. });
  33. });
  34.  
  35. })();