Skip to content

Commit d8e0ce9

Browse files
authored
[FORUMS] Fix config button not appearing (#120)
* fix: failure to add config button * fix: failure to add config button for non-forum-mods
1 parent 36e9aa5 commit d8e0ce9

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

src/EGO Forum Enhancement.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name EdgeGamers Forum Enhancement%RELEASE_TYPE%
33
// @namespace https://github.com/blankdvth/eGOScripts/blob/master/src/EGO%20Forum%20Enhancement.ts
4-
// @version 4.11.5
4+
// @version 4.11.6
55
// @description Add various enhancements & QOL additions to the EdgeGamers Forums that are beneficial for Leadership members.
66
// @author blank_dvth, Skle, MSWS, PixeL
77
// @match https://www.edgegamers.com/*
@@ -630,12 +630,34 @@ function setupForumsConfig() {
630630

631631
const profileMenu = document.querySelector("div.js-visitorMenuBody");
632632
if (profileMenu) {
633-
const profileMenuObserver = new MutationObserver((mutations) => {
634-
mutations.every((mutation) => {
635-
mutation.addedNodes.forEach((node) => {
636-
handleProfileDropdown(node as HTMLElement);
637-
});
638-
});
633+
const profileMenuObserver = new MutationObserver(() => {
634+
// Manually performing querySelector here due to odd failure to identify added node by MutationObserver
635+
const tabPanes = profileMenu.querySelector("ul.tabPanes");
636+
if (tabPanes) {
637+
// Found tabbed menu (forum mod w/ bookmarks tab)
638+
const insertParent = tabPanes.querySelector("li.is-active");
639+
const insertBefore = insertParent?.querySelector(
640+
":scope > a.menu-linkRow",
641+
);
642+
if (insertBefore)
643+
insertConfigButton(
644+
insertParent as HTMLElement,
645+
insertBefore as HTMLElement,
646+
);
647+
} else if (profileMenu.querySelector("a.menu-linkRow")) {
648+
// Didn't find, but has menu buttons now (normal direct menu)
649+
const insertParent = profileMenu;
650+
const insertBefore = insertParent.querySelector(
651+
":scope > a.menu-linkRow",
652+
);
653+
if (insertBefore)
654+
insertConfigButton(
655+
insertParent as HTMLElement,
656+
insertBefore as HTMLElement,
657+
);
658+
} else return; // Still didn't find, wait for next mutation
659+
660+
profileMenuObserver.disconnect();
639661
});
640662
profileMenuObserver.observe(profileMenu, {
641663
childList: true,
@@ -1975,25 +1997,22 @@ function handleOnHold(target: HTMLElement) {
19751997

19761998
/**
19771999
* Adds a button to open the script config in the user dropdown menu
1978-
* @param {HTMLElementEventMap} event
2000+
* @param insertParent The parent element to insert into
2001+
* @param insertBefore The element to insert before
19792002
* @returns void
19802003
*/
1981-
function handleProfileDropdown(target: HTMLElement) {
1982-
if (target.nodeName != "UL" || !target.classList.contains("tabPanes"))
1983-
return;
2004+
function insertConfigButton(
2005+
insertParent: HTMLElement,
2006+
insertBefore: HTMLElement,
2007+
) {
19842008
const btn = document.createElement("a");
19852009
btn.classList.add("menu-linkRow");
19862010
btn.innerHTML = "Forum Enhancement Script Config";
19872011
btn.style.cursor = "pointer";
19882012
btn.onclick = function () {
19892013
GM_config.open();
19902014
};
1991-
target
1992-
.querySelector("li.is-active")
1993-
?.insertBefore(
1994-
btn,
1995-
target.querySelector("li.is-active > a.menu-linkRow"),
1996-
);
2015+
insertParent.insertBefore(btn, insertBefore);
19972016
}
19982017

19992018
/**

0 commit comments

Comments
 (0)