Script: IMDb

IMDb Page Cleaner

IMDb has gone crazy with its page layout of late. I don’t care about most of the sections in a movie/tv page. So I wrote a GM script to remove everything I don’t care about. It’s pretty easy to customize. Play with it.

 

Here’s a before and after comparison

screenshot of the website

screenshot of the website

imdb.js
// ==UserScript==
// @name IMDb Page Cleaner
// @version 2.1
// @author Devin
// @description Remove unnecessary information from IMDb & rearrange the layout
// @grant none
// @match https://*.imdb.com/title/tt*
// @namespace CosmicTowel42
// @license GNU GPLv3
// ==/UserScript==
'use strict';
const SELECTORS = {
title: '[data-testid="hero__pageTitle"]',
userReviews: '[data-testid="UserReviews"]',
videos: '[data-testid="videos-section"]',
photos: '[data-testid="Photos"]',
cast: '[data-testid="title-cast"]'
};
const REVIEW_QUERY =
'reviews?sort=reviewVolume&dir=desc&ratingFilter=0&sort=review_volume,desc';
function removeNodes(nodes) {
nodes.flat(Infinity).filter(Boolean).forEach(node => node.remove());
}
function removeSections() {
const selectors = [
'[data-testid="hero-subnav-bar-right-block"]',
'[data-testid="BoxOffice"]',
'[data-testid="News"]',
'[data-testid="contribution"]',
'[data-testid="TechSpecs"]',
'[data-testid="hero-rating-bar__popularity"]',
'div.sc-f2e21260-0.cSzXBj.ipc-page-grid__item.ipc-page-grid__item--span-1',
'div.sc-10602b09-5.kBrxsq',
'[data-testid="main-column-editorial-single"]',
'[data-testid="DynamicFeature_Episodes"]',
'#ProUpsellLink',
'[data-testid="ai-review-summary"]',
'[data-testid="hero__video-link"]',
'[data-testid="hero__photo-link"]',
'[data-testid="episodes-widget"]',
'[data-testid="content-rating"]'
];
const watchlistButton = document.querySelector('[data-testid="tm-box-wl-button"]');
const moreLikeThis = document.querySelector('[data-testid="MoreLikeThis"]');
const moreLikeThisActions = moreLikeThis
? [...moreLikeThis.getElementsByClassName('ipc-poster-card__actions')]
: [];
removeNodes([
...selectors.map(selector => [...document.querySelectorAll(selector)]),
watchlistButton?.parentElement,
moreLikeThisActions,
]);
}
function modifyLayout() {
const userReviews = document.querySelector(SELECTORS.userReviews);
const video = document.querySelector(SELECTORS.videos);
const photos = document.querySelector(SELECTORS.photos);
const cast = document.querySelector(SELECTORS.cast);
if (userReviews) {
const insertionPoint = video || photos || cast;
if (insertionPoint) {
insertionPoint.before(userReviews);
} else {
console.warn('IMDb Page Cleaner: no video, photo, or cast section found.');
}
}
if (cast) {
if (video) cast.after(video);
if (photos) cast.after(photos);
}
}
function getReviewUrl() {
const reviewLink = document
.querySelector(SELECTORS.userReviews)
?.getElementsByClassName('ipc-title-link-wrapper')[0];
return reviewLink ? `${reviewLink.href.split('reviews?')[0]}${REVIEW_QUERY}` : null;
}
function changeReviewUrl() {
const reviewLink = document
.querySelector(SELECTORS.userReviews)
?.getElementsByClassName('ipc-title-link-wrapper')[0];
const reviewUrl = getReviewUrl();
if (reviewLink && reviewUrl) reviewLink.href = reviewUrl;
}
function changeWishlistUrl() {
// IMDb currently reverts this link after it is changed.
const link = document.querySelector('.imdb-header__watchlist-button a');
if (link) {
link.href =
'https://www.imdb.com/user/ur15239538/watchlist?sort=list_order%2Cdesc&view=detail';
}
}
async function loadAllReviews() {
const reviewUrl = getReviewUrl();
const reviewList = document
.querySelector(SELECTORS.userReviews)
?.getElementsByClassName('ipc-list-card--base')[0];
if (!reviewUrl || !reviewList) return;
document.querySelector('[data-testid="reviews-author"]')?.remove();
try {
const response = await fetch(reviewUrl);
if (!response.ok) {
throw new Error(`IMDb returned HTTP ${response.status}`);
}
const html = await response.text();
const doc = new DOMParser().parseFromString(html, 'text/html');
const fetchedReviews = doc.querySelector('.lister-list');
if (!fetchedReviews) {
throw new Error('Review list was not present in the response');
}
reviewList.innerHTML = fetchedReviews.innerHTML;
cleanReviewFooter();
} catch (error) {
console.error('IMDb Page Cleaner: unable to load all reviews.', error);
}
}
function cleanReviewFooter() {
document.querySelectorAll('.lister-item-content .text-muted').forEach(footer => {
footer.innerText = footer.innerText.replace('|', '');
});
}
function addLanguageMetadata() {
const languages = document.querySelectorAll(
'[data-testid="title-details-languages"] a',
);
const title = document.querySelector(SELECTORS.title);
const metadata = title?.parentElement?.querySelector('ul');
if (!metadata) return;
languages.forEach(language => {
const item = document.createElement('li');
item.textContent = language.textContent;
item.setAttribute('role', 'presentation');
item.classList.add('ipc-inline-list__item');
metadata.appendChild(item);
});
}
function fixReviewLink() {
const link = document
.querySelector('[data-testid="reviews-header"]')
?.querySelector('.ipc-title-link-wrapper');
if (!link) return;
link.href = 'reviews/?sort=reviewVolume&dir=desc&ratingFilter=0';
link.href = link.href.replace('m.imdb', 'www.imdb');
}
function delayedRemoveSection() {
setTimeout(() => {
const watchedButton = [...document.querySelectorAll('[data-testid]')].find(element =>
/watched-button-tt\d+/.test(element.getAttribute('data-testid')),
);
removeNodes([
watchedButton,
'[data-testid="hero-media__slate"]',
'[data-testid="videoPreview_preference_button"]',
'[data-testid="RelatedInterests"]',
SELECTORS.videos,
'[data-testid="hero-rating-bar__popularity"]',
].map(item =>
typeof item === 'string' ? [...document.querySelectorAll(item)] : item,
));
}, 1000);
}
function getTitleId() {
return window.location.pathname.match(/\/title\/(tt\d+)/)?.[1] ?? null;
}
function addExternalLink(label, url, color) {
const title = document.querySelector(SELECTORS.title);
if (!title?.parentElement || title.parentElement.querySelector(`[data-imdb-cleaner-link="${label}"]`)) {
return;
}
const link = document.createElement('a');
link.href = url;
link.target = '_blank';
link.rel = 'noopener noreferrer';
link.textContent = label;
link.dataset.imdbCleanerLink = label;
Object.assign(link.style, {
display: 'inline-block',
color,
fontSize: '14px',
padding: '0 15px',
textDecoration: 'underline',
});
title.parentElement.append(link);
}
function addShowGridURL() {
const type = document.querySelector('meta[property="og:type"]')?.content;
const titleId = getTitleId();
if (type === 'video.tv_show' && titleId) {
addExternalLink(
'ShowGrid',
`https://theshowgrid.com/series/${titleId}/from-imdb-script`,
'#c7b4fa',
);
}
}
function runSafely(label, callback) {
try {
callback();
} catch (error) {
console.error(`IMDb Page Cleaner: ${label} failed.`, error);
}
}
function main() {
const run = () => {
observer.disconnect();
setTimeout(() => {
runSafely('adding ShowGrid link', addShowGridURL);
runSafely('modifying layout', modifyLayout);
runSafely('removing sections', removeSections);
runSafely('changing review URL', changeReviewUrl);
runSafely('loading reviews', loadAllReviews);
runSafely('adding language metadata', addLanguageMetadata);
runSafely('scheduling delayed cleanup', delayedRemoveSection);
}, 1000);
};
const observer = new MutationObserver(() => {
if (document.querySelector(SELECTORS.title)) run();
});
if (document.querySelector(SELECTORS.title)) {
run();
} else {
observer.observe(document.documentElement, { childList: true, subtree: true });
}
}
main();