IMDb you may know them from

Adds a frame with movies I have already seen

当前为 2024-11-26 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         IMDb you may know them from
// @match        https://www.imdb.com/name/*
// @match        https://www.imdb.com/*/name/*
// @description  Adds a frame with movies I have already seen
// @grant        none
// @version      2.0.3
// @license      MIT
// @namespace https://greasyfork.org/users/1218651
// ==/UserScript==
 
(function () {
  var actorId = window.location.href.match(/\/name\/(nm\d+)/)[1];
 
  var container = document.createElement('div');
  container.style.clear = 'both';
 
  var header = document.createElement('h3');
  header.innerHTML = 'You may know them from (click to expand/collapse)';
  header.style.cursor = 'pointer';
  header.style.color = '#0E63BE'; // Imposta il colore dell'intestazione utilizzando il valore esadecimale
 
  var iframe = document.createElement('iframe');
  iframe.src = 'https://www.imdb.com/filmosearch/?role=' + actorId + '&mode=simple&my_ratings=restrict';
  iframe.style.width = '100%';
  iframe.style.height = '500px';
  iframe.style.display = 'none'; // Nasconde inizialmente il frame
 
  // Aggiungi un evento onload all'iframe per modificare i link al suo interno
  iframe.onload = function () {
    // Rimuovi completamente l'elemento con id "imdbHeader" dal frame
    var imdbHeader = iframe.contentDocument.getElementById('imdbHeader');
    if (imdbHeader) {
      imdbHeader.parentNode.removeChild(imdbHeader);
    }
 
    // Rimuovi completamente l'elemento <ul> con la classe specificata dal frame
    var ipcTabs = iframe.contentDocument.querySelector('ul.ipc-tabs.ipc-tabs--base.ipc-tabs--align-left.sc-6736dd52-2.gRVa-dQ.tabs');
    if (ipcTabs) {
      ipcTabs.parentNode.removeChild(ipcTabs);
    }
 
    // Rimuovi completamente l'elemento <div> con la classe specificata dal frame
    var divToRemove = iframe.contentDocument.querySelector('div.sc-e3ac1175-5.eKfFfl');
    if (divToRemove) {
      divToRemove.parentNode.removeChild(divToRemove);
    }
 
    // Rimuovi completamente gli elementi con la classe specificata dal frame
    var elementsToRemove = iframe.contentDocument.querySelectorAll('.ipc-title.ipc-title--base.ipc-title--page-title.ipc-title--on-textPrimary');
    elementsToRemove.forEach(function (element) {
      element.parentNode.removeChild(element);
    });
 
    // Rimuovi completamente gli elementi con la classe specificata dal frame
    var pageBackground = iframe.contentDocument.querySelectorAll('.ipc-page-background.ipc-page-background--baseAlt.sc-8cf8f1-1.kdGFti');
    pageBackground.forEach(function (element) {
      element.parentNode.removeChild(element);
    });
 
    // Rimuovi completamente l'elemento footer con classe "imdb-footer" dal frame
    var imdbFooter = iframe.contentDocument.querySelector('footer.imdb-footer');
    if (imdbFooter) {
      imdbFooter.parentNode.removeChild(imdbFooter);
    }
 
    // Rimuovi completamente l'elemento <div> con la classe specificata dal frame
    var recentlyViewed = iframe.contentDocument.querySelector('div.sc-7f8be4ff-0.ckODVo.recently-viewed.celwidget');
    if (recentlyViewed) {
      recentlyViewed.parentNode.removeChild(recentlyViewed);
    }
 
    // Modifica i link all'interno del frame
    var linksInIframe = iframe.contentDocument.querySelectorAll('a');
    linksInIframe.forEach(function (link) {
      link.setAttribute('target', '_top'); // Imposta il target dei link nell'iframe su "_top"
    });
  };
 
  container.appendChild(header);
  container.appendChild(iframe);
  var targetElement = document.querySelector('div.ipc-chip-list--base');
 
  //var targetElement = document.querySelector('div.ipc-chip-list__scroller');
  // Controlla se l'elemento di destinazione esiste prima di inserire l'iframe
  if (targetElement) {
    targetElement.parentNode.insertBefore(container, targetElement);
 
    header.addEventListener('click', function () {
      if (iframe.style.display === 'none') {
        iframe.style.display = 'block'; // Mostra il frame quando si clicca sull'intestazione
      } else {
        iframe.style.display = 'none'; // Nasconde il frame quando si clicca sull'intestazione di nuovo
      }
    });
  } else {
    // Se l'elemento previsto non esiste, puoi scegliere un modo alternativo per inserire l'iframe o gestire il caso di conseguenza.
    console.log('L\'elemento previsto non esiste su questa pagina.');
  }
})();