Last active
February 3, 2024 18:13
-
-
Save stephanieleary/daa5f3ecfd637dbbba1b69677be386a6 to your computer and use it in GitHub Desktop.
Copy all AO3 work URLs on the page to the clipboard (for Calibre + FanFicFare anthologies)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* USAGE: Copy this code into a bookmarklet creator such as https://mrcoles.com/bookmarklet/ and bookmark the result */ | |
const links = Array.prototype.slice.call(document.querySelectorAll('ol.work.group li.work .header .heading a:first-child')); | |
const urls = links.map(function(elem){ return 'https://archiveofourown.org'+elem.getAttribute("href"); }); | |
if (!urls.length) return; | |
urls.reverse(); | |
const dialog = document.createElement("dialog"); | |
dialog.setAttribute('id', 'modal'); | |
const btn = document.createElement("button"); | |
btn.setAttribute('class', 'action modal modal-closer'); | |
btn.textContent = 'Close'; | |
const msg = document.createElement("p"); | |
msg.textContent = 'Work URLs copied to clipboard.'; | |
const textarea = document.createElement("textarea"); | |
textarea.setAttribute('rows', urls.length); | |
const fragment = document.createDocumentFragment(); | |
const area = fragment.appendChild(dialog).appendChild(textarea); | |
textarea.textContent = urls.join("\n"); | |
dialog.appendChild(msg); | |
dialog.appendChild(btn); | |
dialog.style.maxWidth = '55ch'; | |
dialog.style.margin = '2rem auto'; | |
textarea.style.display = 'block'; | |
btn.style.display = 'block'; | |
btn.addEventListener("click", () => { | |
dialog.close(); | |
}); | |
document.body.appendChild(fragment); | |
navigator.clipboard.writeText(urls.join("\n")); | |
dialog.showModal(); | |
btn.focus(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment