Skip to content

Instantly share code, notes, and snippets.

@thiagomgd
Last active February 9, 2024 23:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save thiagomgd/ddc36493dc934490fe3f4949e827e4bb to your computer and use it in GitHub Desktop.
Better TMDB
// ==UserScript==
// @name Better TMDB
// @namespace http://tampermonkey.net/
// @match https://www.themoviedb.org/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// @grant GM_getValue
// @grant GM_setValue
// @version 1.0
// @author Geekosaur
// @description 2024-01-12, 8:05:21 p.m.
// ==/UserScript==
const config = GM_getValue("config", {});
const AUTH_BEARER = config["AUTH_BEARER"];
const API_KEY = config["API_KEY"];
const ACCOUNT = config["ACCOUNT"];
const ACTORS = config["ACTORS"];
const CAST_AUTO_LOAD_MORE_DETAILS = true;
const HIGHLIGHT = "#dcefff";
const MS_PER_DAY = 1000 * 60 * 60 * 24;
let CURRENT_FILTER = "";
let CURRENT_EXT_LIST_NEXT_PAGE = 1;
const HEADERS = {
accept: "application/json",
Authorization: `Bearer ${AUTH_BEARER}`,
};
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName("head")[0];
if (!head) {
return;
}
style = document.createElement("style");
style.type = "text/css";
style.innerHTML = css;
head.appendChild(style);
}
/*
HELPER FUNCTIONS
*/
function ListPageShowAll() {
console.debug("SHOW ALL");
const allMedia = document.querySelectorAll("li.item.visited");
allMedia.forEach((el) => {
el.style.display = "list-item";
});
CURRENT_FILTER = "";
}
function ListPageUnratedOnly() {
const allMedia = document.querySelectorAll("li.item.visited");
allMedia.forEach((el) => {
if (el.classList.contains("rated")) {
el.style.display = "none";
} else {
el.style.display = "list-item";
}
});
CURRENT_FILTER = "unrated";
}
function ListPageRatedOnly() {
const allMedia = document.querySelectorAll("li.item.visited");
allMedia.forEach((el) => {
if (el.classList.contains("rated")) {
el.style.display = "list-item";
} else {
el.style.display = "none";
}
});
CURRENT_FILTER = "rated";
}
function ListPageAdultOnly() {
const allMedia = document.querySelectorAll("li.item.visited");
allMedia.forEach((el) => {
if (el.classList.contains("adult_false")) {
el.style.display = "none";
} else {
el.style.display = "list-item";
}
});
CURRENT_FILTER = "adult";
}
function ListPageForeignOnly() {
const allMedia = document.querySelectorAll("li.item.visited");
allMedia.forEach((el) => {
if (el.classList.contains("foreign-language")) {
el.style.display = "list-item";
} else {
el.style.display = "none";
}
});
CURRENT_FILTER = "rated";
}
/*
FETCH FUNCTIONS
*/
function fetch_ext_lists(movie_id, page) {
return new Promise(function (resolve, reject) {
GM_xmlhttpRequest({
method: "GET",
headers: HEADERS,
responseType: "json",
synchronous: false,
url: `https://api.themoviedb.org/3/movie/${movie_id}/lists?language=en-US&page=${page}`,
onload: (resp) => {
let json = JSON.parse(resp.responseText);
if (json && json.Error) {
console.log("Error: " + json.Error);
resolve("error");
return;
}
console.debug("response", json);
if (json.total_pages > page) {
CURRENT_EXT_LIST_NEXT_PAGE = page + 1;
} else {
CURRENT_EXT_LIST_NEXT_PAGE = 0;
}
resolve(json.results);
return;
},
});
});
}
async function loadExtLists(movie_id) {
console.debug("loadExtLists", movie_id, CURRENT_EXT_LIST_NEXT_PAGE);
if (!CURRENT_EXT_LIST_NEXT_PAGE) {
return;
}
const lists = await fetch_ext_lists(movie_id, CURRENT_EXT_LIST_NEXT_PAGE);
console.debug("!!!", lists);
const links = lists
.map((list) => {
return `<li><a href="https://www.themoviedb.org/list/${list.id}">${list.name}</a></li>`;
})
.join(" ");
const el_listsUl = document.getElementById("extListsUl");
el_listsUl.innerHTML = links;
}
function fetch_person_movie_credits(person_id) {
console.debug("fetching credits");
return new Promise(function (resolve, reject) {
GM_xmlhttpRequest({
method: "GET",
headers: HEADERS,
responseType: "json",
synchronous: false,
url: `https://api.themoviedb.org/3/person/${person_id}/movie_credits?language=en-US`,
onload: (resp) => {
let json = JSON.parse(resp.responseText);
if (json && json.Error) {
console.log("Error: " + json.Error);
resolve("error");
return;
}
resolve(json.cast);
return;
},
});
});
}
async function loadPersonPosters(actor_id) {
const movies_list = await fetch_person_movie_credits(actor_id);
const avg_global_rating =
movies_list.reduce((total, item) => total + item.vote_average, 0) /
movies_list.filter((item) => item.vote_average).length;
const movies = {};
movies_list.forEach((el, index) => (movies[`/movie/${el.id}`] = el));
const _el_sidebar = document.querySelector("section.left_column");
let el_rating = document.createElement("p");
el_rating.textContent = "Global Rating: " + avg_global_rating.toFixed(2);
_el_sidebar.firstChild.appendChild(el_rating);
const _el_role_links = document.querySelectorAll("td.role > a.tooltip");
for (const roleLink of _el_role_links) {
const movieData = movies[roleLink.pathname];
// console.debug(roleLink.pathname, movieData);
if (!movieData) continue;
if (movieData.original_language !== "en") {
roleLink.textContent = `[${movieData.original_language}] ${roleLink.textContent}`;
}
if (movieData.adult) {
roleLink.textContent = `[A] ${roleLink.textContent}`;
}
roleLink.closest("td").style.verticalAlign = "top";
const _el_tr = roleLink.closest("tr");
const el_data_td = document.createElement("td");
el_data_td.innerHTML = `<td><span class="rating">Rating: ${movieData.vote_average}</span></br><span class="popularity">Pop.: ${movieData.popularity}</span></td>`;
el_data_td.style.verticalAlign = "top";
el_data_td.style.float = "right";
if (movieData.vote_average < avg_global_rating) {
el_data_td.firstChild.classList.add("less_avg");
}
_el_tr.appendChild(el_data_td);
const el_image_td = document.createElement("td");
el_image_td.style.width = "115px";
el_image_td.innerHTML = `<td><img style="max-height:150px;float: right" src="https://image.tmdb.org/t/p/original${movieData.poster_path}"/></td>`;
_el_tr.appendChild(el_image_td);
}
}
function fetch_tmdb_lists_list() {
// TODO: add pagination
// https://api.themoviedb.org/4/account/{account_object_id}/lists
console.log("loading lists");
return new Promise(function (resolve, reject) {
GM_xmlhttpRequest({
method: "GET",
headers: HEADERS,
responseType: "json",
synchronous: false,
url: `https://api.themoviedb.org/4/account/${ACCOUNT}/lists?api_key=${API_KEY}`,
onload: (resp) => {
let json = JSON.parse(resp.responseText);
if (json && json.Error) {
console.log("Error: " + json.Error);
resolve("error");
return;
}
resolve(json.results);
return;
},
});
});
}
function fetch_list_items_page(list_id, page) {
return new Promise(function (resolve, reject) {
GM_xmlhttpRequest({
method: "GET",
headers: HEADERS,
responseType: "json",
synchronous: false,
url: `https://api.themoviedb.org/4/list/${list_id}?api_key=${API_KEY}&page=${page}`,
onload: (resp) => {
// console.log("!!!!!", resp);
let json = JSON.parse(resp.responseText);
if (json && json.Error) {
console.log("Error: " + json.Error);
resolve("error");
return;
}
// console.log('data!!!!: ', json);
resolve(json);
return;
},
});
});
}
function fetch_ratings_page(media_type, page) {
return new Promise(function (resolve, reject) {
GM_xmlhttpRequest({
method: "GET",
headers: HEADERS,
responseType: "json",
synchronous: false,
url: `https://api.themoviedb.org/4/account/${ACCOUNT}/${media_type}/rated?api_key=${API_KEY}&page=${page}`,
onload: (resp) => {
let json = JSON.parse(resp.responseText);
if (json && json.Error) {
console.log("Error: " + json.Error);
resolve("error");
return;
}
// console.log('data!!!!: ', json);
resolve(json);
return;
},
});
});
}
function fetch_watchlist_page(media_type, page) {
return new Promise(function (resolve, reject) {
GM_xmlhttpRequest({
method: "GET",
headers: HEADERS,
responseType: "json",
synchronous: false,
url: `https://api.themoviedb.org/4/account/${ACCOUNT}/${media_type}/watchlist?api_key=${API_KEY}&page=${page}`,
onload: (resp) => {
let json = JSON.parse(resp.responseText);
if (json && json.Error) {
console.log("Error: " + json.Error);
resolve("error");
return;
}
// console.log('data!!!!: ', json);
resolve(json);
return;
},
});
});
}
async function fetch_tmdb_list_items(list_id) {
// TODO: add pagination
// https://api.themoviedb.org/4/account/{account_object_id}/lists
// console.log('loading list items');
const list_items = [];
let page = 1,
pages = 1;
do {
const data = await fetch_list_items_page(list_id, page);
pages = data.total_pages;
page = page + 1;
list_items.push(
...data.results.map((itm) => {
return {
id: itm.id,
media_type: itm.media_type,
language: itm.original_language,
};
})
);
} while (page <= pages);
return list_items;
}
async function load_tmdb_lists() {
// get lists from local, or remote
let lists = GM_getValue("user_lists", undefined);
const last_sync = GM_getValue("user_lists_sync", Date.now());
const dateDiff = (Date.now() - last_sync) / MS_PER_DAY;
if (lists && dateDiff <= 1) {
return lists;
}
const list_array = await fetch_tmdb_lists_list();
lists = {};
const media_details = {};
for (let list of list_array) {
const { id: listId, name: listName, ...listData } = list;
const items = await fetch_tmdb_list_items(listId);
for (const item of items) {
const { id: itemId, media_type, ...details } = item;
media_details[`${media_type}-${itemId}`] = details;
}
lists[listId] = {
id: listId,
name: listName,
items: items.map((item) => `${item.media_type}-${item.id}`),
};
}
GM_setValue("user_lists", lists);
GM_setValue("user_lists_sync", Date.now());
GM_setValue("media_details", media_details);
return lists;
}
async function fetch_tmdb_ratings(media_type) {
console.log("loading ratings", media_type);
const rating_items = [];
let page = 1,
pages = 1;
do {
const data = await fetch_ratings_page(media_type, page);
pages = data.total_pages;
page = page + 1;
rating_items.push(...data.results);
} while (page <= pages);
return rating_items;
}
async function fetch_tmdb_watchlist(media_type) {
console.log("loading watchlist", media_type);
const watchlist_items = [];
let page = 1,
pages = 1;
do {
const data = await fetch_watchlist_page(media_type, page);
pages = data.total_pages;
page = page + 1;
watchlist_items.push(...data.results);
} while (page <= pages);
return watchlist_items;
}
function map_ratings_dict(media_type, ratings, media_ratings) {
for (const item of ratings) {
const rating = item.account_rating.value;
const key = `${media_type}-${item.id}`;
if (media_ratings[key]) {
console.error("DUPLICATE RATING", item);
} else {
media_ratings[key] = rating;
}
}
return media_ratings;
}
function map_watchlist_dict(media_type, watchlist, media_watchlist) {
for (const item of watchlist) {
const key = `${media_type}-${item.id}`;
if (media_watchlist[key]) {
console.error("DUPLICATE RATING", item);
} else {
media_watchlist[key] = true;
}
}
return media_watchlist;
}
async function load_tmdb_ratings() {
let ratings = GM_getValue("user_ratings", undefined);
const last_sync = GM_getValue("user_ratings_sync", Date.now());
const dateDiff = (Date.now() - last_sync) / MS_PER_DAY;
if (ratings && dateDiff <= 1) {
return ratings;
}
const movie_ratings = await fetch_tmdb_ratings("movie");
const tv_ratings = await fetch_tmdb_ratings("tv");
console.log(
"fetched ratings. Movies:",
movie_ratings.length,
"TV",
tv_ratings.length,
"Total",
movie_ratings.length + tv_ratings.length
);
const media_ratings = {};
map_ratings_dict("movie", movie_ratings, media_ratings);
map_ratings_dict("tv", tv_ratings, media_ratings);
GM_setValue("user_ratings", media_ratings);
GM_setValue("user_ratings_sync", Date.now());
return media_ratings;
}
async function load_tmdb_watchlist() {
let watchlist = GM_getValue("user_watchlist", undefined);
const last_sync = GM_getValue("user_watchlist_sync", Date.now());
const dateDiff = (Date.now() - last_sync) / MS_PER_DAY;
if (watchlist && dateDiff <= 1) {
return watchlist;
}
const movie_watchlist = await fetch_tmdb_watchlist("movie");
const tv_watchlist = await fetch_tmdb_watchlist("tv");
// console.log("fetched ratings. Movies:", movie_ratings.length, "TV", tv_ratings.length, "Total", movie_ratings.length + tv_ratings.length)
const media_watchlist = {};
map_watchlist_dict("movie", movie_watchlist, media_watchlist);
map_watchlist_dict("tv", tv_watchlist, media_watchlist);
GM_setValue("user_watchlist", media_watchlist);
GM_setValue("user_watchlist_sync", Date.now());
return media_watchlist;
}
function map_lists_to_dict(lists) {
const media = {};
for (const list of Object.values(lists)) {
const list_key = `${list.id}|${list.name}`;
for (const item of list.items || []) {
if (media[item]) {
media[item].push(list_key);
} else {
media[item] = [list_key];
}
}
}
return media;
}
async function getMediaToListsMap() {
const lists = await load_tmdb_lists();
return map_lists_to_dict(lists);
}
async function getListItems(listId) {
const lists = await load_tmdb_lists();
return lists[listId]?.items || [];
}
async function getMediaDetails() {
return GM_getValue("media_details", {});
}
async function getListItemsAndMedia(listId) {
const lists = await load_tmdb_lists();
if (lists[listId]) {
return [lists[listId].items, await getMediaDetails()];
}
console.debug("loading external list items");
const media_details = {};
const items = await fetch_tmdb_list_items(listId);
for (const item of items) {
const { id: itemId, media_type, ...details } = item;
media_details[`${media_type}-${itemId}`] = details;
}
return [items.map((item) => `${item.media_type}-${item.id}`), media_details];
}
/*
IMPROVE PAGE FUNCTIONS
*/
async function improvePersonPage() {
const media_to_list = await getMediaToListsMap();
const media_ratings = await load_tmdb_ratings();
const media_watchlist = await load_tmdb_watchlist();
let total_rating = 0;
let total_rated = 0;
let total_listed = 0;
let total_watchlist = 0;
const tmdb_id = parseInt(
window.location.href
.split("https://www.themoviedb.org/person/")[1]
.split("-")[0]
);
// FLAG MEDIA ON MY LISTS
const movieLinks = document.querySelectorAll("a.tooltip");
for (const movie of movieLinks) {
const key = movie.pathname.split("/").slice(1).join("-");
if (media_to_list[key]) {
total_listed += 1;
const TMDB_lists = [];
media_to_list[key].forEach((item) => {
TMDB_lists.push(item.split("|")[1]);
});
movie.textContent = `${movie.textContent} [${TMDB_lists.join(", ")}]`;
movie.parentElement.parentElement.style.backgroundColor = HIGHLIGHT;
}
if (media_ratings[key]) {
total_rated += 1;
total_rating += media_ratings[key];
const _el_check =
movie.parentElement.previousElementSibling.querySelector(
".circle-empty"
);
_el_check.classList.remove("circle-empty");
_el_check.classList.add("circle-check");
}
if (media_watchlist[key]) {
total_watchlist += 1;
movie.parentElement.parentElement.style.backgroundColor = HIGHLIGHT;
const _el_check =
movie.parentElement.previousElementSibling.querySelector(
".circle-empty"
);
_el_check.classList.remove("circle-empty");
_el_check.classList.add("bookmark");
}
}
// console.log("TOTAL RATED", total_rated, 'AVERAGE', total_rating/total_rated);
let el_section_header = document.createElement("section");
if (!CAST_AUTO_LOAD_MORE_DETAILS) {
// add option to load images
const el_imgs_btn = document.createElement("button");
el_imgs_btn.setAttribute("id", "loadPostersBtn");
el_imgs_btn.textContent = "Load Posters";
el_section_header.appendChild(el_imgs_btn);
}
// ADD IF ACTOR IS ON MY LIST
if (ACTORS.includes(tmdb_id)) {
let el_following = document.createElement("p");
el_following.innerText = `Following`;
el_section_header.appendChild(el_following);
}
let el_watchlist = document.createElement("p");
el_watchlist.textContent =
"Total Watchlist: " + total_watchlist + "/" + movieLinks.length;
let el_listed = document.createElement("p");
el_listed.textContent =
"Total Listed: " + total_listed + "/" + movieLinks.length;
let el_rated = document.createElement("p");
el_rated.textContent =
"Total Rated: " + total_rated + "/" + movieLinks.length;
let el_rating = document.createElement("p");
el_rating.textContent =
"Avg Rating: " +
(total_rating ? Number(total_rating / total_rated).toFixed(2) : 0);
let el_space = document.createElement("p");
el_section_header.appendChild(el_watchlist);
el_section_header.appendChild(el_listed);
el_section_header.appendChild(el_rated);
el_section_header.appendChild(el_rating);
el_section_header.appendChild(el_space);
const _el_sidebar = document.querySelector("section.left_column");
_el_sidebar.insertBefore(el_section_header, _el_sidebar.firstChild);
if (!CAST_AUTO_LOAD_MORE_DETAILS) {
document.getElementById("loadPostersBtn").addEventListener(
"click",
() => {
loadPersonPosters(tmdb_id);
},
false
);
} else {
loadPersonPosters(tmdb_id);
}
}
async function addRatedToListPage(list_items, media_ratings) {
const _el_totalratings = document.getElementById("totalRatings");
if (!_el_totalratings) {
let total_rated = 0;
for (const key of list_items) {
// const key = `${media_details[id].media_type}-${id}`;
if (media_ratings[key]) {
total_rated += 1;
}
}
const _el_info = document.querySelector("ul.list_info");
let el_ratings = document.createElement("li");
el_ratings.innerHTML = `<span><em>${total_rated}</em></span><br/> rated items`;
el_ratings.setAttribute("id", "totalRatings");
// TODO: fix to insert as 2nd item
_el_info.firstChild.after(el_ratings);
}
}
function addMediaDetailsToListPage(media_ratings, media_details) {
const mediaLinks = document.querySelectorAll(
"ul.items_wrapper.list_results li.item:not(.visited) div.image a"
);
for (const media of mediaLinks) {
// console.debug(media.textContent);
const key = media.pathname.split("/").slice(1).join("-");
media.closest("li").classList.add("visited");
if (media_ratings[key]) {
media.closest("li").classList.add("rated");
}
if (media_details[key] && media_details[key].language) {
// TODO: add language
const _el_strip = media.closest("li").querySelector("div.info_strip");
const el_language = document.createElement("div");
el_language.innerHTML = `<div><span class="language">${media_details[
key
].language.toUpperCase()}</span></div>`;
_el_strip.children[0].after(el_language);
if (media_details[key].language !== "en") {
media.closest("li").classList.add("foreign-language");
}
}
}
}
async function improveListPage() {
if (window.location.pathname.endsWith("/edit")) {
return;
}
console.debug("improveListPage");
const media_ratings = await load_tmdb_ratings();
const tmdb_id = parseInt(
window.location.href
.split("https://www.themoviedb.org/list/")[1]
.split("-")[0]
);
const [list_items, media_details] = await getListItemsAndMedia(tmdb_id);
await addRatedToListPage(list_items, media_ratings);
await addMediaDetailsToListPage(media_ratings, media_details);
// button menu
const _el_myFilters = document.getElementById("myFilters");
if (!_el_myFilters) {
const _el_menu_bar = document.querySelector("ul.list_menu_bar");
let el_rating_filter = document.createElement("li");
el_rating_filter.setAttribute("id", "myFilters");
el_rating_filter.innerHTML = `<li class="menu">
<a class="rounded white button no_click" href="#">Filter By</a>
<ul class="sub_menu">
<li id="filterShowAll" style="color:blue">All</li>
<li id="filterRatedOnly" style="color:blue">Rated</li>
<li id="filterUnratedOnly" style="color:blue">Unrated</li>
<li id="filterAdultOnly" style="color:blue">Adult</li>
<li id="filterForeignOnly" style="color:blue">Foreign</li>
</ul>
</li>
`;
_el_menu_bar.appendChild(el_rating_filter);
document
.getElementById("filterShowAll")
.addEventListener("click", ListPageShowAll, false);
document
.getElementById("filterRatedOnly")
.addEventListener("click", ListPageRatedOnly, false);
document
.getElementById("filterUnratedOnly")
.addEventListener("click", ListPageUnratedOnly, false);
document
.getElementById("filterAdultOnly")
.addEventListener("click", ListPageAdultOnly, false);
document
.getElementById("filterForeignOnly")
.addEventListener("click", ListPageForeignOnly, false);
}
waitForKeyElements("div.pagination.infinite", () => {
setTimeout(improveListPage, 1000);
});
}
async function improveWatchListPage() {
console.debug("improveWatchListPage");
const media_to_list = await getMediaToListsMap();
const mediaLinks = document.querySelectorAll(
"div.title a:not(.visited):has(h2)"
);
for (const media of mediaLinks) {
// console.debug(media.textContent);
const key = media.pathname.split("/").slice(1).join("-");
media.classList.add("visited");
if (media_to_list[key]) {
const TMDB_lists = [];
media_to_list[key].forEach((item) => {
TMDB_lists.push(item.split("|")[1]);
});
media.querySelector("h2").textContent = `${
media.textContent
} [${TMDB_lists.join(", ")}]`;
}
}
const _el_load_more = document.querySelector("a.load_more");
if (_el_load_more) {
_el_load_more.addEventListener("click", () => {
setTimeout(improveWatchListPage, 1000);
});
}
waitForKeyElements("div.pagination.infinite", () => {
setTimeout(improveWatchListPage, 1000);
});
}
async function improveSearchPage() {
// console.debug('improve search page');
const media_to_list = await getMediaToListsMap();
// console.debug('>> loaded lists');
const media_ratings = await load_tmdb_ratings();
// console.debug('>> loaded ratings');
const mediaLinks = document.querySelectorAll("a.result:has(h2)");
// console.debug('>> links', mediaLinks);
for (const media of mediaLinks) {
const key = media.pathname.split("/").slice(1).join("-");
if (media_to_list[key]) {
const TMDB_lists = [];
media_to_list[key].forEach((item) => {
TMDB_lists.push(item.split("|")[1]);
});
media.querySelector("h2").textContent = `${
media.textContent
} [${TMDB_lists.join(", ")}]`;
media.closest("div.details").style.backgroundColor = HIGHLIGHT;
// media.parentElement.parentElement.style.backgroundColor = 'aliceblue';
}
if (media_ratings[key]) {
media.querySelector(
"h2"
).textContent = `${media.textContent} ${media_ratings[key]}*`;
// media.parentElement.parentElement.style.backgroundColor = 'aliceblue';
}
}
}
async function improveMediaPage() {
console.log("improve media page");
const media_to_list = await getMediaToListsMap();
console.log(media_to_list);
let content = 0;
let TMDB_id = 0;
let TMDB_lists = [];
if (window.location.href.includes("https://www.themoviedb.org/movie/")) {
content = "movie";
TMDB_id = parseInt(
window.location.href
.split("https://www.themoviedb.org/movie/")[1]
.split("-")[0]
);
} else if (window.location.href.includes("https://www.themoviedb.org/tv/")) {
content = "tv";
TMDB_id = parseInt(
window.location.href
.split("https://www.themoviedb.org/tv/")[1]
.split("-")[0]
);
} else {
return;
}
(media_to_list[`${content}-${TMDB_id}`] || []).forEach((item) => {
TMDB_lists.push(item.split("|")[1]);
});
let el_lists_header = document.createElement("h3");
el_lists_header.innerText = `Lists: ${TMDB_lists.join(", ")}`;
el_lists_header.classList.add("tagline");
let _el_header_info = document.getElementsByClassName("header_info")[0];
if (_el_header_info) {
_el_header_info.insertBefore(el_lists_header, _el_header_info.firstChild);
}
if (TMDB_lists.length) {
let _el_list_icon = document.getElementsByClassName("thumbnails-list")[0];
_el_list_icon.classList.remove("thumbnails-list");
_el_list_icon.classList.add("plus");
}
// console.log(`${content}-${TMDB_id}`,media_to_list[`${content}-${TMDB_id}`]);
// ADD external lists feature
if (content === "movie") {
const _el_sidebar = document.querySelector("div.column.no_bottom_pad");
const el_lists_div = document.createElement("section");
el_lists_div.setAttribute("id", "listsSection");
el_lists_div.innerHTML = `<section>
<h4>External Lists</h4>
<button id="loadExtLists">Load Lists</button>
<ul id="extListsUl"></ul>
</section>
`;
// _el_sidebar.appendChild(el_lists_div);
_el_sidebar.insertBefore(el_lists_div, _el_sidebar.children[1]);
document.getElementById("loadExtLists").addEventListener(
"click",
() => {
loadExtLists(TMDB_id);
},
false
);
}
}
/*
MAIN
*/
async function main() {
// add global styles
addGlobalStyle(".less_avg { color: red }");
addGlobalStyle(".language { color: white }");
if (window.location.href.startsWith("https://www.themoviedb.org/movie/")) {
improveMediaPage();
} else if (
window.location.href.startsWith("https://www.themoviedb.org/tv/")
) {
improveMediaPage();
} else if (
window.location.href.startsWith("https://www.themoviedb.org/person/")
) {
improvePersonPage();
} else if (
window.location.href.startsWith("https://www.themoviedb.org/search?")
) {
improveSearchPage();
} else if (
window.location.href.startsWith("https://www.themoviedb.org/list/")
) {
improveListPage();
} else if (
window.location.href.startsWith(
"https://www.themoviedb.org/u/falconsensei/watchlist"
)
) {
improveWatchListPage();
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment