IMDb Poster Downloader

A new extension

Size

5.0 KB

Version

1.1.2

Created

Feb 5, 2026

Updated

about 1 month ago

1// ==UserScript==
2// @name		IMDb Poster Downloader
3// @description		A new extension
4// @version		1.1.2
5// @match		https://*.imdb.com/*
6// @icon		https://m.media-amazon.com/images/G/01/imdb/images-ANDW73HA/favicon_desktop_32x32._CB1582158068_.png
7// ==/UserScript==
8(function() {
9    'use strict';
10
11    // Debounce function to prevent excessive calls
12    function debounce(func, wait) {
13        let timeout;
14        return function executedFunction(...args) {
15            const later = () => {
16                clearTimeout(timeout);
17                func(...args);
18            };
19            clearTimeout(timeout);
20            timeout = setTimeout(later, wait);
21        };
22    }
23
24    // Function to download the poster image
25    async function downloadPoster() {
26        try {
27            const posterImg = document.querySelector('.ipc-media img.ipc-image');
28            if (!posterImg || !posterImg.src) {
29                console.error('Poster image not found');
30                alert('Could not find poster image to download');
31                return;
32            }
33
34            // Get higher quality version of the image by modifying the URL
35            let imageUrl = posterImg.src;
36            // Remove size restrictions to get full quality
37            imageUrl = imageUrl.replace(/_V1_.*\.jpg/, '_V1_.jpg');
38
39            console.log('Downloading poster from:', imageUrl);
40
41            // Get the movie title for filename
42            const titleElement = document.querySelector('[data-testid="hero__primary-text"]');
43            const movieTitle = titleElement ? titleElement.textContent.trim() : 'poster';
44            const filename = `${movieTitle.replace(/[^a-z0-9]/gi, '_')}_poster.jpg`;
45
46            // Download the image
47            const response = await fetch(imageUrl);
48            const blob = await response.blob();
49            const url = window.URL.createObjectURL(blob);
50            
51            const a = document.createElement('a');
52            a.href = url;
53            a.download = filename;
54            document.body.appendChild(a);
55            a.click();
56            document.body.removeChild(a);
57            window.URL.revokeObjectURL(url);
58
59            console.log('Poster downloaded successfully');
60        } catch (error) {
61            console.error('Error downloading poster:', error);
62            alert('Failed to download poster. Please try again.');
63        }
64    }
65
66    // Function to create and add the download button
67    function addDownloadButton() {
68        // Check if button already exists
69        if (document.getElementById('imdb-poster-download-btn')) {
70            return;
71        }
72
73        // Find the title section to place button near it
74        const titleSection = document.querySelector('[data-testid="hero__pageTitle"]');
75        if (!titleSection) {
76            console.log('Title section not found, will retry...');
77            return;
78        }
79
80        // Create download button
81        const downloadBtn = document.createElement('button');
82        downloadBtn.id = 'imdb-poster-download-btn';
83        downloadBtn.innerHTML = '⬇️ Download Poster';
84        downloadBtn.style.cssText = `
85            display: inline-block;
86            margin-left: 16px;
87            background-color: #f5c518;
88            color: #000;
89            border: none;
90            padding: 8px 16px;
91            font-size: 14px;
92            font-weight: bold;
93            border-radius: 4px;
94            cursor: pointer;
95            box-shadow: 0 2px 8px rgba(0,0,0,0.2);
96            transition: all 0.2s ease;
97            vertical-align: middle;
98        `;
99
100        // Add hover effect
101        downloadBtn.addEventListener('mouseenter', () => {
102            downloadBtn.style.backgroundColor = '#e6b800';
103            downloadBtn.style.transform = 'scale(1.05)';
104        });
105
106        downloadBtn.addEventListener('mouseleave', () => {
107            downloadBtn.style.backgroundColor = '#f5c518';
108            downloadBtn.style.transform = 'scale(1)';
109        });
110
111        // Add click handler
112        downloadBtn.addEventListener('click', (e) => {
113            e.preventDefault();
114            e.stopPropagation();
115            downloadPoster();
116        });
117
118        // Insert button after the title
119        titleSection.parentElement.appendChild(downloadBtn);
120        console.log('Download button added successfully');
121    }
122
123    // Initialize the extension
124    function init() {
125        console.log('IMDb Poster Downloader initialized');
126
127        // Try to add button immediately
128        addDownloadButton();
129
130        // Watch for DOM changes in case the page loads dynamically
131        const observer = new MutationObserver(debounce(() => {
132            addDownloadButton();
133        }, 500));
134
135        observer.observe(document.body, {
136            childList: true,
137            subtree: true
138        });
139
140        // Also try again after a short delay
141        setTimeout(addDownloadButton, 2000);
142    }
143
144    // Start when DOM is ready
145    if (document.readyState === 'loading') {
146        document.addEventListener('DOMContentLoaded', init);
147    } else {
148        init();
149    }
150})();