Amazon Video ASIN Display

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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 asin = document.querySelector('body').innerHTML.match(/pageTypeId: "([^"]+)"/)[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 });
}());