您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

repo-unicode-escape.js 1.2KB

123456789101112131415161718192021222324252627
  1. import {hideElem, queryElemSiblings, showElem, toggleElem} from '../utils/dom.js';
  2. export function initUnicodeEscapeButton() {
  3. document.addEventListener('click', (e) => {
  4. const btn = e.target.closest('.escape-button, .unescape-button, .toggle-escape-button');
  5. if (!btn) return;
  6. e.preventDefault();
  7. const fileContent = btn.closest('.file-content, .non-diff-file-content');
  8. const fileView = fileContent?.querySelectorAll('.file-code, .file-view');
  9. if (btn.matches('.escape-button')) {
  10. for (const el of fileView) el.classList.add('unicode-escaped');
  11. hideElem(btn);
  12. showElem(queryElemSiblings(btn, '.unescape-button'));
  13. } else if (btn.matches('.unescape-button')) {
  14. for (const el of fileView) el.classList.remove('unicode-escaped');
  15. hideElem(btn);
  16. showElem(queryElemSiblings(btn, '.escape-button'));
  17. } else if (btn.matches('.toggle-escape-button')) {
  18. const isEscaped = fileView[0]?.classList.contains('unicode-escaped');
  19. for (const el of fileView) el.classList.toggle('unicode-escaped', !isEscaped);
  20. toggleElem(fileContent.querySelectorAll('.unescape-button'), !isEscaped);
  21. toggleElem(fileContent.querySelectorAll('.escape-button'), isEscaped);
  22. }
  23. });
  24. }