Listography Easy Copy Permalink

Adds a button to copy list permalinks to clipboard

  1. // ==UserScript==
  2. // @name Listography Easy Copy Permalink
  3. // @description Adds a button to copy list permalinks to clipboard
  4. // @version 1.0.0
  5. // @author petracoding
  6. // @namespace petracoding
  7. // @grant none
  8. // @include https://listography.com/*
  9. // @include http://listography.com/*
  10. // ==/UserScript==
  11.  
  12. // Early Return
  13. if (!document.querySelector(".about")) return;
  14.  
  15. // Get User Id from avatar image
  16. const userId = document.querySelector(".about img").getAttribute("src").replace("/action/user-image?uid=", "");
  17.  
  18. // Get all listboxes and add buttons
  19. const listboxes = document.querySelectorAll(".listbox");
  20. [...listboxes].forEach(listbox => {
  21. const listId = listbox.getAttribute("id").replace("listbox-", "");
  22. const permalink = "https://listography.com/action/list?uid=" + userId + "&lid=" + listId;
  23. const datesEl = listbox.querySelector(".dates");
  24. const copyBtn = document.createElement("button");
  25. copyBtn.innerHTML = "copy link";
  26. copyBtn.setAttribute("class", "copy-permalink-btn");
  27. copyBtn.setAttribute("title", permalink);
  28. copyBtn.setAttribute("style", `
  29. background: none;
  30. border: none;
  31. font-size: 1em;
  32. color: inherit;
  33. font-weight: bold;
  34. display: block;
  35. padding: 0;
  36. cursor: pointer;
  37. `);
  38. datesEl.appendChild(copyBtn);
  39. });
  40.  
  41. // Add event listeners to the new buttons
  42. const btns = document.querySelectorAll(".copy-permalink-btn");
  43. [...btns].forEach(btn => {
  44. btn.addEventListener("click", () => {
  45. navigator.clipboard.writeText(btn.getAttribute("title"));
  46. btn.innerHTML = "copied!";
  47. setTimeout(function(){
  48. btn.innerHTML = "copy link";
  49. }, 1000);
  50. });
  51. });