Skip to content

Instantly share code, notes, and snippets.

@natyusha
Created November 8, 2025 20:53
Show Gist options
  • Select an option

  • Save natyusha/45892ae8b2db6005f5d1377430b8d890 to your computer and use it in GitHub Desktop.

Select an option

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