Amazon Video ASIN Display

Show ASINs for episodes and movies/seasons on Amazon Prime Video

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Amazon Video ASIN Display
// @namespace    [email protected]
// @version      0.2.4
// @description  Show ASINs for episodes and movies/seasons on Amazon Prime Video
// @author       nyuszika7h
// @match        https://www.amazon.com/*
// @match        https://www.amazon.co.uk/*
// @match        https://www.amazon.de/*
// @match        https://www.amazon.co.jp/*
// @match        https://www.primevideo.com/*
// @run-at       document-idle
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  let style = document.createElement('style');
  let styleText = document.createTextNode(`
.x-episode-asin {
  margin: 0.5em 0;
  color: #ff0000;
}

.x-page-asin {
  margin: 0.5em 0 1em 0;
  color: #ff0000;
}`);
  style.appendChild(styleText);
  document.head.appendChild(style);

  function addTitleAsin() {
    // Movie/series ASIN
      let id = document.querySelector('body').innerHTML.match(/pageTypeId: "([^"]+)"/)[1];

      var re = new RegExp(id + '"[^ <>]*"catalogId":"([^"]+)"');
      let asin = document.querySelector('body').innerHTML.match(re)[1];

      let asinEl = document.createElement('div');
      let text = document.createTextNode(asin);
      asinEl.className = 'x-page-asin';
      asinEl.appendChild(text);

      let after = document.querySelector('.dv-dp-node-synopsis, .av-synopsis');
      after.parentNode.insertBefore(asinEl, after.nextSibling);
  }

  function addEpisodeAsins() {
    // Episode ASINs
    document.querySelectorAll('.js-node-episode-container > input, .avu-context-card > input').forEach(el => {
      const parent = el.parentNode;

      if (parent.querySelector('.x-episode-asin')) {
        // Already added ASIN
        return;
      }

        debugger;

      let id = el.id.replace(/^(?:selector|av-episode-expand-toggle)-/, '');
      var re = new RegExp(id + '"[^ <>]*"catalogId":"([^"]+)"');
      let asin = document.querySelector('body').innerHTML.match(re)[1];

      let asinEl = document.createElement('div');
      let text = document.createTextNode(id + " " + asin);
      asinEl.className = 'x-episode-asin';
      asinEl.appendChild(text);

      parent.querySelector('.js-eplist-episode, .av-episode-playback, .js-ep-playback-wrapper').appendChild(asinEl);
    });
  }

  addTitleAsin();
  addEpisodeAsins();

  /*const epExpander = document.querySelector('[data-automation-id="ep-expander"]');
  if (epExpander) {
    epExpander.addEventListener('click', function () {
      setTimeout(addEpisodeAsins, 1000);
    });
  }*/

  new MutationObserver(function (mutationsList, observer) {
    for (const mutation of mutationsList) {
      addEpisodeAsins();
    }
  }).observe(document.querySelector('.DVWebNode-detail-btf-wrapper'), { childList: true, subtree: true });
}());