Created
November 8, 2025 20:53
-
-
Save natyusha/45892ae8b2db6005f5d1377430b8d890 to your computer and use it in GitHub Desktop.
Copy the release date of a torrent on nyaa to the clipboard (great for adding files to anidb)
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
| // ==UserScript== | |
| // @name Nyaa - Copy Release Date (YYYY-MM-DD) | |
| // @namespace https://gist.github.com/natyusha | |
| // @version 1.0 | |
| // @description Copy the release date of a torrent on nyaa to the clipboard (great for adding files to anidb) | |
| // @match https://*.nyaa.si/* | |
| // @grant GM_setClipboard | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| function addCopyButton(td) { | |
| if (!td.hasAttribute('data-timestamp') || td.querySelector('.copy-date-btn')) return; | |
| const fullDate = td.textContent.trim(); | |
| const shortDate = fullDate.split(' ')[0]; | |
| const btn = document.createElement('button'); | |
| btn.textContent = 'π'; | |
| btn.title = `Copy date: ${shortDate}`; | |
| btn.className = 'copy-date-btn'; | |
| btn.style.cssText = ` | |
| margin-left: .5em; | |
| cursor: pointer; | |
| background: none; | |
| border: none; | |
| width: 2em; | |
| text-align: center; | |
| `; | |
| btn.onclick = (e) => { | |
| e.preventDefault(); | |
| e.stopPropagation(); | |
| // Copy | |
| if (typeof GM_setClipboard !== 'undefined') { | |
| GM_setClipboard(shortDate); | |
| } else { | |
| navigator.clipboard.writeText(shortDate); | |
| } | |
| // Feedback: Clipboard -> Checkmark | |
| btn.textContent = 'β '; | |
| setTimeout(() => btn.textContent = 'π', 700); | |
| }; | |
| td.appendChild(btn); | |
| } | |
| function process() { | |
| document.querySelectorAll('td[data-timestamp]').forEach(addCopyButton); | |
| } | |
| // Run on load | |
| if (document.readyState === 'loading') { | |
| document.addEventListener('DOMContentLoaded', process); | |
| } else { | |
| process(); | |
| } | |
| // Re-run on navigation | |
| const origPushState = history.pushState; | |
| history.pushState = function () { | |
| origPushState.apply(this, arguments); | |
| setTimeout(process, 100); | |
| }; | |
| window.addEventListener('popstate', () => setTimeout(process, 100)); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment