Listography Easy Copy Permalink

Adds a button to copy list permalinks to clipboard

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Listography Easy Copy Permalink
// @description Adds a button to copy list permalinks to clipboard
// @version     1.0.0
// @author      petracoding
// @namespace   petracoding
// @grant       none
// @include     https://listography.com/*
// @include     http://listography.com/*
// ==/UserScript==

// Early Return
if (!document.querySelector(".about")) return;

// Get User Id from avatar image
const userId = document.querySelector(".about img").getAttribute("src").replace("/action/user-image?uid=", "");

// Get all listboxes and add buttons
const listboxes = document.querySelectorAll(".listbox");
[...listboxes].forEach(listbox => {
  const listId = listbox.getAttribute("id").replace("listbox-", "");
  const permalink = "https://listography.com/action/list?uid=" + userId + "&lid=" + listId;
  
  const datesEl = listbox.querySelector(".dates");
  const copyBtn = document.createElement("button");
  
  copyBtn.innerHTML = "copy link";
  copyBtn.setAttribute("class", "copy-permalink-btn");
  copyBtn.setAttribute("title", permalink);
  copyBtn.setAttribute("style", `
		background: none;
    border: none;
    font-size: 1em;
    color: inherit;
    font-weight: bold;
    display: block;
    padding: 0;
    cursor: pointer;
	`);
  datesEl.appendChild(copyBtn);
});

// Add event listeners to the new buttons
const btns = document.querySelectorAll(".copy-permalink-btn");
[...btns].forEach(btn => {
  btn.addEventListener("click", () => {
    navigator.clipboard.writeText(btn.getAttribute("title"));
    btn.innerHTML = "copied!";
    
    setTimeout(function(){
    	btn.innerHTML = "copy link";
    }, 1000);
  });
});