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

linkProfilePicture v1.4.0 #220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions plugins/linkProfilePicture.plugin.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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");
}
};