IMDb Image Extractor

Displays links to easily extract individual images from IMDb

目前為 2024-04-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            IMDb Image Extractor
// @namespace    https://github.com/ollm/
// @version      0.1
// @description  Displays links to easily extract individual images from IMDb
// @author       ollm
// @license         MIT
// @homepageURL     https://github.com/ollm/IMDb-Image-Extractor
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @match        https://*.imdb.com/title/*/mediaviewer/*
// @include         https://*.imdb.com/title/*/mediaviewer/*
// @inject-into     content

// ==/UserScript==

(function () {
	'use strict';

	// Personalized Sizes
	const personalizedSizes = [
		1920, // FHD
		3840, // UHD
		5000, // IMDb max size
	];

	// Add Google's own CSS used for image dimensions
	addGlobalStyle(`
		.imdbImagesLinksList {
			position: absolute;
			top: 64px;
			left: 0;
			margin: 10px 0px;
			padding: 4px 6px;
			font-family: Roboto-Medium,Roboto,Arial,sans-serif;
			font-size: 10px;
			line-height: 12px;
			z-index: 100;
		}

		.imdbImagesLinksList a {
			text-decoration: none;
		}

		.imdbImagesLinksList span {
			margin: 0px 4px;
			padding: 4px;
			color: #000;
			background-color: rgba(255,255,255,.5);
			border-radius: 6px;
			text-decoration: none;
		}
		`);

	function sizesToHtml(sizes) {

		let html = '';

		for(let key in sizes)
		{
			html += '<a href="'+sizes[key].src+'" target="_blank"><span>'+sizes[key].text+'</span></a>';
		}

		return html;

	}

	function showImagesLinksList() {

		const parent = document.querySelector('main > div.ipc-page-content-container');
		const image = document.querySelector('.media-viewer > div img:not(.peek)');

		let srcset = image.getAttribute('srcset').split(',');

		let first = false;
		let sizes = [];
		let pSizes = [];

		for(let key in srcset)
		{
			let split = srcset[key].trim().split(' ');
			let text = split[1];
			let src = split[0];

			sizes.push({
				text: text.replace(/[^0-9]/iug, '')+'p',
				src: src,
			});

			if(first === false)
				first = src;
		}

		for(let key in personalizedSizes)
		{
			pSizes.push({
				text: personalizedSizes[key]+'p',
				src: first.replace(/jpg_([A-Z]+)[0-9]+_\.jpg/, 'jpg_$1'+personalizedSizes[key]+'_.jpg'),
			});
		}

		let html = sizesToHtml(pSizes)+' | '+sizesToHtml(sizes);

		let imagesLinksList = document.querySelector('.imdbImagesLinksList');

		if(imagesLinksList)
			imagesLinksList.innerHTML = html;
		else
			parent.insertAdjacentHTML('beforeend', '<div class="imdbImagesLinksList">'+html+'</div>');
	}

	// Run script once on document ready
	showImagesLinksList();

	// Initialize new MutationObserver
	const mutationObserver = new MutationObserver(showImagesLinksList);

	// Let MutationObserver target the images
	const targetNode = document.querySelector('.media-viewer');

	// Run MutationObserver
	mutationObserver.observe(targetNode, { childList: true, subtree: true });

	function addGlobalStyle(css) {
		const head = document.getElementsByTagName('head')[0];
		if (!head) return;
		const style = document.createElement('style');
		style.textContent = css;
		head.appendChild(style);
	}
})();