Skip to content

Instantly share code, notes, and snippets.

@Fooftilly
Last active June 13, 2024 09:50
Show Gist options
  • Save Fooftilly/509ddfbbc0395c0ff209f3fdea112187 to your computer and use it in GitHub Desktop.
Save Fooftilly/509ddfbbc0395c0ff209f3fdea112187 to your computer and use it in GitHub Desktop.
A handy ChatGPT userscript that adds a button below the film poster on Letterboxd, allowing you to search for the same film on RateYourMusic.
// ==UserScript==
// @name Letterboxd to RYM Search
// @version 0.5
// @description A handy ChatGPT userscript that adds a button below the film poster on Letterboxd, allowing you to search for the same film on RateYourMusic
// @author ChatGPT
// @namespace https://gist.github.com/Fooftilly
// @downloadURL https://gist.github.com/Fooftilly/509ddfbbc0395c0ff209f3fdea112187/raw/Letterboxd_to_RYM_Film_Search.user.js
// @updateURL https://gist.github.com/Fooftilly/509ddfbbc0395c0ff209f3fdea112187/raw/Letterboxd_to_RYM_Film_Search.user.js
// @match https://letterboxd.com/film/*
// @grant none
// @license none
// ==/UserScript==
(function() {
'use strict';
function encodeMovieTitle(title) {
return encodeURIComponent(title);
}
function createRYMSearchURL(title) {
const encodedTitle = encodeMovieTitle(title);
return `https://rateyourmusic.com/search?searchterm=${encodedTitle}&searchtype=F`;
}
function addRYMSearchButton() {
const movieTitleElement = document.querySelector('h1.headline-1');
const filmStatsElement = document.querySelector('.film-stats');
if (movieTitleElement && filmStatsElement) {
const movieTitle = movieTitleElement.innerText;
const rymSearchURL = createRYMSearchURL(movieTitle);
const rymButton = document.createElement('a');
rymButton.innerText = 'Search title on RYM';
rymButton.href = rymSearchURL;
rymButton.target = '_blank';
// Apply styles to the button
rymButton.style.display = 'inline-block';
rymButton.style.margin = '10px auto';
rymButton.style.padding = '5px 10px';
rymButton.style.border = '1px solid #1c1c1c';
rymButton.style.borderRadius = '4px';
rymButton.style.fontSize = '14px';
rymButton.style.fontWeight = '500';
rymButton.style.textDecoration = 'none';
rymButton.style.color = '#1c1c1c';
rymButton.style.background = '#f5f5f5';
// Create a new div to hold the button
const buttonDiv = document.createElement('div');
buttonDiv.appendChild(rymButton);
// Apply styles to center the button within the div
buttonDiv.style.textAlign = 'center';
buttonDiv.style.width = '100%';
// Append the new div below the film-stats element
filmStatsElement.parentElement.appendChild(buttonDiv);
} else {
console.error('Could not find the necessary elements.');
}
}
// Try adding the button after a delay to give the page more time to load
setTimeout(addRYMSearchButton, 2000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment