Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name IMDb movie 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/1113n2w/logging_to_a_document_and_appending_data_from_imdb/
- // @match https://www.imdb.com/title/tt*
- // @grant none
- // ==/UserScript==
- ((inf, lst) => {
- if (inf = document.title.match(/^\s*(.* - )IMDb$/)) {
- inf = inf[1] + location.pathname.match(/\/tt(\d+)/)[1]
- } else inf = "";
- lst = localStorage.movieInfoList ? localStorage.movieInfoList.split("\n") : [];
- document.querySelector('[data-testid="hero-title-block__metadata"]').insertAdjacentHTML("beforeend", `
- <style>
- #bmiaddel, #bmishow { margin-left: 2em; border-radius: .3em }
- #bmiaddel { width: 10em; background: #7d7 }
- #bmiaddel:before { content: "Add movie info" }
- #bmiaddel.del { background: #b00; color: #fff }
- #bmiaddel.del:before { content: "Remove movie info" }
- #bmiaddel:disabled { background: revert; color: #bbb }
- </style>
- <button id="bmiaddel"></button>
- <button id="bmishow">Movie info list</button>`);
- if (inf) {
- if (lst.includes(inf)) bmiaddel.className = "del";
- } else bmiaddel.disabled = true;
- bmiaddel.onclick = () => {
- if (bmiaddel.className) { //delete
- bmiaddel.className = "";
- lst.splice(lst.indexOf(inf), 1);
- } else { //add
- bmiaddel.className = "del";
- lst.push(inf);
- }
- localStorage.movieInfoList = lst.join("\n");
- };
- bmishow.onclick = a => {
- if (localStorage.movieInfoList) {
- if (confirm(`Save below movie info list?\n\n${localStorage.movieInfoList}`)) {
- (a = document.createElement("A")).href = URL.createObjectURL(new Blob([localStorage.movieInfoList], {type: "text/plain"}));
- a.download = "movie-info-list.txt";
- a.click();
- setTimeout(() => URL.revokeObjectURL(a.href), 10000);
- }
- } else alert("Movie info list is empty.");
- };
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement