Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AnimeciX): Add new presence #9272

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Conversation

iSwesia
Copy link

@iSwesia iSwesia commented Feb 11, 2025

Description

Feature: Added Premid presences integration for the Animecix website.

Changes Made:

-Integrated Premid presences to fetch data from the Animecix website's page titles and content.
-Implemented dynamic updates to display the correct anime title and episode information as users watch.
-Provided real-time updates for current page content and the specific episodes being watched.

Additional Information:

-This change aims to enhance the user experience by providing more accurate and personalized information while watching anime.
-The Premid presences feature displays relevant title, episode name, and other related details based on the anime being watched.

Testing:

-Tested with several anime titles and episodes on the Animecix website. Presences are updated correctly.
-Each page has been tested one by one, no issues found.

Acknowledgements

Screenshots

Proof showing the creation/modification is working as expected

image
image
image
image
image
image
image
image
image
image

Signed-off-by: iSwesia <[email protected]>
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

},
"url": "animecix.net",
"version": "1.0.0",
"logo": "https://discord.do/wp-content/uploads/2023/08/AnimeciX.jpg",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logo should be 512x512. Use waifu2x if you need to upscale.

"url": "animecix.net",
"version": "1.0.0",
"logo": "https://discord.do/wp-content/uploads/2023/08/AnimeciX.jpg",
"thumbnail": "https://discord.do/wp-content/uploads/2023/08/AnimeciX.jpg",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a screenshot or a promotional image/banner.

Comment on lines 3 to 5
});

const browsingTimestamp = Math.floor(Date.now() / 1000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
});
const browsingTimestamp = Math.floor(Date.now() / 1000);
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

};

