Advertisement
jcunews

imdb-movie-info-list.user.js

Feb 13th, 2023
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        IMDb movie info list
  3. // @namespace   https://greasyfork.org/en/users/85671-jcunews
  4. // @version     1.0.1
  5. // @license     AGPL v3
  6. // @author      jcunews
  7. // @description Context: https://www.reddit.com/r/GreaseMonkey/comments/1113n2w/logging_to_a_document_and_appending_data_from_imdb/
  8. // @match       https://www.imdb.com/title/tt*
  9. // @grant       none
  10. // ==/UserScript==
  11.  
  12. ((inf, lst) => {
  13.   if (inf = document.title.match(/^\s*(.* - )IMDb$/)) {
  14.     inf = inf[1] + location.pathname.match(/\/tt(\d+)/)[1]
  15.   } else inf = "";
  16.   lst = localStorage.movieInfoList ? localStorage.movieInfoList.split("\n") : [];
  17.   document.querySelector('[data-testid="hero-title-block__metadata"]').insertAdjacentHTML("beforeend", `
  18. <style>
  19.   #bmiaddel, #bmishow { margin-left: 2em; border-radius: .3em }
  20.   #bmiaddel { width: 10em; background: #7d7 }
  21.   #bmiaddel:before { content: "Add movie info" }
  22.   #bmiaddel.del { background: #b00; color: #fff }
  23.   #bmiaddel.del:before { content: "Remove movie info" }
  24.   #bmiaddel:disabled { background: revert; color: #bbb }
  25. </style>
  26. <button id="bmiaddel"></button>
  27. <button id="bmishow">Movie info list</button>`);
  28.   if (inf) {
  29.     if (lst.includes(inf)) bmiaddel.className = "del";
  30.   } else bmiaddel.disabled = true;
  31.   bmiaddel.onclick = () => {
  32.     if (bmiaddel.className) { //delete
  33.       bmiaddel.className = "";
  34.       lst.splice(lst.indexOf(inf), 1);
  35.     } else { //add
  36.       bmiaddel.className = "del";
  37.       lst.push(inf);
  38.     }
  39.     localStorage.movieInfoList = lst.join("\n");
  40.   };
  41.   bmishow.onclick = a => {
  42.     if (localStorage.movieInfoList) {
  43.       if (confirm(`Save below movie info list?\n\n${localStorage.movieInfoList}`)) {
  44.         (a = document.createElement("A")).href = URL.createObjectURL(new Blob([localStorage.movieInfoList], {type: "text/plain"}));
  45.         a.download = "movie-info-list.txt";
  46.         a.click();
  47.         setTimeout(() => URL.revokeObjectURL(a.href), 10000);
  48.       }
  49.     } else alert("Movie info list is empty.");
  50.   };
  51. })()
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement