Discord Message ID Extractor

Extract Message IDs from Discord messages and display them

As of 2025-03-26. See the latest version.

  1. // ==UserScript==
  2. // @name Discord Message ID Extractor
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.9
  5. // @description Extract Message IDs from Discord messages and display them
  6. // @author AARR
  7. // @match https://discord.com/*
  8. // @grant none
  9. // @license You can modify as long as you credit me
  10. // ==/UserScript==
  11. (function() {
  12. 'use strict';
  13.  
  14. let observer;
  15. let isBoxVisible = false;
  16. let initialBoxPosition = { x: 90, y: 110 };
  17.  
  18. function makeElementDraggable(el) {
  19. el.onmousedown = function(event) {
  20. event.preventDefault();
  21.  
  22. let shiftX = event.clientX - el.getBoundingClientRect().left;
  23. let shiftY = event.clientY - el.getBoundingClientRect().top;
  24.  
  25. function moveAt(pageX, pageY) {
  26. const newX = Math.min(Math.max(0, pageX - shiftX), window.innerWidth - el.offsetWidth);
  27. const newY = Math.min(Math.max(0, pageY - shiftY), window.innerHeight - el.offsetHeight);
  28.  
  29. el.style.left = newX + 'px';
  30. el.style.top = newY + 'px';
  31.  
  32. const backgroundX = initialBoxPosition.x - newX;
  33. const backgroundY = initialBoxPosition.y - newY;
  34. el.style.backgroundPosition = `${backgroundX}px ${backgroundY}px`;
  35. }
  36.  
  37. function onMouseMove(event) {
  38. moveAt(event.pageX, event.pageY);
  39. }
  40.  
  41. document.addEventListener('mousemove', onMouseMove);
  42.  
  43. function onMouseUp() {
  44. document.removeEventListener('mousemove', onMouseMove);
  45. document.removeEventListener('mouseup', onMouseUp);
  46. }
  47.  
  48. document.addEventListener('mouseup', onMouseUp);
  49. };
  50.  
  51. el.ondragstart = function() {
  52. return false;
  53. };
  54. }
  55.  
  56. function addResizeButtons(el, initialWidth, initialHeight) {
  57. const buttonContainer = document.createElement('div');
  58. buttonContainer.style.position = 'absolute';
  59. buttonContainer.style.right = '5px';
  60. buttonContainer.style.top = '5px';
  61. buttonContainer.style.display = 'flex';
  62. buttonContainer.style.flexDirection = 'column';
  63. buttonContainer.style.gap = '5px';
  64. el.appendChild(buttonContainer);
  65.  
  66. const enlargeButton = document.createElement('button');
  67. enlargeButton.textContent = '+';
  68. enlargeButton.style.padding = '2px 5px';
  69. enlargeButton.style.fontSize = '10px';
  70. enlargeButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  71. enlargeButton.style.color = '#ffffff';
  72. enlargeButton.style.border = 'none';
  73. enlargeButton.style.borderRadius = '3px';
  74. enlargeButton.style.cursor = 'pointer';
  75. enlargeButton.style.transition = 'color 0.3s, background-color 0.3s';
  76. enlargeButton.onmouseenter = () => {
  77. enlargeButton.style.backgroundColor = 'rgba(76, 175, 80, 0.5)';
  78. enlargeButton.style.color = '#ffffff';
  79. };
  80. enlargeButton.onmouseleave = () => {
  81. enlargeButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  82. enlargeButton.style.color = '#ffffff';
  83. };
  84. buttonContainer.appendChild(enlargeButton);
  85.  
  86. const shrinkButton = document.createElement('button');
  87. shrinkButton.textContent = '-';
  88. shrinkButton.style.padding = '2px 5px';
  89. shrinkButton.style.fontSize = '10px';
  90. shrinkButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  91. shrinkButton.style.color = '#ffffff';
  92. shrinkButton.style.border = 'none';
  93. shrinkButton.style.borderRadius = '3px';
  94. shrinkButton.style.cursor = 'pointer';
  95. shrinkButton.style.transition = 'color 0.3s, background-color 0.3s';
  96. shrinkButton.onmouseenter = () => {
  97. shrinkButton.style.backgroundColor = 'rgba(244, 67, 54, 0.5)';
  98. shrinkButton.style.color = '#ffffff';
  99. };
  100. shrinkButton.onmouseleave = () => {
  101. shrinkButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  102. shrinkButton.style.color = '#ffffff';
  103. };
  104. buttonContainer.appendChild(shrinkButton);
  105.  
  106. enlargeButton.addEventListener('click', () => {
  107. el.style.height = (el.clientHeight + 150) + 'px';
  108. });
  109.  
  110. shrinkButton.addEventListener('click', () => {
  111. el.style.width = initialWidth;
  112. el.style.height = initialHeight;
  113. });
  114. }
  115.  
  116. const initialWidth = '170px';
  117. const initialHeight = '320px';
  118.  
  119. const container = document.createElement('div');
  120. container.id = 'messageIdContainer';
  121. container.style.position = 'fixed';
  122. container.style.top = initialBoxPosition.y + 'px';
  123. container.style.left = initialBoxPosition.x + 'px';
  124. container.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
  125. container.style.color = '#ffffff';
  126. container.style.padding = '5px';
  127. container.style.borderRadius = '5px';
  128. container.style.zIndex = '1000';
  129. container.style.width = initialWidth;
  130. container.style.height = initialHeight;
  131. container.style.display = 'none';
  132. container.style.backgroundImage = 'url("https://i.imgur.com/HCw1ebe.jpeg")';
  133. container.style.backgroundSize = 'cover';
  134. container.style.backgroundPosition = 'center';
  135. container.style.backgroundAttachment = 'fixed';
  136. container.style.backgroundRepeat = 'round';
  137. document.body.appendChild(container);
  138.  
  139. makeElementDraggable(container);
  140. addResizeButtons(container, initialWidth, initialHeight);
  141.  
  142. const title = document.createElement('h2');
  143. title.textContent = 'AARR Ex Message IDs';
  144. title.style.margin = '0 0 5px 0';
  145. title.style.fontSize = '15px';
  146. title.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
  147. container.appendChild(title);
  148.  
  149. const toolsLink = document.createElement('a');
  150. toolsLink.href = 'https://aarr-homepage.github.io/page/about5.html';
  151. toolsLink.target = '_blank';
  152. toolsLink.style.color = '#00BFFF';
  153. toolsLink.style.textDecoration = 'underline';
  154. toolsLink.style.display = 'inline-block';
  155. toolsLink.style.marginBottom = '10px';
  156. toolsLink.style.fontSize = '12px';
  157. toolsLink.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
  158. toolsLink.textContent = '🔗other tools';
  159. container.appendChild(toolsLink);
  160.  
  161. const messageIdList = document.createElement('ul');
  162. messageIdList.style.listStyleType = 'none';
  163. messageIdList.style.padding = '0';
  164. messageIdList.style.fontSize = '10px';
  165. messageIdList.style.height = 'calc(100% - 120px)';
  166. messageIdList.style.overflowY = 'scroll';
  167. messageIdList.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
  168. container.appendChild(messageIdList);
  169.  
  170. const startButton = document.createElement('button');
  171. startButton.textContent = ' Start ';
  172. startButton.style.marginTop = '5px';
  173. startButton.style.padding = '2px 5px';
  174. startButton.style.fontSize = '10px';
  175. startButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  176. startButton.style.color = '#ffffff';
  177. startButton.style.border = 'none';
  178. startButton.style.borderRadius = '3px';
  179. startButton.style.cursor = 'pointer';
  180. startButton.style.transition = 'color 0.3s, background-color 0.3s';
  181. startButton.onmouseenter = () => {
  182. startButton.style.backgroundColor = 'rgba(76, 175, 80, 0.5)';
  183. startButton.style.color = '#ffffff';
  184. };
  185. startButton.onmouseleave = () => {
  186. startButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  187. startButton.style.color = '#ffffff';
  188. };
  189. container.appendChild(startButton);
  190.  
  191. const stopButton = document.createElement('button');
  192. stopButton.textContent = ' Stop ';
  193. stopButton.style.marginTop = '5px';
  194. stopButton.style.padding = '2px 5px';
  195. stopButton.style.fontSize = '10px';
  196. stopButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  197. stopButton.style.color = '#ffffff';
  198. stopButton.style.border = 'none';
  199. stopButton.style.borderRadius = '3px';
  200. stopButton.style.cursor = 'pointer';
  201. stopButton.style.transition = 'color 0.3s, background-color 0.3s';
  202. stopButton.onmouseenter = () => {
  203. stopButton.style.backgroundColor = 'rgba(244, 67, 54, 0.5)';
  204. stopButton.style.color = '#ffffff';
  205. };
  206. stopButton.onmouseleave = () => {
  207. stopButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  208. stopButton.style.color = '#ffffff';
  209. };
  210. container.appendChild(stopButton);
  211.  
  212. const resetButton = document.createElement('button');
  213. resetButton.textContent = 'Reset';
  214. resetButton.style.marginTop = '5px';
  215. resetButton.style.padding = '2px 5px';
  216. resetButton.style.fontSize = '10px';
  217. resetButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  218. resetButton.style.color = '#ffffff';
  219. resetButton.style.border = 'none';
  220. resetButton.style.borderRadius = '3px';
  221. resetButton.style.cursor = 'pointer';
  222. resetButton.style.transition = 'color 0.3s, background-color 0.3s';
  223. resetButton.onmouseenter = () => {
  224. resetButton.style.backgroundColor = 'rgba(244, 67, 54, 0.5)';
  225. resetButton.style.color = '#ffffff';
  226. };
  227. resetButton.onmouseleave = () => {
  228. resetButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  229. resetButton.style.color = '#ffffff';
  230. };
  231. container.appendChild(resetButton);
  232.  
  233. const copyButton = document.createElement('button');
  234. copyButton.textContent = 'Copy IDs';
  235. copyButton.style.marginTop = '5px';
  236. copyButton.style.padding = '2px 5px';
  237. copyButton.style.fontSize = '10px';
  238. copyButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  239. copyButton.style.color = '#ffffff';
  240. copyButton.style.border = 'none';
  241. copyButton.style.borderRadius = '3px';
  242. copyButton.style.cursor = 'pointer';
  243. copyButton.style.transition = 'color 0.3s, background-color 0.3s';
  244. copyButton.onmouseenter = () => {
  245. copyButton.style.backgroundColor = 'rgba(76, 175, 80, 0.5)';
  246. copyButton.style.color = '#ffffff';
  247. };
  248. copyButton.onmouseleave = () => {
  249. copyButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  250. copyButton.style.color = '#ffffff';
  251. };
  252. container.appendChild(copyButton);
  253.  
  254. const saveButton = document.createElement('button');
  255. saveButton.textContent = 'Save File';
  256. saveButton.style.marginTop = '5px';
  257. saveButton.style.padding = '2px 5px';
  258. saveButton.style.fontSize = '10px';
  259. saveButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  260. saveButton.style.color = '#ffffff';
  261. saveButton.style.border = 'none';
  262. saveButton.style.borderRadius = '3px';
  263. saveButton.style.cursor = 'pointer';
  264. saveButton.style.transition = 'color 0.3s, background-color 0.3s';
  265. saveButton.onmouseenter = () => {
  266. saveButton.style.backgroundColor = 'rgba(76, 175, 80, 0.5)';
  267. saveButton.style.color = '#ffffff';
  268. };
  269. saveButton.onmouseleave = () => {
  270. saveButton.style.backgroundColor = 'rgba(87, 87, 87, 0.5)';
  271. saveButton.style.color = '#ffffff';
  272. };
  273. container.appendChild(saveButton);
  274.  
  275. function extractMessageIDs() {
  276. const messageElements = document.querySelectorAll('[id^="chat-messages-"]');
  277. const messageIds = new Set();
  278. messageElements.forEach(message => {
  279. const id = message.id.substring(14);
  280. messageIds.add(id);
  281. });
  282. return Array.from(messageIds);
  283. }
  284.  
  285. function updateMessageIDList() {
  286. const messageIds = extractMessageIDs();
  287. messageIds.forEach(id => {
  288. if (!Array.from(messageIdList.children).some(li => li.textContent === id)) {
  289. const listItem = document.createElement('li');
  290. listItem.textContent = id;
  291. listItem.style.color = 'lightblue';
  292. listItem.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
  293. messageIdList.appendChild(listItem);
  294. }
  295. });
  296. }
  297.  
  298. function copyMessageIDsToClipboard() {
  299. const messageIds = Array.from(messageIdList.children).map(li => li.textContent.replace(/-/g, ',')).join('\n');
  300. navigator.clipboard.writeText(messageIds).then(() => {
  301. }).catch(err => {
  302. console.error('Failed to copy message IDs: ', err);
  303. });
  304. }
  305.  
  306. function resetMessageIDList() {
  307. messageIdList.innerHTML = '';
  308. if (observer) {
  309. observer.disconnect();
  310. }
  311. }
  312.  
  313. function saveMessageIDsToFile() {
  314. const messageIds = Array.from(messageIdList.children).map(li => li.textContent.replace(/-/g, ',')).join('\n');
  315. const blob = new Blob([messageIds], { type: 'text/plain' });
  316. const url = URL.createObjectURL(blob);
  317. const a = document.createElement('a');
  318. a.href = url;
  319. a.download = 'message_ids.txt';
  320. document.body.appendChild(a);
  321. a.click();
  322. document.body.removeChild(a);
  323. URL.revokeObjectURL(url);
  324. }
  325.  
  326. startButton.addEventListener('click', () => {
  327. if (observer) {
  328. observer.disconnect();
  329. }
  330. updateMessageIDList();
  331. observer = new MutationObserver(() => {
  332. setTimeout(updateMessageIDList, 1000);
  333. });
  334. observer.observe(document.body, { childList: true, subtree: true });
  335. });
  336.  
  337. stopButton.addEventListener('click', () => {
  338. if (observer) {
  339. observer.disconnect();
  340. observer = null;
  341. }
  342. });
  343.  
  344. copyButton.addEventListener('click', copyMessageIDsToClipboard);
  345. resetButton.addEventListener('click', resetMessageIDList);
  346. saveButton.addEventListener('click', saveMessageIDsToFile);
  347.  
  348. const toggleImage = document.createElement('img');
  349. toggleImage.src = 'https://i.imgur.com/POHPOPN.png';
  350. toggleImage.style.position = 'fixed';
  351. toggleImage.style.width = '30px';
  352. toggleImage.style.height = '30px';
  353. toggleImage.style.cursor = 'pointer';
  354. toggleImage.style.zIndex = '1001';
  355. toggleImage.style.left = '75px';
  356. toggleImage.style.bottom = '123px';
  357. document.body.appendChild(toggleImage);
  358.  
  359. function adjustToggleImagePosition() {
  360.  
  361. }
  362.  
  363. toggleImage.addEventListener('click', () => {
  364. isBoxVisible = !isBoxVisible;
  365. container.style.display = isBoxVisible ? 'block' : 'none';
  366. });
  367. })();