33// @description Opens the corresponding IMDb, TMDB, or Letterboxd page for movies, TV shows and people with a single click. Additionally, it also displays IMDb ratings on both TMDB and Letterboxd pages.
44// @author Tetrax-10
55// @namespace https://github.com/Tetrax-10/imdb-tmdb-letterboxd-linker
6- // @version 2.4
6+ // @version 2.5
77// @license MIT
88// @match *://*.imdb.com/title/tt*
99// @match *://*.imdb.com/name/nm*
@@ -454,13 +454,16 @@ html.k-mobile #linker-parent {
454454 const dividerElement = commonUtils . element . createDividerElement ( )
455455 const loadingElement = commonUtils . element . createLoadingElement ( )
456456
457- const rootElementSelector = 'section.ipc-page-section[data-testid="hero-parent"] > div:nth-child(2) > div:nth-child(2) > div'
457+ const mobileSelector = 'section.ipc-page-section[data-testid="hero-parent"] > div:nth-child(3) > div:nth-child(2) > div:nth-child(2) > div > div'
458+ const desktopSelector = 'section.ipc-page-section[data-testid="hero-parent"] > div:nth-child(2) > div:nth-child(2) > div'
459+
460+ const rootElementSelector = isMobile ? mobileSelector : desktopSelector
458461
459462 window . addEventListener ( "load" , ( ) => {
460463 try {
461- commonUtils . waitForElement ( rootElementSelector , 10000 , isMobile ? 2 : 1 ) . then ( ( element ) => {
464+ commonUtils . waitForElement ( rootElementSelector , 10000 ) . then ( ( element ) => {
462465 element . insertBefore ( parentContainer , element . firstChild )
463- imdbPageUtils . element . mirrorElements ( parentContainer , isMobile , rootElementSelector )
466+ imdbPageUtils . element . mirrorElements ( parentContainer , true , isMobile ? desktopSelector : mobileSelector )
464467
465468 parentContainer . appendChild ( letterboxdElement )
466469 parentContainer . appendChild ( dividerElement )
@@ -475,13 +478,13 @@ html.k-mobile #linker-parent {
475478 // inject parent element if not present
476479 function injectParentElement ( ) {
477480 try {
478- if ( ! document . querySelectorAll ( "#linker-parent" ) [ isMobile ? 2 : 1 ] ) {
479- commonUtils . waitForElement ( rootElementSelector , 10000 , isMobile ? 2 : 1 ) . then ( ( element ) => {
481+ if ( ! document . querySelectorAll ( "#linker-parent" ) [ isMobile ? 1 : 0 ] ) {
482+ commonUtils . waitForElement ( rootElementSelector , 10000 ) . then ( ( element ) => {
480483 element . insertBefore ( parentContainer , element . firstChild )
481484 } )
482485 }
483- if ( ! document . querySelectorAll ( "#linker-parent" ) [ ! isMobile ? 2 : 1 ] ) {
484- imdbPageUtils . element . mirrorElements ( parentContainer , isMobile , rootElementSelector )
486+ if ( ! document . querySelectorAll ( "#linker-parent" ) [ isMobile ? 0 : 1 ] ) {
487+ imdbPageUtils . element . mirrorElements ( parentContainer , true , isMobile ? desktopSelector : mobileSelector )
485488 }
486489 } catch ( error ) {
487490 console . error ( "Failed to inject parent element" , error )
@@ -555,12 +558,12 @@ html.k-mobile #linker-parent {
555558 // inject parent element if not present
556559 function injectParentElement ( ) {
557560 try {
558- if ( ! document . querySelector ( "#linker-parent" ) ) {
561+ if ( ! document . querySelectorAll ( "#linker-parent" ) [ isMobile ? 1 : 0 ] ) {
559562 commonUtils . waitForElement ( rootElementSelector , 10000 , isMobile ? 2 : 1 ) . then ( ( element ) => {
560563 element . insertBefore ( parentContainer , element . firstChild )
561564 } )
562565 }
563- if ( ! document . querySelectorAll ( "#linker-parent" ) [ ! isMobile ? 2 : 1 ] ) {
566+ if ( ! document . querySelectorAll ( "#linker-parent" ) [ isMobile ? 0 : 1 ] ) {
564567 imdbPageUtils . element . mirrorElements ( parentContainer , isMobile , rootElementSelector )
565568 }
566569 } catch ( error ) {
0 commit comments