Amazon Prime Video Expiry Viewer

Makes it obvious which and when videos are going to expire.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Amazon Prime Video Expiry Viewer
// @namespace    https://github.com/Kadauchi
// @version      1.0.4
// @description  Makes it obvious which and when videos are going to expire.
// @author       Kadauchi
// @icon         http://i.imgur.com/oGRQwPN.png
// @include      https://www.amazon.com/gp/video*
// @include      https://www.amazon.com/Prime-Video/*
// ==/UserScript==

const checked = {}

function checkShelf () {
  for (const el of document.getElementsByClassName('dv-shelf-item')) checkIfLeaving(el);
  for (const el of document.getElementsByClassName('dv-packshot')) checkIfLeaving(el);
  for (const el of document.getElementsByClassName('UaW15H')) checkIfLeaving(el);
  for (const el of document.getElementsByClassName('UI789i')) checkIfLeaving(el);
}

async function checkIfLeaving (item) {
  const asin = item.querySelector('[data-asin]').dataset.asin;
  const leaving = await fetchHover(asin);

if (leaving.isLeaving) {
    const date = document.createElement('div');
    date.textContent = 'Leaving ' + leaving.isLeaving;
    date.style = 'text-align: center; color: black;';
    date.style.backgroundColor = 'yellow';
    item.appendChild(date);
  }

  if (leaving.isImdb) {
    const date = document.createElement('div');
    date.textContent = 'Available on your IMDb TV channel';
    date.style = 'text-align: center; color: black;';
    date.style.backgroundColor = 'gold';
    item.appendChild(date);
  }
}

function fetchHover (asin) {
  return new Promise(async (resolve) => {
    if (asin && !checked[asin]) {
      const response = await window.fetch(`https://www.amazon.com/gp/video/hover/${asin}?format=json`);
      const text = await response.text();
      // console.log(text);
      const imdb = text.match(/ncluded with your IMDb TV channel/);
      const leaving = text.match(/Leaving Prime on ([\w\s,]+)/);
      const isImdb = !!imdb;
      const isLeaving = leaving ? leaving[1] : false;
      checked[asin] = { isImdb, isLeaving };
      resolve(checked[asin]);
    } else if (checked[asin]) {
      resolve(checked[asin]);
    }
  })
}

checkShelf();