Greasy Fork

Greasy Fork is available in English.

PSA.pm TVmaze API

TVmaze API (https://www.tvmaze.com/api), Icons created by Flat Icons - Flaticon (https://www.flaticon.com/)

当前为 2022-09-17 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name             PSA.pm TVmaze API
// @namespace  [email protected]
// @description   TVmaze API (https://www.tvmaze.com/api), Icons created by Flat Icons - Flaticon (https://www.flaticon.com/)
// @license           CC BY-SA 4.0
// @include          *://psa.pm/tv-show/*
// @include          *://psarips.com/tv-show/*
// @version          1.00
// @grant              GM.openInTab
// @grant              GM.xmlHttpRequest
// @icon                https://psa.pm/wp-content/uploads/2021/10/cropped-PS-ICO-192x192.png
// ==/UserScript==


//Removing duplicate episodes since it breaks script, sorry if you wanted other variants.

window.addEventListener("DOMContentLoaded", function() {
  var var0 = document.querySelectorAll('.sp-head');
  var regex = /(S\d{2}E\d{2}).*\.720p/;
  for(var x = var0.length; x--; x>-1) {
    var check1 = regex.exec(var0[x].textContent);
    var check2 = regex.exec(var0[x-1].textContent);
    if (check1[1] === check2[1]) var0[x].remove();
  }

});

//Adding style

let head = document.getElementsByTagName('head')[0];
    if (head) {
      let style = document.createElement('style');
      style.setAttribute('type', 'text/css');
      style.textContent = "#FemaleCast {font-family: Verdana, sans-serif; font-size: 1.6em; font-variant: small-caps;} #MaleCast {font-family: Verdana, sans-serif; font-size: 1.6em; font-variant: small-caps;}";
      head.appendChild(style);
    }

//XHR

var id = document.querySelector("h1.entry-title").textContent;
var tvmazeAPI = "https://api.tvmaze.com/singlesearch/shows?q=" + encodeURIComponent(id) + "&embed[]=cast&embed[]=episodes";
GM.xmlHttpRequest ({
  method:            'GET',
  url:                      tvmazeAPI,
  responseType: "json",
  onload:               function (response) {

    document.querySelector("h1.entry-title").textContent += " (" + response.response.premiered.slice(0, 4) + ")"; //Adding year

    //Adding containers for the response data

    document.querySelector("h1.entry-title").insertAdjacentHTML('afterbegin', '<a id="dayLink" href="" target="_blank"><img id="dayImg" style="max-height:51.2px;" src=""></a>&nbsp;&nbsp;');
    document.querySelector("h1.entry-title").insertAdjacentHTML('afterend', '<span id="FemaleCast"></span><br><br><span id="MaleCast"></span>');

          switch (response.response.schedule.days[0]) { //Get the day and set the icon
            case "Sunday":
              document.getElementById("dayLink").setAttribute("href", "https://www.flaticon.com/free-icons/sunday");
              document.getElementById("dayImg").setAttribute("src", "https://cdn-icons-png.flaticon.com/512/5776/5776782.png");
              break;
            case "Monday":
              document.getElementById("dayLink").setAttribute("href", "https://www.flaticon.com/free-icons/monday");
              document.getElementById("dayImg").setAttribute("src", "https://cdn-icons-png.flaticon.com/512/5776/5776609.png");
              break;
            case "Tuesday":
              document.getElementById("dayLink").setAttribute("href", "https://www.flaticon.com/free-icons/tuesday");
              document.getElementById("dayImg").setAttribute("src", "https://cdn-icons-png.flaticon.com/512/5776/5776837.png");
              break;
            case "Wednesday":
              document.getElementById("dayLink").setAttribute("href", "https://www.flaticon.com/free-icons/wednesday");
              document.getElementById("dayImg").setAttribute("src", "https://cdn-icons-png.flaticon.com/512/5776/5776852.png");
              break;
            case "Thursday":
              document.getElementById("dayLink").setAttribute("href", "https://www.flaticon.com/free-icons/thursday");
              document.getElementById("dayImg").setAttribute("src", "https://cdn-icons-png.flaticon.com/512/5776/5776798.png");
              break;
            case "Friday":
              document.getElementById("dayLink").setAttribute("href", "https://www.flaticon.com/free-icons/friday");
              document.getElementById("dayImg").setAttribute("src", "https://cdn-icons-png.flaticon.com/512/5776/5776451.png");
              break;
            case "Saturday":
              document.getElementById("dayLink").setAttribute("href", "https://www.flaticon.com/free-icons/saturday");
              document.getElementById("dayImg").setAttribute("src", "https://cdn-icons-png.flaticon.com/512/5776/5776750.png");
              break;
            default:
              document.getElementById("dayLink").setAttribute("href", "");
              document.getElementById("dayImg").setAttribute("src", "");
          }
    
    //Segregate by gender
    
    const Female = response.response._embedded.cast.filter(actress => actress.person.gender === "Female"); //Ladies first! (*^_^*)
    document.getElementById("FemaleCast").innerHTML = "Female Cast: " + "<a href='" + Female[0].person.url + "' target='_blank'>" + Female[0].person.name + "</a>" + ", " + "<a href='" + Female[1].person.url + "' target='_blank'>" + Female[1].person.name + "</a>" + ", " + "<a href='" + Female[2].person.url + "' target='_blank'>" + Female[2].person.name + "</a>" + ".";
    const Male = response.response._embedded.cast.filter(actor => actor.person.gender === "Male");
    document.getElementById("MaleCast").innerHTML = "Male Cast: " + "<a href='" + Male[0].person.url + "' target='_blank'>" + Male[0].person.name + "</a>" + ", " + "<a href='" + Male[1].person.url + "' target='_blank'>" + Male[1].person.name + "</a>" + ", " + "<a href='" + Male[2].person.url + "' target='_blank'>" + Male[2].person.name + "</a>" + ".";
    document.getElementById("wpd-post-rating").insertAdjacentHTML('afterend', response.response.summary); //Adding show summary

    var var1 = document.querySelectorAll('.sp-head');
    var j = 0;
    for(var i = var1.length; i--; i>-1) { //Adding episode names and summaries
      if (/E\d{2}.*\.720p/.test(var1[i].textContent)) { //Ignores TV-PACKS
        var s = /S(\d{2})/.exec(var1[i].textContent); //Gets the season number
        if (parseInt(s[1], 10) === response.response._embedded.episodes[j].season) { //Checks if the season number matches
          if (/E\d{2}E\d{2}/.test(var1[i].textContent)) { //Double episodes
            var1[i].insertAdjacentHTML('beforeend', '<br>' + response.response._embedded.episodes[j].name + ': ' + response.response._embedded.episodes[j].summary + '<br>' + response.response._embedded.episodes[j+1].name + ': ' + response.response._embedded.episodes[j+1].summary);
            j = j+2;
          } else {
            var1[i].insertAdjacentHTML('beforeend', '<br>' + response.response._embedded.episodes[j].name + ': ' + response.response._embedded.episodes[j].summary);
            j++;
          }
        } else { j++; i++; }
      }
    }
    console.log (
      "GM.xmlHttpRequest() response is:\n",
      response.response
    );
  }
});

// TVmaze API Button

var node1 = document.createElement("div");
node1.setAttribute("style","position: fixed;" +
                                      "bottom: 0;" +
                                      "left: 28px;" +
                                      "cursor: pointer;" +
                                      "border: 1px solid #313131;" +
                                      "border-top-left-radius: 5px;" +
                                      "background: #101000;" +
                                      "padding: 7px 15px;" +
                                      "z-index: 999999;");
node1.setAttribute("title", "Click here to open API");
node1.innerHTML = "<img src='https://static.tvmaze.com/images/api/tvm_api.png' style='max-height:4vh;'><img src='https://licensebuttons.net/l/by-sa/4.0/80x15.png' style='display: block;margin-left: auto;margin-right: auto;'>";
node1.id = "api";
document.body.appendChild(node1);

document.getElementById("api").addEventListener('click', function() { GM.openInTab("https://www.tvmaze.com/api#licensing", false); }, false);