TurretBot

Discord Attachment Copier

Feb 19th, 2024 (edited)
1,333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Discord Attachment Copier
  3. // @version      1.6
  4. // @description  try to take over the world!
  5. // @author       TurretBot
  6. // @match        *.discord.com/channels/*
  7. // @icon         https://www.google.com/s2/favicons?sz=64&domain=discord.com
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.     function getsub(id) {
  14.         var attatchments="",att=document.getElementById("message-accessories-"+id).querySelectorAll("a"),subt=document.getElementById("message-content-"+id).querySelectorAll('span'),i=0;
  15.         for (i=0;i<att.length;i++) {
  16.             if ((att[i]+"").includes("cdn.discord")) {attatchments=attatchments.concat(att[i]+"\n")};
  17.         }
  18.         for (i=0;i<subt.length;i++) {
  19.             if (subt[i].className.includes("attachmentLink")) {attatchments=attatchments.concat(subt[i].getAttribute('href')+"\n")};
  20.         }
  21.         //clear dupes (audio has two hrefs w same link)
  22.         attatchments=attatchments.split("\n").filter((item, i, allItems) => {return i === allItems.indexOf(item);}).join("\n");
  23.         return attatchments+document.getElementById("message-content-"+id).innerText.replaceAll("\`\`\`","");
  24.     };
  25.  
  26.     function ButtonClickAction (zEvent) {
  27.         zEvent.target.innerHTML=getsub(zEvent.target.id);
  28.     }
  29. //edited_f9f2ca
  30. //attachmentLink wrapper_f61d60 interactive
  31.     var mo = new MutationObserver(function(muts) {
  32.         muts.forEach(function(mut) {
  33.             Array.prototype.forEach.call(mut.addedNodes, function(node) {
  34.                 if (node instanceof HTMLElement) {
  35.                     Array.prototype.forEach.call(node.querySelectorAll('time'), function(img) {
  36.                         //https://stackoverflow.com/questions/6480082/add-a-javascript-button-using-greasemonkey-or-tampermonkey
  37.                         if (img.class="edited_f9f2ca") {img.innerHTML="";}
  38.                         var zNode=document.createElement('textarea');
  39.                         zNode.rows=1
  40.                         zNode.placeholder="Click for submission text"
  41.                         zNode.id=img.id.replace("message-timestamp-","");
  42.                         zNode.addEventListener(
  43.                             "click", ButtonClickAction, false
  44.                         );
  45.                         img.appendChild(zNode);
  46.                     });
  47.                 }
  48.             });
  49.         });
  50.     });
  51.     mo.observe(document.body, {childList: true, subtree: true});
  52. })();
Advertisement
Add Comment
Please, Sign In to add comment