Guest User

Untitled

a guest
Jul 24th, 2025
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Highlights & Notes
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Add comments to Mastodon usrers
  6. // @match *://*.cr8r.gg/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function () {
  11. 'use strict';
  12. // Сюда хардкодим то, что хотим подсвечивать на уровне юзернейма (боты, мосты, сервера, которые вас забанили)
  13. const highlightedDomains = [
  14. "@press.anyaforger.art",
  15. "@bird.makeup",
  16. "@threads.net",
  17. "@lamp.leemoon.network",
  18. "@juick.com",
  19. "@pixelfed.",
  20. "@shitpost.poridge.club",
  21. ];
  22.  
  23. const memoryMap = {};
  24. function addToMemory(key, value) {
  25. memoryMap[key] = value;
  26. localStorage.setItem('mem_' + key, value);
  27. console.log(`[MEM] Добавлено: ${key} → ${value}`);
  28. }
  29.  
  30. function highlightAccounts() {
  31. document.querySelectorAll("span.display-name__account").forEach(el => {
  32. const content = el.textContent.trim();
  33. const parent = el.closest('a');
  34.  
  35. if (!parent || parent.querySelector(".personal-user-note")) return;
  36.  
  37. let didHighlight = false;
  38.  
  39. if (highlightedDomains.some(domain => content.includes(domain))) {
  40. el.classList.add("highlight-account");
  41. didHighlight = true;
  42. }
  43.  
  44. const matchedKey = Object.keys(memoryMap).find(key => content.includes(key));
  45. if (matchedKey) {
  46. const note = memoryMap[matchedKey].trim();
  47.  
  48. const noteSpan = document.createElement("span");
  49. noteSpan.textContent = ` (${note})`;
  50. noteSpan.classList.add("personal-user-note");
  51. parent.appendChild(noteSpan);
  52. console.log(`[NOTE] Добавлена заметка для ${content}: ${note}`);
  53. didHighlight = true;
  54. }
  55.  
  56. if (didHighlight) {
  57. console.log(`[HIGHLIGHT] ${content}`);
  58. }
  59. });
  60. }
  61.  
  62. function saveToMemory() {
  63. const key = prompt('Введите ключ:');
  64. if (!key) return;
  65.  
  66. const value = prompt('Введите значение (оставьте пустым, чтобы удалить):');
  67. if (value === null) return;
  68.  
  69. if (value === '') {
  70. // Удалить ключ
  71. delete memoryMap[key];
  72. localStorage.removeItem('mem_' + key);
  73. alert(`Ключ "${key}" удалён`);
  74. } else {
  75. // Сохранить ключ-значение
  76. memoryMap[key] = value;
  77. localStorage.setItem('mem_' + key, value);
  78. alert(`Сохранено: ${key} = ${value}`);
  79. highlightAccounts();
  80. }
  81. }
  82.  
  83. function loadFromStorage() {
  84. console.log('Loading from storage'+localStorage.length+' records');
  85. for (let i = 0; i < localStorage.length; i++) {
  86. const key = localStorage.key(i);
  87. if (key.startsWith('mem_')) {
  88. const value = localStorage.getItem(key);
  89. memoryMap[key.slice(4)] = value;
  90. }
  91. }
  92. }
  93.  
  94.  
  95. const waitForDrawer = setInterval(() => {
  96. const drawerTabs = document.querySelectorAll('.drawer__tab');
  97. if (!drawerTabs.length) return;
  98.  
  99. const signOutBtn = Array.from(drawerTabs).find(a =>
  100. a.getAttribute('href') === '/auth/sign_out'
  101. );
  102.  
  103. if (!signOutBtn || signOutBtn.nextElementSibling?.classList.contains('drawer__tab--add-comment')) {
  104. clearInterval(waitForDrawer);
  105. return;
  106. }
  107.  
  108. const commentBtn = document.createElement('a');
  109. commentBtn.href = '#';
  110. commentBtn.className = 'drawer__tab drawer__tab--add-comment';
  111. commentBtn.title = 'Добавить комментарий';
  112. commentBtn.setAttribute('aria-label', 'Добавить комментарий');
  113. //Это иконка на кнопке
  114. commentBtn.innerHTML = `
  115. <svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" class="icon icon-user-note" aria-hidden="true">
  116. <path d="M19.8201 14H15.6001C15.04 14 14.76 14 14.5461 14.109C14.3579 14.2049 14.2049 14.3578 14.1091 14.546C14.0001 14.7599 14.0001 15.0399 14.0001 15.6V19.82M20 12.7269V7.2C20 6.0799 20 5.51984 19.782 5.09202C19.5903 4.71569 19.2843 4.40973 18.908 4.21799C18.4802 4 17.9201 4 16.8 4H7.2C6.0799 4 5.51984 4 5.09202 4.21799C4.71569 4.40973 4.40973 4.71569 4.21799 5.09202C4 5.51984 4 6.0799 4 7.2V16.8C4 17.9201 4 18.4802 4.21799 18.908C4.40973 19.2843 4.71569 19.5903 5.09202 19.782C5.51984 20 6.0799 20 7.2 20H12.9496C13.4578 20 13.7118 20 13.9498 19.9407C14.1608 19.8882 14.3618 19.8016 14.5449 19.6844C14.7515 19.5522 14.926 19.3675 15.2751 18.9983L19.1254 14.9252C19.4486 14.5833 19.6101 14.4124 19.7255 14.2156C19.8278 14.041 19.903 13.8519 19.9486 13.6548C20 13.4325 20 13.1973 20 12.7269Z" stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/> </svg>
  117. `;
  118.  
  119. commentBtn.addEventListener('click', (e) => {
  120. e.preventDefault();
  121. saveToMemory();
  122. });
  123.  
  124. signOutBtn.insertAdjacentElement('afterend', commentBtn);
  125.  
  126. clearInterval(waitForDrawer);
  127. }, 300);
  128.  
  129.  
  130.  
  131. loadFromStorage();
  132. console.log('Loaded '+Object.keys(memoryMap).length+' records');
  133.  
  134. const observer = new MutationObserver(mutations => {
  135. for (const mutation of mutations) {
  136. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  137. highlightAccounts();
  138. break; // не нужно проходить всё, если уже обновили
  139. }
  140. }
  141. });
  142.  
  143. observer.observe(document.querySelector('main') || document.body, {
  144. childList: true,
  145. subtree: true,
  146. });
  147.  
  148.  
  149. })();
  150.  
Advertisement
Add Comment
Please, Sign In to add comment