Skip to content

Commit 3bbf3ee

Browse files
committed
imdb link on letterboxd person page (#3)
1 parent 996c4c7 commit 3bbf3ee

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

linker.user.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
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(/\/person\/(\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 (/^(https?:\/\/[^.]+\.imdb\.com\/title\/tt[^\/]+(?:\/\?.*)?\/?)$/.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+
/^(https?:\/\/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)\/[A-Za-z0-9-_]+(?:\/(by|language|country|decade|genre|on|year)\/[A-Za-z0-9-_\/]+)?\/(?:page\/\d+\/?)?)$/.test(
939+
currentURL
940+
)
941+
) {
942+
// Letterboxd person page
943+
letterboxdPersonPageInjector()
893944
}
894945
})()

0 commit comments

Comments
 (0)