Listography Easy Copy Permalink

Adds a button to copy list permalinks to clipboard

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==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);
  });
});