|
1 | 1 | // ==UserScript== |
2 | 2 | // @name EdgeGamers Forum Enhancement%RELEASE_TYPE% |
3 | 3 | // @namespace https://github.com/blankdvth/eGOScripts/blob/master/src/EGO%20Forum%20Enhancement.ts |
4 | | -// @version 4.11.5 |
| 4 | +// @version 4.11.6 |
5 | 5 | // @description Add various enhancements & QOL additions to the EdgeGamers Forums that are beneficial for Leadership members. |
6 | 6 | // @author blank_dvth, Skle, MSWS, PixeL |
7 | 7 | // @match https://www.edgegamers.com/* |
@@ -630,12 +630,34 @@ function setupForumsConfig() { |
630 | 630 |
|
631 | 631 | const profileMenu = document.querySelector("div.js-visitorMenuBody"); |
632 | 632 | 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(); |
639 | 661 | }); |
640 | 662 | profileMenuObserver.observe(profileMenu, { |
641 | 663 | childList: true, |
@@ -1975,25 +1997,22 @@ function handleOnHold(target: HTMLElement) { |
1975 | 1997 |
|
1976 | 1998 | /** |
1977 | 1999 | * 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 |
1979 | 2002 | * @returns void |
1980 | 2003 | */ |
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 | +) { |
1984 | 2008 | const btn = document.createElement("a"); |
1985 | 2009 | btn.classList.add("menu-linkRow"); |
1986 | 2010 | btn.innerHTML = "Forum Enhancement Script Config"; |
1987 | 2011 | btn.style.cursor = "pointer"; |
1988 | 2012 | btn.onclick = function () { |
1989 | 2013 | GM_config.open(); |
1990 | 2014 | }; |
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); |
1997 | 2016 | } |
1998 | 2017 |
|
1999 | 2018 | /** |
|
0 commit comments