Last active
July 13, 2026 21:33
-
-
Save calliah333/384e205b311abda8be50003c107e9e17 to your computer and use it in GitHub Desktop.
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 Letterboxd IMDb/TMDB ID Copier | |
| // @author calliah333 | |
| // @namespace https://letterboxd.com/ | |
| // @version 1.0.0 | |
| // @description Copy a film's IMDb or TMDB ID by Shift-clicking its IMDb or TMDB button. | |
| // @match https://letterboxd.com/film/* | |
| // @grant GM_setClipboard | |
| // @run-at document-start | |
| // ==/UserScript== | |
| (function () { | |
| 'use strict'; | |
| const feedback = new WeakMap(); | |
| function getId(service, href) { | |
| const pathname = new URL(href, location.href).pathname; | |
| const match = service === 'IMDB' | |
| ? pathname.match(/\/title\/(tt\d+)(?:\/|$)/i) | |
| : pathname.match(/\/(?:movie|tv)\/(\d+)(?:[-/]|$)/i); | |
| return match?.[1] ?? null; | |
| } | |
| function showCopied(button, id) { | |
| let state = feedback.get(button); | |
| if (state) { | |
| clearTimeout(state.timer); | |
| } else { | |
| state = { | |
| text: button.textContent, | |
| title: button.getAttribute('title'), | |
| timer: 0, | |
| }; | |
| feedback.set(button, state); | |
| } | |
| button.textContent = 'Copied!'; | |
| button.title = `Copied ${id}`; | |
| state.timer = setTimeout(() => { | |
| button.textContent = state.text; | |
| if (state.title === null) { | |
| button.removeAttribute('title'); | |
| } else { | |
| button.title = state.title; | |
| } | |
| feedback.delete(button); | |
| }, 1200); | |
| } | |
| document.addEventListener('click', (event) => { | |
| if (!event.shiftKey || event.button !== 0 || !(event.target instanceof Element)) { | |
| return; | |
| } | |
| const button = event.target.closest('a[data-track-action]'); | |
| const service = button?.dataset.trackAction?.toUpperCase(); | |
| if (service !== 'IMDB' && service !== 'TMDB') { | |
| return; | |
| } | |
| const id = getId(service, button.href); | |
| if (!id) { | |
| return; | |
| } | |
| event.preventDefault(); | |
| event.stopImmediatePropagation(); | |
| GM_setClipboard(id, 'text'); | |
| showCopied(button, id); | |
| }, true); | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment