MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
(Google Analytics 4) |
m (there was a typo in ID) |
||
Line 136: | Line 136: | ||
) { | ) { | ||
gtag('js', new Date()); | gtag('js', new Date()); | ||
gtag('config', 'G- | gtag('config', 'G-27TV985M46'); | ||
$('head').append($('<script/>').attr('async', 1).attr('src', 'https://www.googletagmanager.com/gtag/js?id=G- | $('head').append($('<script/>').attr('async', 1).attr('src', 'https://www.googletagmanager.com/gtag/js?id=G-27TV985M46')); | ||
} | } | ||
/* /Google Analytics 4 */ | /* /Google Analytics 4 */ |
Latest revision as of 12:44, 8 November 2023
/* This is to redirect any URLS with anchors to the proper place. For instance, If you land on a page with #Test in the url, but on which the no element with id="Test" exists on the page, then it will be redirected to the "Main_Page" URL. That is, if you enter http://www.gabormelli.com/RKB/Fact-oriented_Modeling#Test in the URL bar, you should end up on http://www.gabormelli.com/RKB/Main_Page. Likewise, if you enter http://www.factmodels.com/SRS1/v080630/#Fact-oriented%20Modeling, you should end up on http://www.gabormelli.com/RKB/Fact-oriented_Modeling */ redirectAnchors = { 'Test': 'Main_Page', 'Fact-oriented%20Modeling': 'Fact-oriented_Modeling', 'Fact-oriented Modeling': 'Fact-oriented_Modeling'}; var hash = window.location.hash.substring(1); if( hash && $("#" + hash).length === 0 && redirectAnchors[hash] ) { window.location = wgServer + wgScriptPath + '/' + redirectAnchors[hash]; } /* Add "Elide redirects" link to [[Special:WhatLinksHere]]: 1) hides the redirects themselves, 2) but still shows pages which link to those redirects (unlike "Hide redirects"). */ $('.mw-special-Whatlinkshere fieldset').last().append(' | ', $('<a/>') .attr('style', 'font-weight: bold; cursor: pointer') .append("Elide redirects") .one('click', function() { $(this).hide(); /* Hide "Elide redirects" link */ var $ul = $('#mw-whatlinkshere-list'); /* Remove redirects, flatten the list into a long one-level <ul> */ $list = $ul.find('li'); $list.each(function(idx, li) { if($(li.firstChild).hasClass('mw-redirect')) { /* Delete this line, but preserve <ul> inside */ $(li).replaceWith($(li).find('ul').children()); } }); /* Replace <ul> with <ol> */ $ul.replaceWith($('<ol/>') .attr('id', 'mw-whatlinkshere-list') .append($ul.children())); $ul = $('#mw-whatlinkshere-list'); /* Remove: 1) self-references (e.g. A is redirect to B, and B links to A). 2) repeats (e.g. A is redirect to B, and C links to both A and B). */ var target = $('#mw-whatlinkshere-target').val(); var seen = {}; /* Duplicate titles counter: { title1 => 1, title2 => 5, title3 => 2, ... } */ $ul.find('li').each(function(idx, li) { title = li.firstChild.title; if(title == target) { $(li).remove(); } else { if(seen[title]) { $(li).remove(); seen[title] ++; } else { seen[title] = 1; } } }); /* Show the number of repeats for each line */ $ul.find('li').each(function(idx, li) { title = li.firstChild.title; if(seen[title] > 1) { $(li).append($('<span/>') .addClass('mw-whatlinkshere-repeats') .append(" (", $('<span/>') .addClass('mw-whatlinkshere-repeats-number') .append(seen[title]), " repeats)" )); } }); /* Sort by the number of repeats, then alphabetically */ $list = $ul.find('li').remove().sort(function(row1, row2) { r1 = $(row1).find('.mw-whatlinkshere-repeats-number').html() || 1; r2 = $(row2).find('.mw-whatlinkshere-repeats-number').html() || 1; if(r1 != r2) { return r2 - r1; } title1 = $(row1).find('a').attr('title'); title2 = $(row2).find('a').attr('title'); return title1.localeCompare(title2); }); $ul.append($list); }) ); /* Add some non-standard macros to Extension:SimpleMathJax */ var nonStandardMacros = { F: '\\mathbb{F}', /* a finite field */ HH: '\\mathcal{H}', /* a Hilbert space */ bszero: '\\boldsymbol{0}', /* vector of zeros */ bsone: '\\boldsymbol{1}', /* vector of ones */ bst: '\\boldsymbol{t}', /* a vector 't' */ bsv: '\\boldsymbol{v}', /* a vector 'v' */ bsw: '\\boldsymbol{w}', /* a vector 'w' */ bsx: '\\boldsymbol{x}', /* a vector 'x' */ bsy: '\\boldsymbol{y}', /* a vector 'y' */ bsz: '\\boldsymbol{z}', /* a vector 'z' */ bsDelta: '\\boldsymbol{\\Delta}', /* a vector '\Delta' */ E: '\\mathrm{e}', /* the exponential */ rd: '\\,\\mathrm{d}', /* roman d for use in integrals: $\int f(x) \rd x$ */ rdelta: '\\,\\delta', /* delta operator for use in sums */ rD: '\\mathrm{D}', /* differential operator D */ RR: '\\mathbb{R}', ZZ: '\\mathbb{Z}', NN: '\\mathbb{N}', QQ: '\\mathbb{Q}', CC: '\\mathbb{C}', FF: '\\mathbb{F}' }; mw.hook( 'wikipage.content' ).add( function ( $content ) { Object.assign( window.MathJax.tex.macros, nonStandardMacros ); } ); /* Google Analytics 4 */ window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} if ( // Not tracked: admin/bot users, anyone on login/logout pages. !(',' + mw.config.get('wgUserGroups').join(',') + ',').match(/,(sysop|bureaucrat|bot),/) && ['Userlogin', 'Userlogout', 'Preferences', 'Resetpass'].indexOf(mw.config.get('wgCanonicalSpecialPageName')) === -1 ) { gtag('js', new Date()); gtag('config', 'G-27TV985M46'); $('head').append($('<script/>').attr('async', 1).attr('src', 'https://www.googletagmanager.com/gtag/js?id=G-27TV985M46')); } /* /Google Analytics 4 */