«ميدياويكي:Common.js»: الفرق بين المراجعتين
(١٤ مراجعة متوسطة بواسطة مستخدمين اثنين آخرين غير معروضة) | |||
سطر ١: | سطر ١: | ||
/* الجافاسكريبت الموضوع هنا سيتم تحميله لكل المستخدمين مع كل تحميل للصفحة. */ | /* الجافاسكريبت الموضوع هنا سيتم تحميله لكل المستخدمين مع كل تحميل للصفحة. */ | ||
− | /* | + | /* ===================================== |
− | (function () { | + | FUNCTIONS DECLARATION |
+ | ======================================== */ | ||
+ | |||
+ | /* Favicon */ | ||
+ | function fixInsecureFavicon() { | ||
+ | document.querySelector('link[rel="shortcut icon"]').href = "https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico"; | ||
+ | } | ||
+ | |||
+ | /* TOP BUTTON */ | ||
+ | function addButtonTop() { | ||
+ | |||
+ | var contentText = document.querySelector("div#mw-content-text"); | ||
+ | |||
+ | if (contentText !== null) { | ||
+ | |||
+ | var divButtonTop = document.createElement("div"); | ||
+ | divButtonTop.classList.add("top-button"); | ||
+ | contentText.appendChild(divButtonTop); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | function buttonTop() { | ||
+ | |||
+ | var balise = document.querySelector("div#mw-page-header-links"); | ||
+ | var topButton = document.querySelector(".top-button"); | ||
+ | |||
+ | if (balise !== null) { | ||
+ | var options = { | ||
+ | root: null, | ||
+ | rootMargin: "0px", | ||
+ | threshold: 0, | ||
+ | }; | ||
+ | |||
+ | var observer = new IntersectionObserver(callback, options); | ||
+ | observer.observe(balise); | ||
+ | |||
+ | function callback(entries) { | ||
+ | entries.forEach(function(entry) { | ||
+ | if (entry.isIntersecting) { | ||
+ | topButton.classList.remove("show-button"); | ||
+ | } else { | ||
+ | topButton.classList.add("show-button"); | ||
+ | } | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | topButton.addEventListener("click", function(){ | ||
+ | document.documentElement.scrollTo({ | ||
+ | top: 0 | ||
+ | }); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | /* Cookies */ | ||
+ | function cookies() { | ||
var req = new XMLHttpRequest(); | var req = new XMLHttpRequest(); | ||
req.addEventListener('load', function (ev) { | req.addEventListener('load', function (ev) { | ||
سطر ١٦: | سطر ٧١: | ||
req.open('GET', "https://s3-static.geo.gfsrv.net/cookiebanner/version.json"); | req.open('GET', "https://s3-static.geo.gfsrv.net/cookiebanner/version.json"); | ||
req.send(); | req.send(); | ||
+ | } | ||
+ | |||
+ | /* ======================================= | ||
+ | GLOBAL FUNCTION | ||
+ | Executed once on page load | ||
+ | ========================================== */ | ||
+ | |||
+ | (function(){ | ||
+ | fixInsecureFavicon() | ||
+ | |||
+ | var loadScripts = document.querySelectorAll("div[data-load-javascript]"); | ||
+ | |||
+ | /* Load specific scripts when loading certain pages */ | ||
+ | if (loadScripts.length) { | ||
+ | var checkArray = new Array(0); | ||
+ | loadScripts.forEach(function(loadScript){ | ||
+ | script = loadScript.dataset["loadJavascript"]; | ||
+ | if (checkArray.indexOf(script) === -1) { | ||
+ | checkArray.push(script); | ||
+ | switch (script) { | ||
+ | case "tabber" : | ||
+ | mw.loader.load("/index.php?title=MediaWiki:Script/Tabber.js&action=raw&ctype=text/javascript"); | ||
+ | break; | ||
+ | case "skills" : // charge le script pour utiliser le simulateur de compétence | ||
+ | mw.loader.load("/index.php?title=MediaWiki:Script/Skills.js&action=raw&ctype=text/javascript"); | ||
+ | break; | ||
+ | case "modal" : // charge le script pour utiliser les modal | ||
+ | mw.loader.load("/index.php?title=MediaWiki:Script/Modal.js&action=raw&ctype=text/javascript"); | ||
+ | break; | ||
+ | case "switch" : // charge le script pour utiliser les changements de contenu | ||
+ | mw.loader.load("/index.php?title=MediaWiki:Script/Switch.js&action=raw&ctype=text/javascript"); | ||
+ | break; | ||
+ | case "loot" : | ||
+ | mw.loader.load("/index.php?title=MediaWiki:Script/Loot.js&action=raw&ctype=text/javascript"); | ||
+ | break; | ||
+ | case "map" : | ||
+ | mw.loader.load("/index.php?title=MediaWiki:Script/map.js&action=raw&ctype=text/javascript"); | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | addButtonTop(); | ||
+ | buttonTop(); | ||
+ | cookies() | ||
})(); | })(); |
المراجعة الحالية بتاريخ ١٥:٠٠، ٢٠ يناير ٢٠٢٣
/* الجافاسكريبت الموضوع هنا سيتم تحميله لكل المستخدمين مع كل تحميل للصفحة. */
/* =====================================
FUNCTIONS DECLARATION
======================================== */
/* Favicon */
function fixInsecureFavicon() {
document.querySelector('link[rel="shortcut icon"]').href = "https://gf1.geo.gfsrv.net/cdn98/191b803adbf82f4b8febe3a2c38c2c.ico";
}
/* TOP BUTTON */
function addButtonTop() {
var contentText = document.querySelector("div#mw-content-text");
if (contentText !== null) {
var divButtonTop = document.createElement("div");
divButtonTop.classList.add("top-button");
contentText.appendChild(divButtonTop);
}
}
function buttonTop() {
var balise = document.querySelector("div#mw-page-header-links");
var topButton = document.querySelector(".top-button");
if (balise !== null) {
var options = {
root: null,
rootMargin: "0px",
threshold: 0,
};
var observer = new IntersectionObserver(callback, options);
observer.observe(balise);
function callback(entries) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
topButton.classList.remove("show-button");
} else {
topButton.classList.add("show-button");
}
});
}
topButton.addEventListener("click", function(){
document.documentElement.scrollTo({
top: 0
});
});
}
}
/* Cookies */
function cookies() {
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();
}
/* =======================================
GLOBAL FUNCTION
Executed once on page load
========================================== */
(function(){
fixInsecureFavicon()
var loadScripts = document.querySelectorAll("div[data-load-javascript]");
/* Load specific scripts when loading certain pages */
if (loadScripts.length) {
var checkArray = new Array(0);
loadScripts.forEach(function(loadScript){
script = loadScript.dataset["loadJavascript"];
if (checkArray.indexOf(script) === -1) {
checkArray.push(script);
switch (script) {
case "tabber" :
mw.loader.load("/index.php?title=MediaWiki:Script/Tabber.js&action=raw&ctype=text/javascript");
break;
case "skills" : // charge le script pour utiliser le simulateur de compétence
mw.loader.load("/index.php?title=MediaWiki:Script/Skills.js&action=raw&ctype=text/javascript");
break;
case "modal" : // charge le script pour utiliser les modal
mw.loader.load("/index.php?title=MediaWiki:Script/Modal.js&action=raw&ctype=text/javascript");
break;
case "switch" : // charge le script pour utiliser les changements de contenu
mw.loader.load("/index.php?title=MediaWiki:Script/Switch.js&action=raw&ctype=text/javascript");
break;
case "loot" :
mw.loader.load("/index.php?title=MediaWiki:Script/Loot.js&action=raw&ctype=text/javascript");
break;
case "map" :
mw.loader.load("/index.php?title=MediaWiki:Script/map.js&action=raw&ctype=text/javascript");
break;
}
}
});
}
addButtonTop();
buttonTop();
cookies()
})();