Last active
January 1, 2026 12:05
-
-
Save natyusha/45892ae8b2db6005f5d1377430b8d890 to your computer and use it in GitHub Desktop.
Copy magnet links or the release date 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 Magnet/Release Date (YYYY-MM-DD) | |
| // @namespace https://gist.github.com/natyusha | |
| // @version 1.2.2 | |
| // @description Copy magnet links or the release date to the clipboard (great for adding files to anidb) | |
| // @match https://*.nyaa.si/* | |
| // @grant GM_setClipboard | |
| // @updateURL https://gist.github.com/natyusha/45892ae8b2db6005f5d1377430b8d890/raw/NyaaCopyMagnetAndReleaseDate.user.js | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| function createCopyButton(icon, title, getTextToCopy) { | |
| const btn = document.createElement('button'); | |
| btn.textContent = icon; | |
| btn.title = title; | |
| btn.style.cssText = ` | |
| margin-left: .5em; | |
| cursor: pointer; | |
| background: none; | |
| border: none; | |
| width: 2em; | |
| text-align: center; | |
| `; | |
| btn.onclick = (e) => { | |
| e.preventDefault(); | |
| e.stopPropagation(); | |
| const text = typeof getTextToCopy === 'function' ? getTextToCopy() : getTextToCopy; | |
| if (typeof GM_setClipboard !== 'undefined') { | |
| GM_setClipboard(text); | |
| } else { | |
| navigator.clipboard.writeText(text); | |
| } | |
| const original = btn.textContent; | |
| btn.textContent = '✅'; | |
| setTimeout(() => btn.textContent = original, 1000); | |
| }; | |
| return btn; | |
| } | |
| function addDateButtons() { | |
| document.querySelectorAll('[data-timestamp]').forEach(el => { | |
| if (el.closest('a')) return; | |
| if (el.querySelector('.copy-date-btn')) return; | |
| const shortDate = el.textContent.trim().split(' ')[0]; | |
| const btn = createCopyButton('📋', `Copy date: ${shortDate}`, shortDate); | |
| btn.className = 'copy-date-btn'; | |
| el.appendChild(btn); | |
| }); | |
| } | |
| function addMagnetButtons() { | |
| document.querySelectorAll('i.fa-magnet').forEach(icon => { | |
| const link = icon.closest('a'); | |
| if (!link || !link.href.startsWith('magnet:')) return; | |
| if (link.querySelector('.copy-magnet-btn')) return; | |
| const btn = createCopyButton('🧲', 'Copy magnet link', link.href); | |
| btn.className = 'copy-magnet-btn'; | |
| link.insertAdjacentElement('afterend', btn); | |
| }); | |
| } | |
| function process() { | |
| addDateButtons(); | |
| addMagnetButtons(); | |
| } | |
| // 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