U2编辑框增强

给U2的编辑框加上点按钮儿

  1. // ==UserScript==
  2. // @name U2编辑框增强
  3. // @version 1.0.1
  4. // @description 给U2的编辑框加上点按钮儿
  5. // @namespace Violentmonkey Scripts
  6. // @match https://u2.dmhy.org/upload.php*
  7. // @match https://u2.dmhy.org/edit.php?id=*
  8. // @grant none
  9. // ==/UserScript==
  10. (() => {
  11. const editArea = document.querySelector('#descr');
  12. const createButton = (buttonName) => {
  13. const btnContainer = document.createElement('td');
  14. const btnInput = document.createElement('input');
  15. btnContainer.className = 'embedded';
  16. btnInput.value = buttonName.toUpperCase();
  17. btnInput.style.fontSize = '11px';
  18. btnInput.style.marginRight = '3px';
  19. btnInput.className = 'codebuttons';
  20. btnInput.type = 'button';
  21. btnContainer.appendChild(btnInput);
  22. btnInput.addEventListener('click', (e) => {
  23. e.preventDefault();
  24. insertTag(editArea, [`[${buttonName}]`, `[/${buttonName}]`]);
  25. });
  26. return btnContainer;
  27. }
  28. const insertTag = (element, tag) => {
  29. const start = element.selectionStart;
  30. const end = element.selectionEnd;
  31. element.value = element.value.slice(0, start) + tag[0] + element.value.slice(start, end) + tag[1] + element.value.slice(end);
  32. }
  33. const lastTableDataCell =
  34. location.href.includes('edit.php')
  35. ? document.querySelector('#compose > table > tbody > tr:nth-child(7) > td.rowfollow > table > tbody > tr:nth-child(1) > td > table > tbody > tr > td:nth-child(6)')
  36. : document.querySelector('#compose > table > tbody > tr:nth-child(35) > td.rowfollow > table > tbody > tr:nth-child(1) > td > table > tbody > tr > td:nth-child(6)');
  37.  
  38. const spoilerBtnContainer = createButton('spoiler');
  39. lastTableDataCell.parentNode.insertBefore(
  40. spoilerBtnContainer,
  41. lastTableDataCell.nextSibling
  42. );
  43. const mediaInfoBtnContainer = createButton('mediainfo');
  44. spoilerBtnContainer.parentNode.insertBefore(
  45. mediaInfoBtnContainer,
  46. spoilerBtnContainer.nextSibling
  47. );
  48. })()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址