mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-12-12 14:35:35 +00:00
38 lines
724 B
JavaScript
38 lines
724 B
JavaScript
|
/* eslint-disable camelcase */
|
||
|
/**
|
||
|
* Initializes the Speculation Rules API for Citizen
|
||
|
*
|
||
|
* @return {void}
|
||
|
*/
|
||
|
function init() {
|
||
|
if (
|
||
|
!HTMLScriptElement.supports ||
|
||
|
!HTMLScriptElement.supports( 'speculationrules' )
|
||
|
) {
|
||
|
return;
|
||
|
}
|
||
|
const articlePath = mw.config.get( 'wgArticlePath' );
|
||
|
const article = articlePath.replace( /\$(1)/, '*' );
|
||
|
if ( !article ) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
const specRules = {
|
||
|
prerender: [ {
|
||
|
where: {
|
||
|
href_matches: article
|
||
|
},
|
||
|
eagerness: 'moderate'
|
||
|
} ]
|
||
|
};
|
||
|
|
||
|
const specScript = document.createElement( 'script' );
|
||
|
specScript.type = 'speculationrules';
|
||
|
specScript.textContent = JSON.stringify( specRules );
|
||
|
document.body.append( specScript );
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
init: init
|
||
|
};
|