IMDb you may know them from

Adds a frame with movies I have already seen

目前为 2024-01-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name IMDb you may know them from
  3. // @match https://www.imdb.com/name/*
  4. // @description Adds a frame with movies I have already seen
  5. // @grant none
  6. // @version 1.0.3
  7. // @license MIT
  8. // @namespace https://greasyfork.org/users/1218651
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. var actorId = window.location.href.match(/\/name\/(nm\d+)/)[1];
  13.  
  14. var container = document.createElement('div');
  15. container.style.clear = 'both';
  16.  
  17. var header = document.createElement('h3');
  18. header.innerHTML = 'You may know them from (click to expand/collapse)';
  19. header.style.cursor = 'pointer';
  20. header.style.color = '#0E63BE'; // Sets the header color using the hexadecimal value
  21.  
  22. var iframe = document.createElement('iframe');
  23. iframe.src = 'https://www.imdb.com/filmosearch/?role=' + actorId + '&mode=simple&my_ratings=restrict';
  24. iframe.style.width = '100%';
  25. iframe.style.height = '500px';
  26. iframe.style.display = 'none'; // Hides the frame initially
  27.  
  28.  
  29. // Add an onload event to the iframe to modify links within it
  30. iframe.onload = function () {
  31. var linksInIframe = iframe.contentDocument.querySelectorAll('a');
  32. linksInIframe.forEach(function (link) {
  33. link.setAttribute('target', '_top'); // Sets the target of links in the iframe to "_top"
  34. });
  35. };
  36.  
  37. container.appendChild(header);
  38. container.appendChild(iframe);
  39. var targetElement = document.querySelector('div.ipc-chip-list--base');
  40.  
  41. //var targetElement = document.querySelector('div.ipc-chip-list__scroller');
  42. // Check if the target element exists before inserting the iframe
  43. if (targetElement) {
  44. targetElement.parentNode.insertBefore(container, targetElement);
  45.  
  46. header.addEventListener('click', function () {
  47. if (iframe.style.display === 'none') {
  48. iframe.style.display = 'block'; // Shows the frame when clicking the header
  49. } else {
  50. iframe.style.display = 'none'; // Hides the frame when clicking the header again
  51. }
  52. });
  53. } else {
  54. // If the expected element doesn't exist, you can choose an alternative way to insert the iframe or handle the case accordingly.
  55. console.log('The expected element does not exist on this page.');
  56. }
  57. })();