IMDb you may know them from (Multi-Language)

Adds a collapsible section with your rated movies per actor, auto-detected in 7 languages

  1. // ==UserScript==
  2. // @name IMDb you may know them from (Multi-Language)
  3. // @match https://www.imdb.com/name/*
  4. // @match https://www.imdb.com/*/name/*
  5. // @description Adds a collapsible section with your rated movies per actor, auto-detected in 7 languages
  6. // @grant none
  7. // @version 3.0.1
  8. // @license MIT
  9. // @namespace https://greasyfork.org/users/1218651
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. // 1. LANGUAGE CONFIGURATION
  14. const translations = {
  15. en: 'You may know them from (click to expand/collapse)',
  16. fr: 'Vous les connaissez peut-être grâce à (cliquer pour agrandir/réduire)',
  17. de: 'Vielleicht kennen Sie sie aus (klicken zum Aufklappen/Zuklappen)',
  18. hi: 'आप उन्हें इनसे जानते होंगे (विस्तार/संक्षिप्त करने के लिए क्लिक करें)',
  19. it: 'Forse li conosci da (clicca per espandere/collassare)',
  20. pt_BR: 'Talvez você os conheça de (clique para expandir/recolher)',
  21. pt_PT: 'Talvez os conheça de (clique para expandir/recolher)',
  22. es: 'Puede que los conozca de (haga clic para ampliar/contraer)'
  23. };
  24.  
  25. const langMap = {
  26. // French
  27. 'fr': 'fr', 'fr-fr': 'fr', 'fr-ca': 'fr',
  28. // German
  29. 'de': 'de', 'de-de': 'de', 'de-at': 'de',
  30. // Hindi
  31. 'hi': 'hi', 'hi-in': 'hi',
  32. // Italian
  33. 'it': 'it', 'it-it': 'it',
  34. // Portuguese
  35. 'pt': 'pt_BR', 'pt-br': 'pt_BR', 'pt-pt': 'pt_PT',
  36. // Spanish
  37. 'es': 'es', 'es-es': 'es', 'es-mx': 'es', 'es-ar': 'es'
  38. };
  39.  
  40. // 2. IMPROVED LANGUAGE DETECTION (unchanged)
  41. const detectLanguage = () => {
  42. const urlPath = window.location.pathname;
  43. const isNeutralUrl = !urlPath.match(/^\/[a-z]{2}(?:-[a-z]{2})?\//);
  44.  
  45. if (isNeutralUrl) return 'en';
  46.  
  47. const urlLang = (urlPath.match(/^\/([a-z]{2}(?:-[a-z]{2})?)\//i) || [])[1];
  48. if (urlLang) {
  49. if (['en', 'en-us', 'en-gb', 'en-ca'].includes(urlLang.toLowerCase())) {
  50. return 'en';
  51. }
  52. if (langMap[urlLang.toLowerCase()]) {
  53. return langMap[urlLang.toLowerCase()];
  54. }
  55. }
  56.  
  57. const browserLang = (navigator.language || navigator.userLanguage || 'en').toLowerCase();
  58. if (['en', 'en-us', 'en-gb', 'en-ca'].some(code => browserLang.startsWith(code))) {
  59. return 'en';
  60. }
  61. for (const [imdbCode, langCode] of Object.entries(langMap)) {
  62. if (browserLang.startsWith(imdbCode)) {
  63. return langCode;
  64. }
  65. }
  66.  
  67. return 'en';
  68. };
  69.  
  70. // 3. MAIN SCRIPT WITH ADDITIONAL ELEMENT REMOVAL
  71. var actorId = window.location.href.match(/\/name\/(nm\d+)/)[1];
  72. var container = document.createElement('div');
  73. container.style.clear = 'both';
  74.  
  75. const language = detectLanguage();
  76. var header = document.createElement('h3');
  77. header.textContent = translations[language] || translations.en;
  78. header.style.cursor = 'pointer';
  79. header.style.color = '#0E63BE';
  80.  
  81. var iframe = document.createElement('iframe');
  82. iframe.src = 'https://www.imdb.com/filmosearch/?role=' + actorId + '&mode=simple&my_ratings=restrict';
  83. iframe.style.width = '100%';
  84. iframe.style.height = '500px';
  85. iframe.style.display = 'none';
  86.  
  87. iframe.onload = function () {
  88. // Updated list of elements to remove (added your new request)
  89. var elementsToRemove = [
  90. '#imdbHeader',
  91. 'ul.ipc-tabs.ipc-tabs--base.ipc-tabs--align-left.sc-6736dd52-2.gRVa-dQ.tabs',
  92. 'div.sc-e3ac1175-5.eKfFfl',
  93. '.ipc-title.ipc-title--base.ipc-title--page-title.ipc-title--on-textPrimary',
  94. '.ipc-page-background.ipc-page-background--baseAlt.sc-8cf8f1-1.kdGFti',
  95. 'footer.imdb-footer',
  96. 'div.sc-7f8be4ff-0.ckODVo.recently-viewed.celwidget',
  97. '.ipc-page-section.ipc-page-section--none.recently-viewed-items' // New element to remove
  98. ];
  99.  
  100. elementsToRemove.forEach(selector => {
  101. var elements = iframe.contentDocument.querySelectorAll(selector);
  102. elements.forEach(element => {
  103. if (element && element.parentNode) {
  104. element.parentNode.removeChild(element);
  105. }
  106. });
  107. });
  108.  
  109. // Modify links
  110. var links = iframe.contentDocument.querySelectorAll('a');
  111. links.forEach(link => link.setAttribute('target', '_top'));
  112. };
  113.  
  114. container.appendChild(header);
  115. container.appendChild(iframe);
  116. var targetElement = document.querySelector('div.ipc-chip-list--base');
  117.  
  118. if (targetElement) {
  119. targetElement.parentNode.insertBefore(container, targetElement);
  120. header.addEventListener('click', function () {
  121. iframe.style.display = iframe.style.display === 'none' ? 'block' : 'none';
  122. });
  123. } else {
  124. console.log('Target element not found on this page');
  125. }
  126. })();