1111// @match *://*.themoviedb.org/tv/*
1212// @match *://*.themoviedb.org/person/*
1313// @match *://*.letterboxd.com/film/*
14+ // @include /^https?:\/\/(?:www\.)?letterboxd\.com\/(actor|additional-photography|camera-operator|cinematography|composer|costume-design|director|editor|executive-producer|hairstyling|makeup|original-writer|producer|set-decoration|sound|story|visual-effects|writer)\/.*$/
1415// @connect imdb.com
1516// @connect themoviedb.org
1617// @homepageURL https://github.com/Tetrax-10/imdb-tmdb-letterboxd-linker
@@ -868,6 +869,49 @@ html.k-mobile #linker-parent {
868869 }
869870 } )
870871 }
872+
873+ function letterboxdPersonPageInjector ( ) {
874+ commonUtils . waitForElement ( `.micro-button[href^="https://www.themoviedb.org/person/"]` , 10000 ) . then ( async ( element ) => {
875+ try {
876+ // open tmdb link in new tab
877+ element . target = "_blank"
878+
879+ // To make sure other scripts didn't inject imdb link
880+ if ( document . querySelector ( `.micro-button[href^="https://www.imdb.com/name/nm"]` ) ) return
881+
882+ // Fetch TMDB ID
883+ const tmdbId = element . href ?. match ( / \/ p e r s o n \/ ( \d + ) \/ ? / ) ?. [ 1 ] ?? null
884+
885+ if ( tmdbId ) {
886+ // Fetch external IDs
887+ const tmdbRawRes = await fetch ( `https://api.themoviedb.org/3/person/${ tmdbId } ?api_key=${ TMDB_API_KEY } &append_to_response=external_ids` ) . catch ( ( error ) => {
888+ console . error ( "Failed to fetch external IDs from TMDB:" , error )
889+ } )
890+ if ( ! tmdbRawRes ) return
891+
892+ // Extract IMDb ID
893+ const tmdbRes = await tmdbRawRes . json ( )
894+ const imdbId = tmdbRes [ "external_ids" ] [ "imdb_id" ] || null
895+
896+ if ( imdbId && ! document . querySelector ( `.micro-button[href^="https://www.imdb.com/name/nm"]` ) ) {
897+ // create IMDb element
898+ const imdbElement = element . cloneNode ( true )
899+ imdbElement . href = `https://www.imdb.com/name/${ imdbId } `
900+ imdbElement . innerText = "IMDB"
901+ imdbElement . target = "_blank"
902+ imdbElement . setAttribute ( "data-track-action" , "IMDb" )
903+ imdbElement . style . marginRight = "5px"
904+
905+ // inject IMDb element
906+ element . parentElement . insertBefore ( imdbElement , element )
907+ }
908+ }
909+ } catch ( error ) {
910+ console . error ( "Error in letterboxdPersonPageInjector:" , error )
911+ }
912+ } )
913+ }
914+
871915 const currentURL = location . protocol + "//" + location . hostname + location . pathname
872916
873917 if ( / ^ ( h t t p s ? : \/ \/ [ ^ . ] + \. i m d b \. c o m \/ t i t l e \/ t t [ ^ \/ ] + (?: \/ \? .* ) ? \/ ? ) $ / . test ( currentURL ) ) {
@@ -890,5 +934,12 @@ html.k-mobile #linker-parent {
890934 // Letterboxd title page
891935 GM_addStyle ( letterboxdTitlePageCss )
892936 letterboxdTitlePageInjector ( )
937+ } else if (
938+ / ^ ( h t t p s ? : \/ \/ l e t t e r b o x d \. c o m \/ ( a c t o r | a d d i t i o n a l - p h o t o g r a p h y | c a m e r a - o p e r a t o r | c i n e m a t o g r a p h y | c o m p o s e r | c o s t u m e - d e s i g n | d i r e c t o r | e d i t o r | e x e c u t i v e - p r o d u c e r | h a i r s t y l i n g | m a k e u p | o r i g i n a l - w r i t e r | p r o d u c e r | s e t - d e c o r a t i o n | s o u n d | s t o r y | v i s u a l - e f f e c t s | w r i t e r ) \/ [ A - Z a - z 0 - 9 - _ ] + (?: \/ ( b y | l a n g u a g e | c o u n t r y | d e c a d e | g e n r e | o n | y e a r ) \/ [ A - Z a - z 0 - 9 -_ \/ ] + ) ? \/ (?: p a g e \/ \d + \/ ? ) ? ) $ / . test (
939+ currentURL
940+ )
941+ ) {
942+ // Letterboxd person page
943+ letterboxdPersonPageInjector ( )
893944 }
894945} ) ( )
0 commit comments