// ==UserScript== // @name PTP button on other film sites // @version 1.1.1 // @namespace https://github.com/chrisjp // @description Adds a button linking to a PTP search for the film on various websites like IMDb, TMDB, Letterboxd, Trakt... // @license MIT // @icon https://www.google.com/s2/favicons?sz=32&domain=https://passthepopcorn.me // @homepageURL https://github.com/chrisjp/ptpBtnOnFilmSites // @supportURL https://github.com/chrisjp/ptpBtnOnFilmSites/issues // @match https://*.imdb.com/title/tt* // @match https://letterboxd.com/film/* // @match https://trakt.tv/movies/* // @match https://www.themoviedb.org/movie/* // @exclude https://letterboxd.com/film/*/views/* // @exclude https://letterboxd.com/film/*/lists/* // @exclude https://letterboxd.com/film/*/likes/* // @exclude https://letterboxd.com/film/*/fans/* // @exclude https://letterboxd.com/film/*/ratings/* // @exclude https://letterboxd.com/film/*/reviews/* // @grant GM.addStyle // @run-at document-end // @noframes // @downloadURL https://update.greasyfork.org/scripts/452640/PTP%20button%20on%20other%20film%20sites.user.js // @updateURL https://update.greasyfork.org/scripts/452640/PTP%20button%20on%20other%20film%20sites.meta.js // ==/UserScript== (function() { 'use strict'; // Which website are we on? let domain = window.location.hostname.replace('www.', ''); let imdbId = null; //console.log(`Domain: ${domain}`); if (domain === "imdb.com") { addPtpToImdb(); } else if (domain === "letterboxd.com") { addPtpToLetterboxd(); } else if (domain === "trakt.tv") { addPtpToTrakt(); } else if (domain === "themoviedb.org") { addPtpToTmdb(); } })(); // IMDb: Add a button linking to PTP in the ratings bar function addPtpToImdb() { // Perform some checks... // 1. that this film has a rating (i.e. it's been released) // 2. User rating button. This is useful in rare cases where a film is too obscure or new to have // enough ratings (>=5) for IMDb to display an average let filmHasAggRating = document.querySelector('[data-testid="hero-rating-bar__aggregate-rating__score"]'); let filmHasYourRating = document.querySelector('[data-testid="hero-rating-bar__user-rating"]'); // Get IMDb ID from the URL let imdbId = document.URL.match(/\/tt([0-9]+)\//)[1]; if (imdbId > 0 && (filmHasAggRating !== null || filmHasYourRating !== null)) { // Since a lot of relevant class names are random... Basically we: // 1. get the div.rating-bar__base-button elements // 2. clone the first one (IMDb average user rating) // 3. set its HTML to the information we just scraped from Letterboxd // 4. add it to the DOM with the other div.rating-bar__base-button elements // That way it keeps all IMDB's styling and looks like a normal part of the page const ptpUrl = "https://passthepopcorn.me/torrents.php?action=advanced&searchstr=tt" + imdbId + "&order_by=relevance"; // Clone the node let ratingBarBtns = document.querySelectorAll(".rating-bar__base-button"); let ratingBarBtnPTP = ratingBarBtns[0].cloneNode(true); // Add CSS (this forces it to the leftmost position in the ratings bar) ratingBarBtnPTP.classList.add('ptp-button'); GM.addStyle(` .ptp-button { order: -1; } `); // Set title ratingBarBtnPTP.children[0].innerHTML = "PTP"; // If the cloned node is the IMDb aggregate rating we can simply overwrite the child elements' innerHTML if (ratingBarBtnPTP.dataset.testid === "hero-rating-bar__aggregate-rating") { console.log("We have a valid IMDb rating. Adding PTP button to DOM..."); // set a.href let ptpElementA = ratingBarBtnPTP.children[1]; ptpElementA.href = ptpUrl; // edit all its child elements let ptpElementADiv = ptpElementA.children[0].children[0]; // icon set to 24x24 ptpElementADiv.children[0].innerHTML = ''; // ratings data let ptpElementDiv = ptpElementADiv.children[1]; // average rating ptpElementDiv.children[0].children[0].innerHTML = "\uD83D\uDD0E"; ptpElementDiv.children[0].children[1].remove(); // total ratings ptpElementDiv.children[2].remove(); // data-testid ptpElementDiv.children[0].dataset.testid = "hero-rating-bar__ptp-button"; } // If the cloned node is NOT the IMDb aggregate rating (it doesn't have one) it'll be the button allowing us to rate it if logged in // The child nodes of the