Skip to content

Commit

Permalink
AvatarHover v0.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Inve1951 committed Nov 13, 2021
1 parent 7c17200 commit 0e063b4
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 33 deletions.
6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/build_dev.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions coffee/AvatarHover.plugin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
class global.AvatarHover
getName: -> "Avatar Hover"
getDescription: -> "When hovering, resize the avatar. Use Ctrl / Ctrl+Shift."
getAuthor: -> "noVaLue, MurmursOnSARS, square, Green"
getVersion: -> "0.7.1"
getAuthor: -> "square, noVaLue, MurmursOnSARS, Green"
getVersion: -> "0.7.2"

hoverCard = AsyncKeystate = null

Expand Down Expand Up @@ -93,7 +93,7 @@ class global.AvatarHover
target.querySelector("img")?.src or
target.src or
getComputedStyle(target).backgroundImage.match(/^url\((["']?)(.+)\1\)$/)[2]
).replace /\?size=\d{3,4}\)?$/, "?size=#{size}"
).replace /\?size=\d{2,4}\)?$/, "?size=#{size}"

Object.assign hoverCard.style,
backgroundColor: settings.avatarBackgroundColor
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"name": "BetterDiscordStuff",
"description": "square's BD plugins & themes, focused on enhancing user experience",
"author": "Inve1951 (square#3880)",
"license": "DSL",
"private": true,
"scripts": {
"build": "coffee --no-header -o plugins/ -bct coffee/"
"build": "coffee --no-header -o plugins/ -bct coffee/",
"build:dev": "coffee --no-header -o plugins/ -bctM coffee/"
},
"repository": {
"type": "git",
Expand All @@ -13,8 +17,6 @@
"BD",
"discord"
],
"author": "Inve1951 (square#3880)",
"license": "DSL",
"bugs": {
"url": "https://github.com/Inve1951/BetterDiscordStuff/issues"
},
Expand Down
77 changes: 50 additions & 27 deletions plugins/AvatarHover.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ global.AvatarHover = function () {
}

getAuthor() {
return "noVaLue, MurmursOnSARS, square, Green";
return "square, noVaLue, MurmursOnSARS, Green";
}

getVersion() {
return "0.7.3";
return "0.7.2";
}

