Greasy Fork is available in English.

Amazon Video ASIN Display

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

  1. // ==UserScript==
  2. // @name Amazon Video ASIN Display
  3. // @namespace nyuszika7h@gmail.com
  4. // @version 0.2.4
  5. // @description Show ASINs for episodes and movies/seasons on Amazon Prime Video
  6. // @author nyuszika7h
  7. // @match https://www.amazon.com/*
  8. // @match https://www.amazon.co.uk/*
  9. // @match https://www.amazon.de/*
  10. // @match https://www.amazon.co.jp/*
  11. // @match https://www.primevideo.com/*
  12. // @run-at document-idle
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. let style = document.createElement('style');
  20. let styleText = document.createTextNode(`
  21. .x-episode-asin {
  22. margin: 0.5em 0;
  23. color: #ff0000;
  24. }
  25.  
  26. .x-page-asin {
  27. margin: 0.5em 0 1em 0;
  28. color: #ff0000;
  29. }`);
  30. style.appendChild(styleText);
  31. document.head.appendChild(style);
  32.  
  33. function addTitleAsin() {
  34. // Movie/series ASIN
  35. let asin = document.querySelector('body').innerHTML.match(/pageTypeId: "([^"]+)"/)[1];
  36.  
  37. let asinEl = document.createElement('div');
  38. let text = document.createTextNode(asin);
  39. asinEl.className = 'x-page-asin';
  40. asinEl.appendChild(text);
  41.  
  42. let after = document.querySelector('.dv-dp-node-synopsis, .av-synopsis');
  43. after.parentNode.insertBefore(asinEl, after.nextSibling);
  44. }
  45.  
  46. function addEpisodeAsins() {
  47. // Episode ASINs
  48. document.querySelectorAll('.js-node-episode-container > input, .avu-context-card > input').forEach(el => {
  49. const parent = el.parentNode;
  50.  
  51. if (parent.querySelector('.x-episode-asin')) {
  52. // Already added ASIN
  53. return;
  54. }
  55.  
  56. debugger;
  57.  
  58. let id = el.id.replace(/^(?:selector|av-episode-expand-toggle)-/, '');
  59. var re = new RegExp(id + '"[^ <>]*"catalogId":"([^"]+)"');
  60. let asin = document.querySelector('body').innerHTML.match(re)[1];
  61.  
  62. let asinEl = document.createElement('div');
  63. let text = document.createTextNode(id + " " + asin);
  64. asinEl.className = 'x-episode-asin';
  65. asinEl.appendChild(text);
  66.  
  67. parent.querySelector('.js-eplist-episode, .av-episode-playback, .js-ep-playback-wrapper').appendChild(asinEl);
  68. });
  69. }
  70.  
  71. addTitleAsin();
  72. addEpisodeAsins();
  73.  
  74. /*const epExpander = document.querySelector('[data-automation-id="ep-expander"]');
  75. if (epExpander) {
  76. epExpander.addEventListener('click', function () {
  77. setTimeout(addEpisodeAsins, 1000);
  78. });
  79. }*/
  80.  
  81. new MutationObserver(function (mutationsList, observer) {
  82. for (const mutation of mutationsList) {
  83. addEpisodeAsins();
  84. }
  85. }).observe(document.querySelector('.DVWebNode-detail-btf-wrapper'), { childList: true, subtree: true });
  86. }());