MediaWiki:Common.js : Différence entre versions
Ligne 25 : | Ligne 25 : | ||
var myElement = document.getElementById('mw-mywiki-example'); | var myElement = document.getElementById('mw-mywiki-example'); | ||
− | myElement.innerHTML = | + | myElement.innerHTML = '<button>hello</button>'; |
}()); | }()); | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | mw.loader.using( ['mediawiki.util', 'mediawiki.notify'], function () { | ||
+ | var extraCSS = mw.util.getParamValue( 'withCSS' ), | ||
+ | extraJS = mw.util.getParamValue( 'withJS' ); | ||
+ | |||
+ | if ( extraCSS ) { | ||
+ | // DONT REMOVE THIS IF (unless you are OK with CSRF attacks) | ||
+ | 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 ) { | ||
+ | // DONT REMOVE THIS IF (unless you are OK with XSS & CSRF attacks) | ||
+ | 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' } ); | ||
+ | } | ||
+ | } | ||
+ | }); |
Version du 10 septembre 2018 à 03:15
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
$('div#content').append( "<div class='content-footer'></div>" );
(function () {
var req = new XMLHttpRequest();
req.addEventListener('load', function (ev) {
if (this.status >= 200 && this.status < 300) {
var data = JSON.parse(this.responseText);
if (data.hasOwnProperty('version')) {
var gdpr = document.createElement("script");
gdpr.src = "https://s3-static.geo.gfsrv.net/cookiebanner/" + data.version + "/cookie.min.js";
document.head.appendChild(gdpr);
}
}
});
req.open('GET', "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
req.send();
})();
/* fonction pour créer des scripts persos */
(function jsperso() {
var myElement = document.getElementById('mw-mywiki-example');
myElement.innerHTML = '<button>hello</button>';
}());
mw.loader.using( ['mediawiki.util', 'mediawiki.notify'], function () {
var extraCSS = mw.util.getParamValue( 'withCSS' ),
extraJS = mw.util.getParamValue( 'withJS' );
if ( extraCSS ) {
// DONT REMOVE THIS IF (unless you are OK with CSRF attacks)
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 ) {
// DONT REMOVE THIS IF (unless you are OK with XSS & CSRF attacks)
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' } );
}
}
});