MediaWiki:Common.js: Difference between revisions

From Good Creations! MC Wiki
Jump to navigation Jump to search
m Fix
Tag: Reverted
m Another try to fix
Tag: Reverted
Line 50: Line 50:
});
});


// ---- WidgetBot Crate Widget ----
// WidgetBot: Discord Crate widget
$.getScript('https://cdn.jsdelivr.net/npm/@widgetbot/crate@3', function () {
$.getScript('https://cdn.jsdelivr.net/npm/@widgetbot/crate@3', function () {
     new Crate({
     new Crate({
Line 60: Line 60:
});
});


// ---- Custom Elements Built-in polyfill (Safari support) ----
// Safari polyfill for custom elements with built-in extends
(function () {
(function () {
     const ceBuiltinScript = document.createElement('script');
     var ceScript = document.createElement('script');
     ceBuiltinScript.src = 'https://unpkg.com/@ungap/custom-elements-builtin';
     ceScript.src = 'https://unpkg.com/@ungap/custom-elements-builtin';
     ceBuiltinScript.async = false;
     ceScript.async = false;
     document.head.appendChild(ceBuiltinScript);
    ceScript.onload = () => console.log('[Polyfill] custom-elements-builtin loaded');
     document.head.appendChild(ceScript);
})();
})();


// ---- X-Frame-Bypass loader ----
// X-Frame-Bypass module script (type=module) — MUST be loaded as type="module"
fetch('https://unpkg.com/x-frame-bypass')
(function () {
     .then(res => res.text())
    var bypassScript = document.createElement('script');
    .then(code => {
    bypassScript.type = 'module';
        const script = document.createElement('script');
    bypassScript.src = 'https://unpkg.com/x-frame-bypass';
        script.textContent = code;
     bypassScript.onload = () => console.log('[XFB] x-frame-bypass module loaded');
        document.head.appendChild(script);
    document.head.appendChild(bypassScript);
    })
})();
    .catch(err => console.error('Failed to load x-frame-bypass:', err));

Revision as of 18:21, 2 June 2025

/*
 * This is the JS for all skins (for both mobile and desktop) on MediaWiki.org.
 * Consider whether you can use a gadget with one of the options set to limit
 * where it is loaded. See [[Extension:Gadgets#Options]].
 */
/* global mw, $ */
/**
 * Hide prefix in category
 *
 * @source https://www.mediawiki.org/wiki/Snippets/Hide_prefix_in_category
 * @rev 5
 */
var prefix = $.trim( $( '#mw-cat-hideprefix' ).text() ) || ( mw.config.get( 'wgTitle' ) + '/' );
$( '#mw-pages' ).find( 'a' ).text( function ( i, val ) {
    return val.slice( 0, prefix.length ) === prefix ? val.slice( prefix.length ) : val;
} );

/**
 * @source https://www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 * @revision 2017-05-16
 */
mw.loader.using( ['mediawiki.util'], function () {
	var extraCSS = mw.util.getParamValue( 'withCSS' ),
		extraJS = mw.util.getParamValue( 'withJS' ),
		extraModule = mw.util.getParamValue( 'withModule' );

	if ( extraCSS ) {
		if ( /^MediaWiki:[^&<>=%#]*\.css$/.test( extraCSS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraCSS ) + '&action=raw&ctype=text/css', 'text/css' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withCSS value' } );
		}
	}

	if ( extraJS ) {
		if ( /^MediaWiki:[^&<>=%#]*\.js$/.test( extraJS ) ) {
			mw.loader.load( '/w/index.php?title=' + encodeURIComponent( extraJS ) + '&action=raw&ctype=text/javascript' );
		} else {
			mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
		}
	}

	if ( extraModule ) {
		if ( /^ext\.gadget\.[^,\|]+$/.test( extraModule ) ) {
			mw.loader.load( extraModule );
		} else {
			mw.notify( 'Only gadget modules are allowed.', { title: 'Invalid withModule value' } );
		}
	}
});

// WidgetBot: Discord Crate widget
$.getScript('https://cdn.jsdelivr.net/npm/@widgetbot/crate@3', function () {
    new Crate({
        server: '1163030464903258122', // The 'Good Creations!' Minecraft Server
        channel: '1163030468111908986', // #general-💬
        allChannelNotifications: true,
        color: 'black'
    });
});

// Safari polyfill for custom elements with built-in extends
(function () {
    var ceScript = document.createElement('script');
    ceScript.src = 'https://unpkg.com/@ungap/custom-elements-builtin';
    ceScript.async = false;
    ceScript.onload = () => console.log('[Polyfill] custom-elements-builtin loaded');
    document.head.appendChild(ceScript);
})();

// X-Frame-Bypass module script (type=module) — MUST be loaded as type="module"
(function () {
    var bypassScript = document.createElement('script');
    bypassScript.type = 'module';
    bypassScript.src = 'https://unpkg.com/x-frame-bypass';
    bypassScript.onload = () => console.log('[XFB] x-frame-bypass module loaded');
    document.head.appendChild(bypassScript);
})();