@@ -8,23 +8,80 @@ import { createMainUI, attachEventListeners } from './ui-dashboard.js';
88 * ============================================
99 */
1010
11+ export function getPerformerIdFromUrl ( ) {
12+ const match = window . location . pathname . match ( / ^ \/ p e r f o r m e r s \/ ( \d + ) (?: \/ | $ ) / ) ;
13+ return match ? match [ 1 ] : null ;
14+ }
15+
16+ export function isOnSinglePerformerPage ( ) {
17+ return getPerformerIdFromUrl ( ) !== null ;
18+ }
19+
1120export function shouldShowButton ( ) {
1221 const path = window . location . pathname ;
13- return / ^ \/ p e r f o r m e r s / . test ( path ) || / ^ \/ i m a g e s / . test ( path ) ;
22+
23+ if ( path === "/performers" || path === "/performers/" ) return true ;
24+ if ( path === "/images" || path === "/images/" ) return true ;
25+
26+ return / ^ \/ p e r f o r m e r s \/ \d + (?: \/ | $ ) / . test ( path ) ;
1427}
1528
1629export function addFloatingButton ( ) {
17- if ( document . getElementById ( "hon-floating-btn" ) ) return ;
18- if ( ! shouldShowButton ( ) ) return ;
19-
20- const btn = document . createElement ( "button" ) ;
21- btn . id = "hon-floating-btn" ;
22- btn . innerHTML = "🔥" ;
23- btn . onclick = ( ) => window . openRankingModal ( ) ;
24- btn . setAttribute ( "onclick" , "window.openRankingModal()" ) ;
25- document . body . appendChild ( btn ) ;
30+ const buttonId = "plugin_hon" ;
31+ const existing = document . getElementById ( buttonId ) ;
32+
33+ // Remove if not needed
34+ if ( ! shouldShowButton ( ) ) {
35+ if ( existing ) existing . closest ( ".col-4" ) ?. remove ( ) ;
36+ return ;
37+ }
38+
39+ // Prevent duplicates
40+ if ( existing ) return ;
41+
42+ // Outer container matches other buttons
43+ const buttonContainer = document . createElement ( "div" ) ;
44+ buttonContainer . className = "col-4 col-sm-3 col-md-2 col-lg-auto nav-link" ;
45+
46+ // Inner button styled exactly like the Performers button
47+ buttonContainer . innerHTML = `
48+ <a href="javascript:void(0);" id="${ buttonId } " class="minimal p-4 p-xl-2 d-flex d-xl-inline-block flex-column justify-content-between align-items-center btn btn-primary" title="HotOrNot">
49+ <svg
50+ xmlns="http://www.w3.org/2000/svg"
51+ viewBox="0 0 16 16"
52+ class="plugin_hon__flame svg-inline--fa fa-icon nav-menu-icon d-block d-xl-inline mb-2 mb-xl-0"
53+ fill="currentColor"
54+ aria-hidden="true"
55+ focusable="false"
56+ role="img">
57+ <path d="M8 0c-.2 3.5-2 5-3 6-1 1-1 3-1 4s1 3 3 3 4-1 4-3c0-2-2-3-2-5 0-1 1-2 1-2S9.5 0 8 0z"/>
58+ </svg>
59+ <span>HotOrNot</span>
60+ </a>
61+ ` ;
62+
63+ // Add click behavior
64+ const button = buttonContainer . querySelector ( `#${ buttonId } ` ) ;
65+ button . addEventListener ( "click" , openRankingModal ) ;
66+
67+ // Append to navbar
68+ const navTarget = document . querySelector ( ".navbar-nav" ) ;
69+ if ( navTarget ) navTarget . appendChild ( buttonContainer ) ;
2670}
2771
72+ function watchForNavigation ( ) {
73+ const observer = new MutationObserver ( ( ) => {
74+ addFloatingButton ( ) ;
75+ } ) ;
76+
77+ observer . observe ( document . body , {
78+ childList : true ,
79+ subtree : true ,
80+ } ) ;
81+ }
82+
83+ watchForNavigation ( ) ;
84+
2885// Declared outside so closeRankingModal can remove the same reference
2986function handleGlobalKeys ( e ) {
3087 const activeModal = document . getElementById ( "hon-modal" ) ;
@@ -158,3 +215,19 @@ export function closeRankingModal() {
158215
159216 document . removeEventListener ( "keydown" , handleGlobalKeys ) ;
160217}
218+
219+ addFloatingButton ( ) ; // initial render
220+
221+ const navTarget = document . querySelector ( ".navbar-nav" ) ;
222+ if ( navTarget ) {
223+ const observer = new MutationObserver ( ( ) => {
224+ addFloatingButton ( ) ;
225+ } ) ;
226+
227+ observer . observe ( navTarget , { childList : true , subtree : true } ) ;
228+ }
229+
230+ // Optional: handle SPA navigation
231+ [ "popstate" ] . forEach ( event =>
232+ window . addEventListener ( event , addFloatingButton )
233+ ) ;
0 commit comments