Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Trakt movie/show info list
- // @namespace https://greasyfork.org/en/users/85671-jcunews
- // @version 1.0.1
- // @license AGPL v3
- // @author jcunews
- // @description Context: https://www.reddit.com/r/GreaseMonkey/comments/11332a7/creating_an_unlimited_watchlist_from_traktv/
- // @match https://trakt.tv/*
- // @grant none
- // ==/UserScript==
- (lst => {
- function bmiaddelClick(a, b, c, d) {
- a = this.closest('[data-show-id],[data-episode-id],[data-movie-id]');
- if (this.classList.contains("del")) { //delete
- delete lst[a.dataset.type + (a.dataset.episodeId || a.dataset.showId || a.dataset.movieId)];
- this.title = "Add to watchlist"
- } else { //add
- b = a.querySelector('.titles-link>*'); //title with optional year
- c = a.querySelector('.titles-link+.titles-link'); //optional episode
- d = a.querySelector('.titles meta[itemprop="datePublished"]'); //optional episode time
- lst[a.dataset.type + (a.dataset.episodeId || a.dataset.showId || a.dataset.movieId)] =
- "[" + (a.dataset.type === "show" ? "TV" : a.dataset.type === "episode" ? "Episode" : "Movie") + "] " + //type
- b.firstChild.data.trim() + (b.firstElementChild ? " (" + b.firstElementChild.textContent.trim() + ")": "") + //title with optional year
- (c ? " (" + c.textContent.trim() + ")": "") + //optional episode & local time
- (d ? " {" + (new Date(d.content.replace(" UTC", "Z"))).toDateString() + "}": "");
- this.title = "Remove from watchlist"
- }
- localStorage.movieInfoList = JSON.stringify(lst);
- this.classList.toggle("del")
- }
- function getData() {
- lst = JSON.parse(localStorage.movieInfoList || "{}");
- document.querySelectorAll(':is([data-show-id],[data-episode-id],[data-movie-id]) .actions').forEach((e, a) => {
- a = e.closest('[data-show-id],[data-episode-id],[data-movie-id]');
- if (!(b = e.querySelector(".bmiaddel"))) {
- e.insertAdjacentHTML("beforeend", '<a class="bmiaddel" title="Add to watchlist">👁</a>');
- (b = e.lastElementChild).onclick = bmiaddelClick
- }
- if (lst[a.dataset.type + (a.dataset.episodeId || a.dataset.showId || a.dataset.movieId)]) {
- b.classList.add("del")
- } else b.classList.remove("del")
- });
- }
- document.querySelector('#top-nav .navbar-nav.brand-right').insertAdjacentHTML("beforeend", `
- <li>
- <style>
- #bmishow { margin-left: 2em; border-radius: .3em }
- .bmiaddel { color: #77d }
- .bmiaddel:hover { background: #335; color: #99f }
- .bmiaddel.del { background: #33b }
- </style>
- <a id="bmishow" href="javascript:void(0)">Watchlist</a>
- </li>`);
- document.querySelector('#bmishow').onclick = (l, a) => {
- if (localStorage.movieInfoList) {
- if (confirm(`Save below movie/show info list?\n\n${l = Object.values(lst).join("\n")}`)) {
- (a = document.createElement("A")).href = URL.createObjectURL(new Blob([l], {type: "text/plain"}));
- a.download = "movieshow-info-list.txt";
- a.click();
- setTimeout(() => URL.revokeObjectURL(a.href), 10000);
- }
- } else alert("Movie/show info list is empty.");
- };
- addEventListener("focus", getData);
- getData()
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement