Jump to content

MediaWiki:Common.js

From CasinoLeaks
Revision as of 23:16, 5 November 2026 by Admin (talk | contribs) (Footer redesign: two link columns, calmer 18+ notice, quiet last-edited bar (CURACAOFIL-6))

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* CasinoLeaks footer (CURACAOFIL-6). One block: 18+ notice, two link columns, small bottom line.
   Replaces the default footer link row and the earlier trust-links and 18+ scripts. Owner-authorised 2026-11-05. */
mw.hook( 'wikipage.content' ).add( function () {
	var footer = document.querySelector( 'footer.mw-footer' ) || document.getElementById( 'footer' );
	if ( !footer || footer.querySelector( '.clf' ) ) {
		return;
	}
	function el( tag, cls, text ) {
		var n = document.createElement( tag );
		if ( cls ) { n.className = cls; }
		if ( text ) { n.textContent = text; }
		return n;
	}
	function link( label, target, external ) {
		var a = el( 'a', null, label );
		if ( external ) {
			a.href = target; a.rel = 'noopener nofollow'; a.target = '_blank';
		} else {
			a.href = mw.util.getUrl( target );
		}
		return a;
	}
	var box = el( 'div', 'clf' );

	var rg = el( 'div', 'clf-rg' );
	rg.appendChild( el( 'span', 'clf-age', '18+' ) );
	var p = el( 'p' );
	p.appendChild( el( 'strong', null, 'Gambling can be addictive.' ) );
	p.appendChild( document.createTextNode( ' This site is for information only and is not an invitation to gamble. Need help? ' ) );
	p.appendChild( link( 'GambleAware', 'https://www.gambleaware.org', true ) );
	p.appendChild( document.createTextNode( ', ' ) );
	p.appendChild( link( 'Gambling Therapy', 'https://gamblingtherapy.org', true ) );
	p.appendChild( document.createTextNode( ' or ' ) );
	p.appendChild( link( 'more help', 'CasinoLeaks:Get_help' ) );
	p.appendChild( document.createTextNode( '.' ) );
	rg.appendChild( p );
	box.appendChild( rg );

	var nav = el( 'nav', 'clf-nav' );
	nav.setAttribute( 'aria-label', 'About CasinoLeaks' );
	[
		[ 'About', [ [ 'About us', 'CasinoLeaks:About' ], [ 'Methodology', 'CasinoLeaks:Methodology' ], [ 'Sources and coverage', 'CasinoLeaks:Sources_and_coverage' ], [ 'Independence', 'CasinoLeaks:Funding_and_independence' ], [ 'Team and experts', 'CasinoLeaks:Team_and_experts' ] ] ],
		[ 'Help', [ [ 'Corrections', 'CasinoLeaks:Corrections_policy' ], [ 'Report an error', 'CasinoLeaks:Report_an_error' ], [ 'Contact', 'CasinoLeaks:Contact' ], [ 'Privacy', 'CasinoLeaks:Privacy_policy' ], [ 'Disclaimer', 'CasinoLeaks:General_disclaimer' ] ] ]
	].forEach( function ( group ) {
		var col = el( 'div', 'clf-col' );
		col.appendChild( el( 'div', 'clf-head', group[ 0 ] ) );
		var ul = el( 'ul' );
		group[ 1 ].forEach( function ( item ) {
			var li = el( 'li' );
			li.appendChild( link( item[ 0 ], item[ 1 ] ) );
			ul.appendChild( li );
		} );
		col.appendChild( ul );
		nav.appendChild( col );
	} );
	box.appendChild( nav );

	var bottom = el( 'div', 'clf-bottom' );
	bottom.appendChild( el( 'span', null, '© ' + new Date().getFullYear() + ' CasinoLeaks · Sourced and dated facts about online gambling' ) );
	var toggle = document.getElementById( 'mw-mf-display-toggle' ) || document.querySelector( '#footer-places-mobileview a' );
	if ( toggle ) {
		var t = link( toggle.textContent, '' );
		t.href = toggle.href;
		bottom.appendChild( t );
	}
	box.appendChild( bottom );

	var anchor = footer.querySelector( '.footer-content' ) || footer;
	anchor.insertBefore( box, anchor.firstChild );
	document.documentElement.classList.add( 'clf-ready' );
} );

/* Last-edited bar on phones: show when, not which account (CURACAOFIL-6).
   Minerva replaces the text node after load, so watch the whole bar and re-query each time. */
mw.hook( 'wikipage.content' ).add( function () {
	var bar = document.querySelector( '.last-modified-bar' );
	if ( !bar || bar.getAttribute( 'data-clf' ) ) {
		return;
	}
	bar.setAttribute( 'data-clf', '1' );
	function tidy() {
		var t = bar.querySelector( '.last-modified-bar__text' );
		var m = t && t.textContent.replace( /\s+/g, ' ' ).trim().match( /^(.*?) by .+$/ );
		if ( m ) {
			t.textContent = m[ 1 ];
		}
	}
	tidy();
	new MutationObserver( tidy ).observe( bar, { childList: true, subtree: true, characterData: true } );
} );