Skip to content

Commit

Permalink
Handle the case when the movie already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Morea committed Sep 26, 2023
1 parent 6755301 commit cd7b709
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions PTP - Add IMDB Cover/PTP - Add IMDB Cover.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ await (async function () {
);

if (result.querySelector(".media_index_thumb_list") !== null) {
resolve(await insertCoverAlternative());
resolve(await insertCoverAlternative(imdbId));
}
let imageElement = result
.querySelector(".subpage_title_block")
Expand Down Expand Up @@ -172,11 +172,8 @@ await (async function () {
});
};

const insertCoverAlternative = async () => {
let value = document.querySelector("#imdb").value;
if (value.startsWith("http"))
value = "tt" + value.split("/tt")[1].split("/")[0];
let url = "https://www.imdb.com/title/" + value + "/mediaindex";
const insertCoverAlternative = async (imdbId) => {
let url = "https://www.imdb.com/title/" + imdbId + "/mediaindex";
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: url,
Expand Down Expand Up @@ -300,13 +297,13 @@ await (async function () {
document.querySelector("#autofill").addEventListener("click", async () => {
try {
let apiToken = await getPtpImgApiKey();
let value = document.querySelector("#imdb").value;
if (value.startsWith("http"))
value = "tt" + value.split("/tt")[1].split("/")[0];
let url = await fetchCover(value);
let imdbId = document.querySelector("#imdb").value;
if (imdbId.startsWith("http"))
imdbId = "tt" + imdbId.split("/tt")[1].split("/")[0];
let url = await fetchCover(imdbId);
console.log(url);
if (!url || (await isSmall(url))) {
url = await fetchCoverFromMainPage(value);
url = await fetchCoverFromMainPage(imdbId);
}
coverInput.value = await uploadToPtpimg(url, apiToken);
coverInput.dispatchEvent(new Event("change"));
Expand Down

0 comments on commit cd7b709

Please sign in to comment.