load() {
Expand All @@ -25,6 +25,7 @@ global.AvatarHover = function () {
if (err || 200 !== (res != null ? res.statusCode : void 0)) {
return r(err != null ? err : res);
}

Object.defineProperties(window.SuperSecretSquareStuff, {
libLoaded: {
value: c
Expand All @@ -40,7 +41,10 @@ global.AvatarHover = function () {

async start() {
var createElement;
({ AsyncKeystate, createElement } = await SuperSecretSquareStuff);
({
AsyncKeystate,
createElement
} = await SuperSecretSquareStuff);
getSettings();
updateQualifier();
BdApi.injectCSS("css-AvatarHover", css);
Expand All @@ -67,10 +71,17 @@ global.AvatarHover = function () {
static updateSettings() {
var checked, i, len, name, ref, type, value;
ref = document.querySelectorAll("#settings_AvatarHover input");

for (i = 0, len = ref.length; i < len; i++) {
({ name, type, value, checked } = ref[i]);
({
name,
type,
value,
checked
} = ref[i]);
settings[name] = "checkbox" === type ? checked : value || defaultSettings[name];
}

BdApi.setData("AvatarHover", "settings", settings);
return updateQualifier();
}
Expand All @@ -97,55 +108,57 @@ global.AvatarHover = function () {
isHoverProfile: "Profiles and modals"
};
results = [];
for (k in ref) {
v = ref[k];
results.push(makeInput(k, v));
}
return results;
}().join("")}</div>`;
}

};
}

;
hoverCard = AsyncKeystate = null;

qualifier = null;

updateQualifier = function () {
return qualifier = [
// guilds
settings.isHoverGuilds ? ".wrapper-1BJsBx" : void 0,
// voip, DM channels
settings.isHoverChannels ? ".avatarContainer-28iYmV, .channel-2QD9_O .wrapper-3t9DeA" : void 0,
// friends list
settings.isHoverFriends ? ".userInfo-2zN2z8 .avatar-3W3CeO" : void 0,
// messages, embeds
settings.isHoverChatMessages ? ".contents-2mQqc9 .avatar-1BDn8e, .embedAuthorIcon--1zR3L" : void 0,
// channel users
settings.isHoverChatUsers ? ".member-3-YXUe .wrapper-3t9DeA" : void 0,
// DM call
settings.isHoverCall ? ".participant-1lOCsd .wrapper-2QE8vf" : void 0,
// user modal, user popout, mutual servers/friends
settings.isHoverProfile ? ".header-QKLPzZ .avatar-3EQepX, .wrapper-3t9DeA, .listAvatar-1NlAhb" : void 0].filter(function (s) {
return qualifier = [// guilds
settings.isHoverGuilds ? ".wrapper-25eVIn" : void 0, // voip, DM channels
settings.isHoverChannels ? ".avatarContainer-2inGBK, .channel-2QD9_O .avatar-3uk_u9" : void 0, // friends list
settings.isHoverFriends ? ".userInfo-2zN2z8 .avatar-3W3CeO" : void 0, // messages, embeds
settings.isHoverChatMessages ? ".contents-2mQqc9 .avatar-1BDn8e, .embedAuthorIcon--1zR3L" : void 0, // channel users
settings.isHoverChatUsers ? ".member-3-YXUe .avatar-3uk_u9" : void 0, // DM call
settings.isHoverCall ? ".callAvatarWrapper-3Ax_xH" : void 0, // modals, userpopout
settings.isHoverProfile ? ".header-QKLPzZ .avatar-3EQepX, .avatarWrapper-3H_478" : void 0].filter(function (s) {
return s != null;
}).join(", ");
};

handleKeyUpDown = function ({ key }) {
handleKeyUpDown = function ({
key
}) {
if (key !== "Control" && key !== "Shift") {
return;
}

return updateHoverCard();
};

handleFocusLoss = function () {
return updateHoverCard();
};

handleMouseOverOut = function ({ type, target }) {
handleMouseOverOut = function ({
type,
target
}) {
if (!(target.matches(qualifier) || (target = target.closest(qualifier)))) {
return;
}

return updateHoverCard("mouseover" === type && target);
};

Expand All @@ -156,23 +169,29 @@ global.AvatarHover = function () {
lastTarget = target;
isShown = settings.isShown || AsyncKeystate.key("Control");
isLarge = settings.isLarge || AsyncKeystate.key("Shift");

if (!(isShown && target)) {
return hoverCard.remove();
}

size = isLarge && 256 || 128;
boundsTarget = target.getBoundingClientRect();
boundsWindow = {
width: window.innerWidth,
height: window.innerHeight
};
left = Math.max(0, boundsTarget.left + (boundsTarget.width - size) / 2);

if (left + size > boundsWindow.width) {
left = boundsWindow.width - size;
}

top = size > boundsWindow.height ? (boundsWindow.height - size) / 2 : boundsTarget.bottom + size > boundsWindow.height ? boundsTarget.top - size : boundsTarget.bottom;
if ("none" === (imageUrl = (((ref = target.querySelector("img")) != null ? ref.src : void 0) || target.src || getComputedStyle(target).backgroundImage.match(/^url\((["']?)(.+)\1\)$/)[2]).replace(/\?size=\d{3,4}\)?$/, `?size=${size}`))) {

if ("none" === (imageUrl = (((ref = target.querySelector("img")) != null ? ref.src : void 0) || target.src || getComputedStyle(target).backgroundImage.match(/^url\((["']?)(.+)\1\)$/)[2]).replace(/\?size=\d{2,4}\)?$/, `?size=${size}`))) {
return hoverCard.remove();
}

Object.assign(hoverCard.style, {
backgroundColor: settings.avatarBackgroundColor,
backgroundImage: `url(${imageUrl})`,
Expand Down Expand Up @@ -202,28 +221,33 @@ global.AvatarHover = function () {
isHoverCall: true,
isHoverProfile: true
};

settings = null;

getSettings = function () {
var k, ref, results, v;

if (settings != null) {
return;
}

settings = (ref = BdApi.getData("AvatarHover", "settings")) != null ? ref : {};
results = [];

for (k in defaultSettings) {
v = defaultSettings[k];
results.push(settings[k] != null ? settings[k] : settings[k] = v);
}

return results;
};

makeInput = function (name, label) {
var _default, isCheckbox, type;

if (label == null) {
return "<br/>";
}

type = Boolean === defaultSettings[name].constructor && (isCheckbox = true) && "checkbox" || "text";
_default = isCheckbox ? settings[name] ? "checked" : "" : `placeholder="${defaultSettings[name]}" value="${settings[name]}\"`;
return `<label><input type="${type}" name="${name}" ${_default} onChange="AvatarHover.updateSettings()"/> ${label}</label><br/>`;
Expand All @@ -240,6 +264,5 @@ global.AvatarHover = function () {
#settings_AvatarHover {
color: #87909C;
}`;

return AvatarHover;
}.call(this);
}.call(this);

0 comments on commit 0e063b4

Please sign in to comment.