@@ -632,11 +632,32 @@ function setupForumsConfig() {
632632 if ( profileMenu ) {
633633 const profileMenuObserver = new MutationObserver ( ( ) => {
634634 // Manually performing querySelector here due to odd failure to identify added node by MutationObserver
635- const target = profileMenu . querySelector ( "ul.tabPanes" ) ;
636- if ( target ) {
637- handleProfileDropdown ( target as HTMLElement ) ;
638- profileMenuObserver . disconnect ( ) ;
639- }
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 ( ) ;
640661 } ) ;
641662 profileMenuObserver . observe ( profileMenu , {
642663 childList : true ,
@@ -1976,25 +1997,22 @@ function handleOnHold(target: HTMLElement) {
19761997
19771998/**
19781999 * Adds a button to open the script config in the user dropdown menu
1979- * @param {HTMLElementEventMap } event
2000+ * @param insertParent The parent element to insert into
2001+ * @param insertBefore The element to insert before
19802002 * @returns void
19812003 */
1982- function handleProfileDropdown ( target : HTMLElement ) {
1983- if ( target . nodeName != "UL" || ! target . classList . contains ( "tabPanes" ) )
1984- return ;
2004+ function insertConfigButton (
2005+ insertParent : HTMLElement ,
2006+ insertBefore : HTMLElement ,
2007+ ) {
19852008 const btn = document . createElement ( "a" ) ;
19862009 btn . classList . add ( "menu-linkRow" ) ;
19872010 btn . innerHTML = "Forum Enhancement Script Config" ;
19882011 btn . style . cursor = "pointer" ;
19892012 btn . onclick = function ( ) {
19902013 GM_config . open ( ) ;
19912014 } ;
1992- target
1993- . querySelector ( "li.is-active" )
1994- ?. insertBefore (
1995- btn ,
1996- target . querySelector ( "li.is-active > a.menu-linkRow" ) ,
1997- ) ;
2015+ insertParent . insertBefore ( btn , insertBefore ) ;
19982016}
19992017
20002018/**
0 commit comments