diff --git a/plugins/linkProfilePicture.plugin.js b/plugins/linkProfilePicture.plugin.js index 7d6a23b..f2fb499 100644 --- a/plugins/linkProfilePicture.plugin.js +++ b/plugins/linkProfilePicture.plugin.js @@ -1,7 +1,7 @@ /** * @name Link-Profile-Picture * @description Lets you click users' avatars on their profile page to view a bigger version in your browser. - * @version 1.3.3 + * @version 1.4.0 * @author square * @authorLink https://betterdiscord.app/developer/square * @website https://betterdiscord.app/plugin/Link-Profile-Picture @@ -10,14 +10,24 @@ */ module.exports = class linkProfilePicture { - stop(){} + stop() {} start() { - document.addEventListener("click", LinkProfilePicture, true); - this.stop = document.removeEventListener.bind(document, "click", LinkProfilePicture, true); - function LinkProfilePicture({ target }) { - if (target.classList.contains("avatar_e1126d") && target.parentElement?.parentElement?.classList.contains("inner_e1126d")) { - window.open(target.querySelector("img").src.replace(/\?.*$/, "?quality=lossless&size=4096"), "_blank"); - } - } + document.addEventListener("click", this.handleProfilePictureClick, true); + this.stop = () => { + document.removeEventListener("click", this.handleProfilePictureClick, true); + }; + } + + handleProfilePictureClick({ target }) { + const parent = target.parentElement; + const grandParent = parent.parentElement; + + // Check if the immediate parent contains a class that starts with 'avatar_' and its parent contains a class that starts with 'headerInner_' + if (!parent || ![...parent.classList].some(cls => cls.startsWith("avatar_"))) return; + if (!grandParent || ![...grandParent.classList].some(cls => cls.startsWith("headerInner_"))) return; + + // Open the image with modified URL + const imageUrl = target.querySelector("img").src.replace(/\?.*$/, "?quality=lossless&size=4096"); + window.open(imageUrl, "_blank"); } };