const updatePresence = () => {
let presenceData: PresenceData = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let presenceData: PresenceData = {
const presenceData: PresenceData = {

Comment on lines 13 to 17
const observer = new MutationObserver(() => {
callback();
});

observer.observe(document.body, { childList: true, subtree: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const observer = new MutationObserver(() => {
callback();
});
observer.observe(document.body, { childList: true, subtree: true });
new MutationObserver(() => {
callback();
}).observe(document.body, { childList: true, subtree: true });

Comment on lines 33 to 41
const episodeTitle = document.querySelectorAll(".t-title > .ng-star-inserted")[1]?.textContent;
const SEInfo = document.querySelector(".episode-number")?.textContent;
// Thumbnail
// const animeImgElement = document.querySelector("img.media-image-el");
const animeImg = document.querySelector<HTMLElement>("media-item-header")?.style.backgroundImage.match(/url\(["']?(.*?)["']?\)/)?.[1]

presenceData.largeImageKey = animeImg;
presenceData.details = episodeTitle || "Loading";
presenceData.state = SEInfo || "Loading";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const episodeTitle = document.querySelectorAll(".t-title > .ng-star-inserted")[1]?.textContent;
const SEInfo = document.querySelector(".episode-number")?.textContent;
// Thumbnail
// const animeImgElement = document.querySelector("img.media-image-el");
const animeImg = document.querySelector<HTMLElement>("media-item-header")?.style.backgroundImage.match(/url\(["']?(.*?)["']?\)/)?.[1]
presenceData.largeImageKey = animeImg;
presenceData.details = episodeTitle || "Loading";
presenceData.state = SEInfo || "Loading";
presenceData.largeImageKey = document.querySelector<HTMLElement>("media-item-header")?.style.backgroundImage.match(/url\(["']?(.*?)["']?\)/)?.[1];
presenceData.details = document.querySelectorAll(".t-title > .ng-star-inserted")[1]?.textContent || "Loading";
presenceData.state = document.querySelector(".episode-number")?.textContent || "Loading";

Comment on lines 45 to 52
const animeTitle = document.querySelector(".t-title a")?.textContent;
// Thumbnail
// const animeImgElement = document.querySelector("img.media-image-el");
const animeImg = document.querySelector<HTMLElement>("media-item-header")?.style.backgroundImage.match(/url\(["']?(.*?)["']?\)/)?.[1]

presenceData.largeImageKey = animeImg;
presenceData.details = animeTitle || "Loading";
presenceData.state = "Bölümler görüntüleniyor";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const animeTitle = document.querySelector(".t-title a")?.textContent;
// Thumbnail
// const animeImgElement = document.querySelector("img.media-image-el");
const animeImg = document.querySelector<HTMLElement>("media-item-header")?.style.backgroundImage.match(/url\(["']?(.*?)["']?\)/)?.[1]
presenceData.largeImageKey = animeImg;
presenceData.details = animeTitle || "Loading";
presenceData.state = "Bölümler görüntüleniyor";
presenceData.largeImageKey = document.querySelector<HTMLElement>("media-item-header")?.style.backgroundImage.match(/url\(["']?(.*?)["']?\)/)?.[1];
presenceData.details = document.querySelector(".t-title a")?.textContent || "Loading";
presenceData.state = "Bölümler görüntüleniyor";

Comment on lines 70 to 73
const userImg = document.querySelector<HTMLImageElement>(".header > .user-avatar.real")?.src;
const userName = document.querySelector(".header > h1.name")?.textContent;
presenceData.largeImageKey = Assets.Logo;
presenceData.smallImageKey = userImg;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const userImg = document.querySelector<HTMLImageElement>(".header > .user-avatar.real")?.src;
const userName = document.querySelector(".header > h1.name")?.textContent;
presenceData.largeImageKey = Assets.Logo;
presenceData.smallImageKey = userImg;
const userName = document.querySelector(".header > h1.name")?.textContent;
presenceData.largeImageKey = Assets.Logo;
presenceData.smallImageKey = document.querySelector<HTMLImageElement>(".header > .user-avatar.real")?.src;

presenceData.smallImageText = userName;
presenceData.details = "Kullanıcı görüntüleniyor:";
presenceData.state = userName || "Loading..";
} else if (document.location.pathname === "/watchlist") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer switch instead of else if...

switch (document.location) {
  case "watchlist": {
   // ... code
   break;
}
};

Comment on lines 121 to 126
const keyword = document.querySelector(".query")?.textContent;
presenceData.largeImageKey = Assets.Logo;
presenceData.smallImageKey = Assets.Search;
presenceData.smallImageText = "Aranıyor"
presenceData.details = "Aranıyor:";
presenceData.state = keyword;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format with prettier to fix semicolons

Suggested change
const keyword = document.querySelector(".query")?.textContent;
presenceData.largeImageKey = Assets.Logo;
presenceData.smallImageKey = Assets.Search;
presenceData.smallImageText = "Aranıyor"
presenceData.details = "Aranıyor:";
presenceData.state = keyword;
presenceData.largeImageKey = Assets.Logo;
presenceData.smallImageKey = Assets.Search;
presenceData.smallImageText = "Aranıyor";
presenceData.details = "Aranıyor:";
presenceData.state = document.querySelector(".query")?.textContent;

websites/A/AnimeciX/presence.ts Show resolved Hide resolved
Signed-off-by: iSwesia <[email protected]>
Signed-off-by: iSwesia <[email protected]>
Signed-off-by: iSwesia <[email protected]>
Signed-off-by: iSwesia <[email protected]>
Signed-off-by: iSwesia <[email protected]>
Signed-off-by: iSwesia <[email protected]>
Signed-off-by: iSwesia <[email protected]>
Signed-off-by: iSwesia <[email protected]>

enum Images {
Logo = 'https://i.imgur.com/ExLxNbB.png',
SettingsICO = 'https://i.imgur.com/pUucFeP.png',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asset should be 512x512px

&& document.location.pathname.includes('/episode/')
) {
// Thumbnail
// const animeImgElement = document.querySelector("img.media-image-el");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// const animeImgElement = document.querySelector("img.media-image-el");

function updatePresence() {
const presenceData: PresenceData = {
largeImageKey: Images.Logo,
} as PresenceData
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the type cast needed here?

&& !document.location.pathname.includes('/episode/')
) {
// Thumbnail
// const animeImgElement = document.querySelector("img.media-image-el");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// const animeImgElement = document.querySelector("img.media-image-el");

Comment on lines +157 to +176
break
}
case '/gw-rooms': {
presenceData.largeImageKey = Images.Logo
presenceData.smallImageKey = Assets.Premiere
presenceData.smallImageText = 'Group Watch'
presenceData.details = 'AnimeciX'
presenceData.state = 'İzleme odaları görüntüleniyor..'

break
}
case '/search': {
presenceData.largeImageKey = Images.Logo
presenceData.smallImageKey = Assets.Search
presenceData.smallImageText = 'Aranıyor'
presenceData.details = 'Aranıyor:'
presenceData.state = document.querySelector('.query')?.textContent

break
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra newline between break and code


enum Images {
Logo = 'https://i.imgur.com/ExLxNbB.png',
SettingsICO = 'https://i.imgur.com/pUucFeP.png',

Check failure

Code scanning / PMD

Makes sure all images (logo and URLs) are exactly 512x512 pixels Error

Image URL dimensions must be exactly 512x512 pixels, got 500x500 for URL: https://i.imgur.com/pUucFeP.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants