// ==UserScript==
// @name Letterboxd to IMDb Links with Ratings and Additional Sites
// @namespace http://tampermonkey.net/
// @version 2.5
// @description Add IMDb, Rotten Tomatoes, Metacritic ratings, and links to Ekşi Sözlük, Trakt, and Sinefil for Letterboxd films using OMDb API
// @author sheeper
// @match https://letterboxd.com/*
// @grant GM_xmlhttpRequest
// @connect omdbapi.com
// @require https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==
(function() {
'use strict';
// OMDB API anahtarları
const OMDB_API_KEYS = [
"9db6d9f8",
"47ca1a23",
"af42b336",
"11f220cd",
"3566c9e5",
"2d1afb54"
];
function getRandomApiKey(apiKeys) {
return apiKeys[Math.floor(Math.random() * apiKeys.length)];
}
function addIMDbLinks() {
$('.poster-container').each(function() {
const filmPoster = $(this);
const filmTitle = filmPoster.find('img').attr('alt');
const filmYear = filmPoster.closest('[data-film-release-year]').data('film-release-year');
const filmLink = filmPoster.find('a').attr('href');
console.log(`Film Link: ${filmLink}`); // Log the film link to verify
const apiKey = getRandomApiKey(OMDB_API_KEYS);
const searchUrl = `https://www.omdbapi.com/?apikey=${apiKey}&t=${encodeURIComponent(filmTitle)}&y=${filmYear}`;
GM_xmlhttpRequest({
method: 'GET',
url: searchUrl,
onload: function(response) {
const data = JSON.parse(response.responseText);
if (data && data.Response !== "False") {
const movieId = data.imdbID;
const movieYear = data.Year;
const imdbRating = data.imdbRating;
const rtRating = data.Ratings.find(r => r.Source === "Rotten Tomatoes")?.Value || "N/A";
const mcRatingRaw = data.Ratings.find(r => r.Source === "Metacritic")?.Value || "N/A";
const mcRating = mcRatingRaw !== "N/A" ? mcRatingRaw.split('/')[0] : "N/A";
const rtLink = `https://www.rottentomatoes.com/search?search=${encodeURIComponent(filmTitle)}%20${movieYear}`;
const mcLink = `https://www.metacritic.com/search/${encodeURIComponent(filmTitle)}%20${movieYear}/?page=1&category=2`;
// Ratings Div
const ratingsDiv = $('<div>')
.css('position', 'absolute')
.css('top', '5px')
.css('left', '50%')
.css('transform', 'translateX(-50%)')
.css('background-color', 'rgba(0, 0, 0, 0.7)')
.css('padding', '4px 6px')
.css('border-radius', '5px')
.css('display', 'flex')
.css('align-items', 'center')
.css('z-index', '10');
if (imdbRating) {
const imdbLogo = $('<a>')
.attr('href', `https://www.imdb.com/title/${movieId}`)
.attr('target', '_blank')
.append(
$('<img>')
.attr('src', 'https://upload.wikimedia.org/wikipedia/commons/6/69/IMDB_Logo_2016.svg')
.attr('alt', 'IMDb Logo')
.css('width', '14px') // Intermediate size
.css('vertical-align', 'middle')
.css('margin-right', '2px') // Intermediate margin
);
const imdbRatingText = $('<span>')
.text(imdbRating)
.css('vertical-align', 'middle')
.css('font-size', '11px') // Intermediate font size
.css('color', '#fff'); // White text color
ratingsDiv.append(imdbLogo).append(imdbRatingText);
}
if (rtRating !== "N/A") {
const rtLogo = $('<a>')
.attr('href', rtLink)
.attr('target', '_blank')
.append(
$('<img>')
.attr('src', 'https://upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Rotten_Tomatoes.svg/2019px-Rotten_Tomatoes.svg.png')
.attr('alt', 'Rotten Tomatoes Logo')
.css('width', '14px') // Intermediate size
.css('vertical-align', 'middle')
.css('margin-left', '5px') // Intermediate margin
.css('margin-right', '2px') // Intermediate margin
);
const rtRatingText = $('<span>')
.text(rtRating)
.css('vertical-align', 'middle')
.css('font-size', '11px') // Intermediate font size
.css('color', '#fff'); // White text color
ratingsDiv.append(rtLogo).append(rtRatingText);
}
if (mcRating !== "N/A") {
const mcLogo = $('<a>')
.attr('href', mcLink)
.attr('target', '_blank')
.append(
$('<img>')
.attr('src', 'https://upload.wikimedia.org/wikipedia/commons/2/20/Metacritic.svg')
.attr('alt', 'Metacritic Logo')
.css('width', '14px') // Intermediate size
.css('vertical-align', 'middle')
.css('margin-left', '5px') // Intermediate margin
.css('margin-right', '2px') // Intermediate margin
);
const mcRatingText = $('<span>')
.text(mcRating)
.css('vertical-align', 'middle')
.css('font-size', '11px') // Intermediate font size
.css('color', '#fff'); // White text color
ratingsDiv.append(mcLogo).append(mcRatingText);
}
filmPoster.css('position', 'relative').append(ratingsDiv);
// Additional links Div
const additionalLinksDiv = $('<div>')
.css('background-color', 'rgba(0, 0, 0, 0.7)')
.css('padding', '4px 6px')
.css('border-radius', '5px')
.css('display', 'flex')
.css('justify-content', 'center')
.css('align-items', 'center')
.css('margin-top', '5px'); // Added margin-top for spacing
// Ekşi Sözlük, Trakt ve Sinefil ikonları ve linkleri
const ekşiLink = `https://eksisozluk.com/?q=${encodeURIComponent(filmTitle)}`;
const traktLink = `https://trakt.tv/search/imdb?query=${encodeURIComponent(movieId)}`;
const sinefilLink = `https://www.sinefil.com/ara/${encodeURIComponent(movieId)}`;
const ekşiLogo = $('<a>')
.attr('href', ekşiLink)
.attr('target', '_blank')
.append(
$('<img>')
.attr('src', 'https://i.imgur.com/k5K7m9h.png')
.attr('alt', 'Ekşi Sözlük Logo')
.css('width', '10px')
.css('vertical-align', 'middle')
.css('margin-left', '5px')
.css('margin-right', '2px')
);
const traktLogo = $('<a>')
.attr('href', traktLink)
.attr('target', '_blank')
.append(
$('<img>')
.attr('src', 'https://i.imgur.com/adN3cCW.png')
.attr('alt', 'Trakt Logo')
.css('width', '14px')
.css('vertical-align', 'middle')
.css('margin-left', '5px')
.css('margin-right', '2px')
);
const sinefilLogo = $('<a>')
.attr('href', sinefilLink)
.attr('target', '_blank')
.append(
$('<img>')
.attr('src', 'https://i.imgur.com/Z8E36pP.png')
.attr('alt', 'Sinefil Logo')
.css('width', '14px')
.css('vertical-align', 'middle')
.css('margin-left', '5px')
.css('margin-right', '2px')
);
additionalLinksDiv.append(ekşiLogo).append(traktLogo).append(sinefilLogo);
// Append additional links div below the ratings div
ratingsDiv.after(additionalLinksDiv);
const filmTitleDiv = $('<div>')
.text(`${filmTitle} (${movieYear})`)
.css('text-align', 'center') // Center the text
.css('margin-top', '5px')
.css('color', filmPoster.find('a').css('color')); // Match the color of other texts
filmPoster.append(filmTitleDiv);
}
}
});
});
}
$(document).ready(function() {
addIMDbLinks();
// Overlay-actions bölümünü yukarı taşıma
$('<style>')
.prop('type', 'text/css')
.html(`
.overlay-actions {
top: 140px !important; /* Yukarı taşıma değeri, ihtiyaca göre ayarlanabilir */
}
`)
.appendTo('head');
});
})();