IMDb to 豆瓣

Adds a link to jump to Douban page using IMDb ID and automatically clicks on the first result. Also adds a link to search Douban for the current movie or show on JustWatch.

  1. // ==UserScript==
  2. // @name IMDb to 豆瓣
  3. // @namespace Violentmonkey Scripts
  4. // @match *://*.imdb.com/title/*
  5. // @match *://movie.douban.com/subject_search?search_text=*
  6. // @match *://www.justwatch.com/*
  7. // @author xuintl
  8. // @license MIT
  9. // @grant none
  10. // @version 1.4
  11. // @description Adds a link to jump to Douban page using IMDb ID and automatically clicks on the first result. Also adds a link to search Douban for the current movie or show on JustWatch.
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to create and insert the Douban button on IMDb
  18. function addDoubanButtonIMDb() {
  19. // Extract the IMDb ID from the URL
  20. const imdbIdMatch = window.location.pathname.match(/title\/(tt\d+)/);
  21. if (imdbIdMatch && imdbIdMatch[1]) {
  22. const imdbId = imdbIdMatch[1];
  23.  
  24. // Construct the Douban URL using the IMDb ID
  25. const doubanUrl = `https://movie.douban.com/subject_search?search_text=${imdbId}&cat=1002`;
  26.  
  27. // Create a new button element
  28. const doubanButton = document.createElement('a');
  29. doubanButton.href = doubanUrl;
  30. doubanButton.textContent = 'Douban';
  31. doubanButton.target = '_blank';
  32. doubanButton.style = 'padding: 2px 6px; background-color: #00a680; color: white; border-radius: 3px; text-decoration: none; font-size: 14px; margin-left: 10px;';
  33.  
  34. // Find the element to insert the button next to (e.g., next to the title)
  35. const titleElement = document.querySelector('h1');
  36.  
  37. // Insert the button into the page
  38. if (titleElement) {
  39. titleElement.parentElement.appendChild(doubanButton);
  40. }
  41. }
  42. }
  43.  
  44. // Function to click the first search result on Douban
  45. function clickFirstResultDouban() {
  46. // Wait for the DOM to fully load
  47. window.addEventListener('load', function() {
  48. // Select the first search result link
  49. const firstResult = document.querySelector('.title a');
  50.  
  51. if (firstResult) {
  52. // Navigate to the first result link
  53. window.location.href = firstResult.href;
  54. }
  55. });
  56. }
  57.  
  58. // Function to create and insert the Douban button on JustWatch
  59. function addDoubanButtonJustWatch() {
  60. // Get the title element from the JustWatch page
  61. const titleElement = document.querySelector('.title-block h1');
  62.  
  63. if (titleElement && !document.querySelector('#doubanButton')) {
  64. // Extract the movie/show title
  65. const title = titleElement.textContent.trim();
  66.  
  67. // Construct the Douban search URL
  68. const doubanSearchUrl = `https://www.douban.com/search?q=${encodeURIComponent(title)}&cat=1002`;
  69.  
  70. // Create a new button element
  71. const doubanButton = document.createElement('a');
  72. doubanButton.href = doubanSearchUrl;
  73. doubanButton.id = 'doubanButton';
  74. doubanButton.textContent = 'Douban';
  75. doubanButton.target = '_blank';
  76. doubanButton.style = 'padding: 2px 6px; background-color: #00a680; color: white; border-radius: 3px; text-decoration: none; font-size: 14px; margin-left: 10px;';
  77.  
  78. // Find the rating info container to insert the button next to the icons
  79. const ratingInfoContainer = document.querySelector('.detail-infos__value .jw-scoring-listing__rating');
  80.  
  81. // Insert the button into the page
  82. if (ratingInfoContainer) {
  83. ratingInfoContainer.parentElement.appendChild(doubanButton);
  84. }
  85. }
  86. }
  87.  
  88. // Create a MutationObserver to watch for changes in the DOM on JustWatch
  89. const observer = new MutationObserver(() => {
  90. addDoubanButtonJustWatch();
  91. });
  92.  
  93. // Start observing the body for changes on JustWatch
  94. observer.observe(document.body, { childList: true, subtree: true });
  95.  
  96. // Initial call to add the button in case the title is already loaded
  97. window.addEventListener('load', addDoubanButtonJustWatch);
  98.  
  99. // Determine if we are on IMDb, Douban, or JustWatch
  100. if (window.location.hostname.includes('imdb.com')) {
  101. // Wait for the DOM to fully load before running the script
  102. window.addEventListener('load', addDoubanButtonIMDb);
  103. } else if (window.location.hostname.includes('douban.com') && window.location.search.includes('search_text=tt')) {
  104. // Only execute on Douban when search_text includes an IMDb ID pattern
  105. clickFirstResultDouban();
  106. } else if (window.location.hostname.includes('justwatch.com')) {
  107. // Start observing the body for changes on JustWatch
  108. observer.observe(document.body, { childList: true, subtree: true });
  109. // Initial call to add the button in case the title is already loaded
  110. window.addEventListener('load', addDoubanButtonJustWatch);
  111. }
  112. })();

QingJ © 2025

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