Netflix Interactive Selection Tracker

Logs every option selected during interactive content

  1. // ==UserScript==
  2. // @name Netflix Interactive Selection Tracker
  3. // @namespace https://github.com/lmelvin
  4. // @version 1.1
  5. // @license MIT
  6. // @description Logs every option selected during interactive content
  7. // @author lmelvin
  8. // @match https://www.netflix.com/watch/*
  9. // @grant GM_addStyle
  10. // @require https://cdn.jsdelivr.net/npm/file-saver@2.0.0/dist/FileSaver.min.js
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. let DOWNLOAD_MENU = `<li class='dm list-header'>Interactive Selection Tracker</li>
  17. <li class='dm download track'>Download</li>`;
  18. let DM_HEADER_SELECTOR = '.dm.header';
  19. let DM_DOWNLOAD_SELECTOR = '.dm.download';
  20.  
  21. let observerConfig = { attributes: true, childList: true, subtree: true };
  22. let currentLog;
  23.  
  24. GM_addStyle(`.dm { white-space: nowrap; padding-right: 5px; }
  25. ${DM_HEADER_SELECTOR} { font-weight: bold; }
  26. ${DM_DOWNLOAD_SELECTOR} { cursor: pointer }`);
  27.  
  28. var observerCallback = function (mutations, observer) {
  29. for (var mutation of mutations) {
  30. buildDownloadMenu(mutation);
  31. if (mutation.isSelectionMutation()) {
  32. appendToCurrentLog(mutation.getSelectedValue());
  33. break;
  34. }
  35. }
  36. };
  37.  
  38. let observer = new MutationObserver(observerCallback);
  39. observer.observe(document.body, observerConfig);
  40.  
  41. function buildDownloadMenu(mutation) {
  42. for (var node of mutation.addedNodes) {
  43. let trackMenu = (node.parentNode || node).querySelector('.audio-subtitle-controller');
  44. if (trackMenu !== null && trackMenu.querySelector('.subtitle-downloader-menu') === null) {
  45. let ul = document.createElement('ul');
  46. ul.setAttribute('class', 'track-list');
  47. ul.innerHTML = DOWNLOAD_MENU;
  48. trackMenu.appendChild(ul);
  49. ul.querySelector(DM_DOWNLOAD_SELECTOR).addEventListener('click', download);
  50. }
  51. }
  52. }
  53.  
  54. function appendToCurrentLog(value) {
  55. currentLog = (currentLog ? currentLog + `\n` : '') + value;
  56. console.log(currentLog);
  57. }
  58.  
  59. function download() {
  60. var blob = new Blob([currentLog], { type: "text/plain;charset=utf-8" });
  61. saveAs(blob, `${getTitle()}_selections.txt`);
  62. }
  63.  
  64. function getTitle() {
  65. let titleElement = document.querySelector('h4.ellipsize-text');
  66. let title = titleElement.textContent;
  67. title = title ? title.replace(/[:*?"<>|\\\/]+/g, '_').replace(/ /g, '.') : 'selection_tracker';
  68. return title;
  69. }
  70.  
  71. MutationRecord.prototype.isSelectionMutation = function () {
  72. return this.type == 'attributes'
  73. && this.target.classList.contains('BranchingInteractiveScene--choice-selection')
  74. && this.target.classList.contains('selected');
  75. }
  76.  
  77. MutationRecord.prototype.getSelectedValue = function () {
  78. return this.target.getAttribute("aria-label");
  79. }
  80. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址