Greasy Fork is available in English.

Letterboxd IMDb Code Extractor

Extract and copy IMDb code on Letterboxd film pages

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Advertisement:

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

Advertisement:

// ==UserScript==
// @name         Letterboxd IMDb Code Extractor
// @namespace    http://tampermonkey.net/
// @version      1.7
// @description  Extract and copy IMDb code on Letterboxd film pages
// @author       You
// @match        https://letterboxd.com/film/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to create a button that matches the IMDb button style
    function createMatchingButton(imdbCode) {
        const button = document.createElement('button');
        button.textContent = imdbCode;
        // Apply provided styles
        button.style.background = '#14181c'; // Background color as per request
        button.style.border = '2px solid #303840';
        button.style.borderRadius = '2px';
        button.style.color = '#9ab';
        button.style.fontSize = '.76923077rem';
        button.style.letterSpacing = '.075em';
        button.style.padding = '4px 5px 3px';
        button.style.textTransform = 'uppercase';
        button.style.cursor = 'pointer';
        button.style.marginLeft = '10px'; // Space from the existing TMDB button
        button.onclick = function() {
            navigator.clipboard.writeText(imdbCode).then(function() {
                console.log('IMDb code copied to clipboard');
            }, function(err) {
                console.error('Could not copy IMDb code: ', err);
            });
        };
        return button;
    }

    // Wait for the TMDB button to load on the page
    const waitForTmdbButton = setInterval(function() {
        const tmdbButton = document.querySelector('a[href*="themoviedb.org/movie/"]'); // The TMDB button element
        if (tmdbButton) {
            clearInterval(waitForTmdbButton);

            // Extract the IMDb code from the page
            const imdbLinkElement = document.querySelector('a[href*="imdb.com/title/tt"]');
            if (imdbLinkElement) {
                const imdbUrl = imdbLinkElement.href;
                const imdbCodeMatch = imdbUrl.match(/title\/(tt\d+)/);
                if (imdbCodeMatch && imdbCodeMatch[1]) {
                    const imdbCode = imdbCodeMatch[1];
                    const matchingButton = createMatchingButton(imdbCode);
                    tmdbButton.parentNode.insertBefore(matchingButton, tmdbButton.nextSibling); // Insert the button after the TMDB button
                }
            }
        }
    }, 500); // Check every 500ms if the TMDB button has loaded
})();