MediaWiki:Common.js: Difference between revisions

No edit summary
GA: skip missing pages; add site_check parameter to filter fake hits
 
(7 intermediate revisions by the same user not shown)
Line 41: Line 41:
if ( extraJS ) {
if ( extraJS ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
mw.loader.load( '/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript' );
mw.loader.load( '/index.php?title=' + extraJS + '&action=raw&ctype=text/javascript&maxage=300&smaxage=300' );
} else {
} else {
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
Line 121: Line 121:
} );
} );
/* DO NOT ADD CODE BELOW THIS LINE */
/* DO NOT ADD CODE BELOW THIS LINE */
/* Main Page: show the language button at the top (in the title bar), as on all other pages */
$( function () {
if ( mw.config.get( 'wgIsMainPage' ) ) {
var $btn = $( '#p-lang-btn' ), $bar = $( '.vector-page-titlebar' );
if ( $btn.length && $bar.length && !$btn.closest( '.vector-page-titlebar' ).length ) {
$btn.addClass( 'mw-portlet-lang-heading-0' ).appendTo( $bar );
}
}
} );
/* Google Analytics 4 (property "Chabadpedia English - GA4")
* Counted only: visitors who are not logged in, viewing a page for reading
* (articles, portals, categories, project pages; not history, diffs, edits or special pages),
* and only after a real action on the page (mouse, scroll, touch or key), which most bots never do. */
( function () {
if ( mw.config.get( 'wgUserName' ) !== null || mw.config.get( 'wgAction' ) !== 'view' ) {
return;
}
var ns = mw.config.get( 'wgNamespaceNumber' );
if ( [ 0, 4, 14, 3000 ].indexOf( ns ) === -1 ) {
return;
}
/* Pages that do not exist (404) are not counted; category pages without text are still counted */
if ( mw.config.get( 'wgArticleId' ) === 0 && ns !== 14 ) {
return;
}
if ( /[?&](diff|oldid|curid|printable|redirect)=/.test( location.search ) ) {
return;
}
var id = 'G-V6K7LP5ZTY';
var events = [ 'mousemove', 'scroll', 'touchstart', 'keydown', 'click' ];
var done = false;
function start() {
if ( done ) {
return;
}
done = true;
events.forEach( function ( ev ) {
window.removeEventListener( ev, start, true );
} );
var s = document.createElement( 'script' );
s.async = true;
s.src = 'https://www.googletagmanager.com/gtag/js?id=' + id;
document.head.appendChild( s );
window.dataLayer = window.dataLayer || [];
window.gtag = function () { window.dataLayer.push( arguments ); };
window.gtag( 'js', new Date() );
/* site_check marks hits sent by this code; reports can be filtered on it to drop fake hits sent straight to Google */
window.gtag( 'set', { site_check: 'cp1' } );
window.gtag( 'config', id, { site_check: 'cp1' } );
}
events.forEach( function ( ev ) {
window.addEventListener( ev, start, { capture: true, passive: true } );
} );
}() );
/* Related Articles box at the bottom of articles: see [[MediaWiki:RelatedArticles.js]] */
mw.loader.load( mw.config.get( 'wgScript' ) + '?title=MediaWiki:RelatedArticles.js&action=raw&ctype=text/javascript&maxage=300&smaxage=300' );
/* "Read in Hebrew" button at the top of articles: see [[MediaWiki:ReadInHebrew.js]] */
mw.loader.load( mw.config.get( 'wgScript' ) + '?title=MediaWiki:ReadInHebrew.js&action=raw&ctype=text/javascript&maxage=300&smaxage=300' );
/* Short description under the article title: see [[MediaWiki:ShortDescription.js]] */
mw.loader.load( mw.config.get( 'wgScript' ) + '?title=MediaWiki:ShortDescription.js&action=raw&ctype=text/javascript&maxage=300&smaxage=300' );