Skip to content

Instantly share code, notes, and snippets.

@nunocunha
Last active April 20, 2026 20:06
Show Gist options
  • Select an option

  • Save nunocunha/94bc5f5ec322102144c839da1373c16f to your computer and use it in GitHub Desktop.

Select an option

Save nunocunha/94bc5f5ec322102144c839da1373c16f to your computer and use it in GitHub Desktop.
Adds an icon button on IMDb to copy the title of shows and movies, with IDs ready for metadata providers
// ==UserScript==
// @name Copy IMDb title
// @namespace https://nunocunha.pt/
// @version 1.0.3
// @description Adds an icon button on IMDb to copy the title of shows and movies, with IDs ready for metadata providers
// @author Nuno Cunha
// @match https://www.imdb.com/title/*
// @match https://www.imdb.com/*/title/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=imdb.com
// @license MIT
// @updateURL https://gist.github.com/nunocunha/94bc5f5ec322102144c839da1373c16f/raw/copy-imdb-title.js
// @downloadURL https://gist.github.com/nunocunha/94bc5f5ec322102144c839da1373c16f/raw/copy-imdb-title.js
// @grant GM_setClipboard
// ==/UserScript==
/*
* MIT License
*
* Copyright (c) 2026 Nuno Cunha
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
(function() {
'use strict';
const icon = "📄";
const currentTitleElement = document.querySelector('h1[data-testid="hero__pageTitle"] span');
const originalTitleElement = document.querySelector('h1[data-testid="hero__pageTitle"] ~ div');
const extraInfo = document.querySelector('h1[data-testid="hero__pageTitle"] ~ ul');
const titleElement = originalTitleElement ?? currentTitleElement;
const hasAlternateTitle = originalTitleElement != null;
const extractTitle = () => {
const firstTextLine = titleElement.innerText.split('\n').shift();
if (!hasAlternateTitle) {
return firstTextLine;
}
return firstTextLine.match(/: (.+)/iu).pop();
}
const extractYear = () => {
const yearRegex = /(\d{4})(?:-\d{4})?/iu;
const yearNode = Array.from(extraInfo.childNodes).find((e) => e.innerText.match(yearRegex));
return yearNode.innerText.match(yearRegex)?.pop();
};
const copyToClipboard = () => {
const regex = new RegExp('/(tt\\d+)/?', 'iu');
const pageId = document.location.pathname.match(regex).pop();
const title = extractTitle();
const year = extractYear();
const yearPart = `(${year})`;
const idPart = `[imdbid-${pageId}]`;
const partsToCopy = year != null ? [title, yearPart, idPart] : [title, idPart];
GM_setClipboard(partsToCopy.join(' '));
}
const addButton = () => {
const newElement = document.createElement('div');
newElement.style.display = "inline-block";
newElement.style.cursor = "pointer";
newElement.style.position = "absolute";
newElement.style.top = "0";
newElement.style.right = "100%";
newElement.style.marginRight = "0.5em";
newElement.style.fontSize = "20px";
newElement.style.overflow = "visible";
newElement.title = "Copy to clipboard";
newElement.appendChild(document.createTextNode(icon));
newElement.addEventListener('click', copyToClipboard);
titleElement.appendChild(newElement);
titleElement.style.position = "relative";
}
addButton();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment