Gebruiker:MakiBoy/Gadget-TestGadget.js: verschil tussen versies

Uit Wikikids
Naar navigatie springen Naar zoeken springen
(+ WikiStats)
(korte test)
Regel 1: Regel 1:
 +
/* jshint sub:true maxerr:100000 */
 
// Waarschuwing, heeft impact op alle bezoekers van WikiKids die minder dan 5 bijdragen hebben gedaan!     
 
// Waarschuwing, heeft impact op alle bezoekers van WikiKids die minder dan 5 bijdragen hebben gedaan!     
 
// Script geschreven door MakiBoy en Rots61
 
// Script geschreven door MakiBoy en Rots61
Regel 140: Regel 141:
 
function disableViewLoggingLC(timeLC){
 
function disableViewLoggingLC(timeLC){
 
mw.storage.set('disableLoggingLC', true, timeLC);
 
mw.storage.set('disableLoggingLC', true, timeLC);
 +
}
 +
 +
// Script dat ervoor zorgt dat alle pagina's met een categorie die bij een portaal hoort, automatisch een of meerdere TVB krijgen.
 +
// Geschreven door Rots61
 +
 +
var api;
 +
var catsOnPage = mw.config.get('wgCategories');
 +
var TVBportalen = [];
 +
var hoofdportalen = {};
 +
// Het hoofdportaal wordt niet getoond als een onderportaal dit heeft. 
 +
hoofdportalen["Nederland"] = ["Groningen (provincie)", "Friesland", "Gelderland", "Drenthe", "Flevoland", "Zuid-Holland", "Zeeland", "Noord-Holland", "Noord-Braband", "Limburg", "Utrecht (provincie)", "Overijssel"];
 +
hoofdportalen["België"] = ["Vlaanderen", "Wallonië"];
 +
hoofdportalen["Oceanië"] = ["Australië", "Nieuw-Zeeland"];
 +
hoofdportalen["Europa"] = ["Nederland", "België", "Frankrijk", "Denemarken", "Duitsland", "Griekenland", "Italië", "Luxemburg", "Oekraïne", "Oostenrijk", "Rusland", "Spanje", "Turkije", "Verenigd Koninkrijk", "Zweden", "Zwitserland", "Groningen (provincie)", "Friesland", "Gelderland", "Drenthe", "Flevoland", "Zuid-Holland", "Zeeland", "Noord-Holland", "Noord-Braband", "Limburg", "Utrecht (provincie)", "Overijssel", "Vlaanderen", "Wallonië"];
 +
hoofdportalen["Azië"] = ["China", "Japan", "Turkije", "Rusland", "Israël", "Filipijnen"];
 +
hoofdportalen["Afrika"] = ["Egypte", "Israël"];
 +
hoofdportalen["Noord-Amerika"] = ["Mexico", "Verenigde Staten", "Canada"];
 +
hoofdportalen["WikiKidsAtlas"] = ["Nederland", "België", "Frankrijk", "Denemarken", "Duitsland", "Griekenland", "Italië", "Luxemburg", "Oekraïne", "Oostenrijk", "Rusland", "Spanje", "Turkije", "Verenigd Koninkrijk", "Zweden", "Zwitserland", "Groningen (provincie)", "Friesland", "Gelderland", "Drenthe", "Flevoland", "Zuid-Holland", "Zeeland", "Noord-Holland", "Noord-Braband", "Limburg", "Utrecht (provincie)", "Overijssel", "Vlaanderen", "Wallonië", "China", "Japan", "Turkije", "Rusland", "Israël", "Filipijnen", "Egypte", "Mexico", "Verenigde Staten", "Canada"]; //Alle portalen eronder, als het goed is.
 +
hoofdportalen["Geschiedenis"] = ["Amerikaanse Burgeroorlog", "Eerste Wereldoorlog", "Egyptische Oudheid", "Franse Tijd", "Gouden Eeuw", "Oudheid", "Prehistorie", "Renaissance", "Romeinse Oudheid", "Van 1945 tot nu", "Griekse Oudheid", "Industriële Revolutie"];
 +
hoofdportalen["Wetenschap"] = ["Wiskunde", "Natuurkunde", "Scheikunde", "Biologie", "Coronavirus", "Menselijk lichaam", "Dierentuinen"];
 +
hoofdportalen["Verkeer & Vervoer"] = ["Openbaar vervoer", "Ruimtevaart", "Binnen- en zeevaart"];
 +
hoofdportalen["Biologie"] = ["Coronavirus", "Menselijk lichaam", "Dierentuinen"];
 +
 +
function TVBstart0() {
 +
    api = new mw.Api();
 +
    // Get the number of links
 +
    var temp;
 +
    for (var x = 0; x < catsOnPage.length; x++) {
 +
    api[x] = new mw.Api();
 +
        console.log('Begin');
 +
    TVBgetPageCountPT(x, "Categorie:" + catsOnPage[x]).then(console.log('Einde'));
 +
    }
 +
    setTimeout( function () { // The page count we got will be passed here.
 +
    if (TVBportalen.length !== 0) {
 +
    TVBportalen = TVBportalen.filter(function(item, pos, self) {
 +
    return self.indexOf(item) == pos;
 +
});
 +
if (TVBportalen.length > 1) { //Zorgt ervoor dat veel pagina's niet 'standaard' gekoppeld worden aan woordenschat.
 +
TVBportalen.splice(TVBportalen.indexOf('Woordenschat'), 1);
 +
}
 +
for (const property in hoofdportalen) {
 +
if (TVBportalen.includes(property)) {
 +
for (var a = 0; a < hoofdportalen[property].length; a++) {
 +
if (TVBportalen.includes(hoofdportalen[property][a])) {
 +
TVBportalen.splice(TVBportalen.indexOf(property), 1);
 +
}
 +
}
 +
}
 +
}
 +
    document.getElementById('TVBdemo').innerHTML = 'Alle pagina\'s in deze categorie tonen deze box(en): ';
 +
    for (var y = 0; y < TVBportalen.length; y++) {
 +
    document.getElementById('TVBdemo').innerHTML += TVBportalen[y] + ', ';
 +
    }
 +
    } else {
 +
    document.getElementById('TVBdemo').innerHTML = 'Geen boxen in deze categorie.' ;
 +
    }
 +
    }, 500);
 +
}
 +
 +
function TVBgetPageCountPT(apinr, pageName) {
 +
    return api[apinr].get({
 +
        action: "query",
 +
        prop: "linkshere",
 +
        titles: pageName,
 +
        lhlimit: "100",
 +
    }).then(function (data) {
 +
        temp = data.query.pages;
 +
        for (const property in temp) {
 +
        temp = temp[property].linkshere;
 +
        }
 +
        if (typeof temp === 'undefined') {
 +
            return 0;
 +
        } else {
 +
            var tempgetal = 0;
 +
            while (temp[tempgetal]) {
 +
                if (temp[tempgetal]["title"].startsWith("Gebruiker:Rots61/Portalen")) {
 +
                    TVBportalen.push(temp[tempgetal]["title"].split("/Portalen/").pop());
 +
                }
 +
                tempgetal += 1;
 +
            }
 +
            if (TVBportalen.length) {
 +
                return TVBportalen;
 +
            } else {
 +
                return 0;
 +
            }
 +
        }
 +
    });
 +
}
 +
 +
function TVBstartCats() {
 +
api[1] = new mw.Api();
 +
TVBgetPageCountPT(1, "Categorie:" + mw.config.get('wgTitle'));
 +
    setTimeout( function () { // The page count we got will be passed here.
 +
    if (TVBportalen.length !== 0) {
 +
    TVBportalen = TVBportalen.filter(function(item, pos, self) {
 +
    return self.indexOf(item) == pos;
 +
});
 +
if (TVBportalen.length > 1) { //Zorgt ervoor dat veel pagina's niet 'standaard' gekoppeld worden aan woordenschat.
 +
TVBportalen.splice(TVBportalen.indexOf('Woordenschat'), 1);
 +
}
 +
for (const property in hoofdportalen) {
 +
if (TVBportalen.includes(property)) {
 +
for (var a = 0; a < hoofdportalen[property].length; a++) {
 +
if (TVBportalen.includes(hoofdportalen[property][a])) {
 +
TVBportalen.splice(TVBportalen.indexOf(property), 1);
 +
}
 +
}
 +
}
 +
}
 +
    document.getElementById('TVBdemo').innerHTML = 'Alle pagina\'s in deze categorie tonen deze box(en): ';
 +
    for (var y = 0; y < TVBportalen.length; y++) {
 +
    document.getElementById('TVBdemo').innerHTML += TVBportalen[y] + ', ';
 +
    }
 +
    } else {
 +
    document.getElementById('TVBdemo').innerHTML = 'Geen boxen in deze categorie.' ;
 +
    }
 +
    }, 500);
 +
}
 +
 +
if (mw.config.get('wgNamespaceNumber') === 0 && mw.config.get('wgAction') === 'view') {
 +
if (navigator.userAgent === "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1") {
 +
document.getElementById('mw-content-text').outerHTML += '<div id="TVBdemo" style="display:none;"></div>';
 +
TVBstart0();
 +
}
 +
} else if (mw.config.get('wgNamespaceNumber') === 14 && mw.config.get('wgAction') === 'view') {
 +
if (navigator.userAgent === "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1") {
 +
document.getElementById('mw-content-text').outerHTML += '<div id="TVBdemo" style="display:none;"></div>';
 +
TVBstartCats();
 +
}
 
}
 
}

Versie van 4 mei 2023 18:27

/* jshint sub:true maxerr:100000 */
// Waarschuwing, heeft impact op alle bezoekers van WikiKids die minder dan 5 bijdragen hebben gedaan!    
// Script geschreven door MakiBoy en Rots61
// Een groot gedeelte van de code is een comment, deze code werd eerder gebruikt, en kan later ook gebruikt gaan worden. Verwijder deze code niet. 

function processview() {
	/* 
    if (mw.config.get('wgIsMainPage')) { //Hoofdpagina 
    	processchanges('hp','bodyContent');
    	//veranderd de "hp-newpagessection" zodat elke link hier eindigd op '?x=hp'  
    }
    if (mw.config.get('wgNamespaceNumber') === 14) {//Alle categorieën
    	processchanges('ca', 'bodyContent');
    	//veranderd de "bodyContent" van de categorieën zodat elke link eindigd op '?x=ca' 
    }
    */
    var object;
    var loggedPages = [1, 61839, 97842, 2429, 5756, 138368, 149810, 149866, 40669, 2430, 25376, 51736, 93624, 1295, 103753, 4112];
    if ((mw.config.get('wgArticleId') > 0 && (mw.config.get('wgNamespaceNumber') === 0 || ( mw.config.get('wgNamespaceNumber') === 14) ||mw.config.get('wgNamespaceNumber') === 100)) || (loggedPages.includes(mw.config.get('wgArticleId'))) && (mw.config.get('wgAction') == "view")) {
    	//Een bestaande pagina in de naamruimte 0 (artikels), 14 (categorie) of 100 (portaal). 
    	//Of een artikel met een ID in de array 'loggedPages'. 
    	//En alleen als de pagina wordt bekeken (dus niet als het wordt bewerkt of iets anders) 
	    object = {
	        title: mw.config.get('wgPageName'),
	        fromMainPage: false
	    };
	    /* 
		var visitedLC = JSON.parse(mw.storage.get('firstvisitLogCounter042023b'));
		if (visitedLC) {
		    if (visitedLC.includes(mw.config.get('wgArticleId'))) {
		    } else {
		        visitedLC.push(mw.config.get('wgArticleId'));
		        mw.storage.set('firstvisitLogCounter042023b', JSON.stringify(visitedLC), 604800); //7 dagen
		        object.fromMainPage = true;
		    }
		} else {
		    visitedLC = [];
		    visitedLC.push(mw.config.get('wgArticleId'));
		    mw.storage.set('firstvisitLogCounter042023b', JSON.stringify(visitedLC), 604800); //7 dagen
		    object.fromMainPage = true;
		}
	    // Voor week 16
	    object = {
	    	title: getTimestampInMinutesSinceBegin(),
	    	fromMainPage: false
	    };

	    // Detecteert de mobiele telefoon

	    if (navigator.userAgent.match(/Android/i)|| navigator.userAgent.match(/webOS/i)|| navigator.userAgent.match(/iPhone/i)
         || navigator.userAgent.match(/iPad/i)|| navigator.userAgent.match(/iPod/i)|| navigator.userAgent.match(/BlackBerry/i)
         || navigator.userAgent.match(/Windows Phone/i)) {
            object.fromMainPage = true;
        }
        */
        if (navigator.userAgent.match(/CRoS/i)) {
        	object.fromMainPage = true;	
        }
        /*
        if (mw.storage.get('firstvisitLogCounter042023a')) {
        } else {
        	mw.storage.set('firstvisitLogCounter042023a', 'waarde', 1209600); //14 dagen, 
        	object.fromMainPage = true;
        }
        if (mw.util.getParamValue('x') === "li") { //Links //hp = hoofdpagina //ca = categorie
	        object.fromMainPage = true;
	    }
	    */
	    /* Deze bezoeker is hier gekomen via wikikids. Intern
	    if ((new RegExp('(://wikikids.nl|://www.wikikids.nl)')).test(document.referrer)) {
	    	object.fromMainPage = true;
	    }
	    */
        fetch("https://wikikids.martvanweeghel.nl/pages",
            {
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json'
                },
                method: "POST",
                body: JSON.stringify(object)
            })
            .then(function (res) {})
            .catch(function (res) {});
    }
}

function processchanges(achtervoegsel, idplace) {
	// Veranderd alle links zodat er een achtervoegsel bijkomt waardoor we kunnen zien wie via links onze pagina's bezoekt. 
	// Niet in gebruik
	var anchors;
	if (idplace) {
		if (document.getElementById(idplace)) {
			anchors = document.getElementById(idplace).getElementsByTagName("a");
		} else {
			anchors = document.getElementsByTagName("a");
		}
	} else {
		anchors = document.getElementsByTagName("a");
	}
	for (var i = 0; i < anchors.length; i++) {
	    if (anchors[i].hash) {
	    } else if (anchors[i].href.includes('Gebruiker:')) {
	    } else if (anchors[i].href.includes('Overleg')) {
	    } else if (anchors[i].href.includes('index.php')) {
	    } else if (anchors[i].href.includes('Bestand:')) {
	    } else if (anchors[i].href.includes('Speciaal:')) {
	    } else if (anchors[i].href.includes('?')) {
	    } else if (!anchors[i].href.includes('wikikids')) {
	    } else {
	    	anchors[i].href = anchors[i].href + '?x=' + achtervoegsel; 
	    }
	}
}

$.when($.ready, mw.loader.using(['mediawiki.util'])).done(function () {
	// processchanges(li);
	var userAgent = navigator.userAgent; 
	if (!userAgent.includes('bot')) { //controleert of de bezoeker een bot is, dan wordt het niet gelogd. 
		if (!mw.config.get('wgIsRedirect')) {
			if (document.referrer !== document.URL) { //controleert of de vorige pagina niet hetzelfde is als deze pagina
				if (window.performance) {//controleert of het kan controleren
					if (performance.navigation.type != performance.navigation.TYPE_RELOAD) {//controleert of de pagina niet is herladen
						processview();
					}
				} else {
					processview();
				}
			}
		}
	}
});

if (mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgTitle') === "LogCounter" || (mw.config.get('wgTitle') === "Statistieken Wikikids" || (mw.config.get('wgTitle') === "Statistieken WikiKids" || mw.config.get('wgTitle') === "WikiStats")))) {
	document.getElementById('bodyContent').innerHTML = `Login om de statistieken te zien. <br><input type="password" id="passwordLC"><button onclick="if (document.getElementById('passwordLC').value === 'WikiStats') {
	disableViewLoggingLC(1800);
	alert('Herlaad de pagina');
	}">Login</button>`;
}

function disableViewLoggingLC(timeLC){
	mw.storage.set('disableLoggingLC', true, timeLC);
}

// Script dat ervoor zorgt dat alle pagina's met een categorie die bij een portaal hoort, automatisch een of meerdere TVB krijgen.
// Geschreven door Rots61

var api; 
var catsOnPage = mw.config.get('wgCategories');
var TVBportalen = [];
var hoofdportalen = {};
// Het hoofdportaal wordt niet getoond als een onderportaal dit heeft.  
hoofdportalen["Nederland"] = ["Groningen (provincie)", "Friesland", "Gelderland", "Drenthe", "Flevoland", "Zuid-Holland", "Zeeland", "Noord-Holland", "Noord-Braband", "Limburg", "Utrecht (provincie)", "Overijssel"];
hoofdportalen["België"] = ["Vlaanderen", "Wallonië"];
hoofdportalen["Oceanië"] = ["Australië", "Nieuw-Zeeland"];
hoofdportalen["Europa"] = ["Nederland", "België", "Frankrijk", "Denemarken", "Duitsland", "Griekenland", "Italië", "Luxemburg", "Oekraïne", "Oostenrijk", "Rusland", "Spanje", "Turkije", "Verenigd Koninkrijk", "Zweden", "Zwitserland", "Groningen (provincie)", "Friesland", "Gelderland", "Drenthe", "Flevoland", "Zuid-Holland", "Zeeland", "Noord-Holland", "Noord-Braband", "Limburg", "Utrecht (provincie)", "Overijssel", "Vlaanderen", "Wallonië"];
hoofdportalen["Azië"] = ["China", "Japan", "Turkije", "Rusland", "Israël", "Filipijnen"];
hoofdportalen["Afrika"] = ["Egypte", "Israël"];
hoofdportalen["Noord-Amerika"] = ["Mexico", "Verenigde Staten", "Canada"];
hoofdportalen["WikiKidsAtlas"] = ["Nederland", "België", "Frankrijk", "Denemarken", "Duitsland", "Griekenland", "Italië", "Luxemburg", "Oekraïne", "Oostenrijk", "Rusland", "Spanje", "Turkije", "Verenigd Koninkrijk", "Zweden", "Zwitserland", "Groningen (provincie)", "Friesland", "Gelderland", "Drenthe", "Flevoland", "Zuid-Holland", "Zeeland", "Noord-Holland", "Noord-Braband", "Limburg", "Utrecht (provincie)", "Overijssel", "Vlaanderen", "Wallonië", "China", "Japan", "Turkije", "Rusland", "Israël", "Filipijnen", "Egypte", "Mexico", "Verenigde Staten", "Canada"]; //Alle portalen eronder, als het goed is. 
hoofdportalen["Geschiedenis"] = ["Amerikaanse Burgeroorlog", "Eerste Wereldoorlog", "Egyptische Oudheid", "Franse Tijd", "Gouden Eeuw", "Oudheid", "Prehistorie", "Renaissance", "Romeinse Oudheid", "Van 1945 tot nu", "Griekse Oudheid", "Industriële Revolutie"];
hoofdportalen["Wetenschap"] = ["Wiskunde", "Natuurkunde", "Scheikunde", "Biologie", "Coronavirus", "Menselijk lichaam", "Dierentuinen"];
hoofdportalen["Verkeer & Vervoer"] = ["Openbaar vervoer", "Ruimtevaart", "Binnen- en zeevaart"];
hoofdportalen["Biologie"] = ["Coronavirus", "Menselijk lichaam", "Dierentuinen"];

function TVBstart0() {
    api = new mw.Api();
    // Get the number of links
    var temp;
    for (var x = 0; x < catsOnPage.length; x++) {
    	api[x] = new mw.Api();
        console.log('Begin');
    	TVBgetPageCountPT(x, "Categorie:" + catsOnPage[x]).then(console.log('Einde'));
    }
    setTimeout( function () { // The page count we got will be passed here.
    	if (TVBportalen.length !== 0) {
    		TVBportalen = TVBportalen.filter(function(item, pos, self) {
			    return self.indexOf(item) == pos;
			});
			if (TVBportalen.length > 1) { //Zorgt ervoor dat veel pagina's niet 'standaard' gekoppeld worden aan woordenschat. 
				TVBportalen.splice(TVBportalen.indexOf('Woordenschat'), 1);
			}
			for (const property in hoofdportalen) {
				if (TVBportalen.includes(property)) {
					for (var a = 0; a < hoofdportalen[property].length; a++) {
						if (TVBportalen.includes(hoofdportalen[property][a])) {
							TVBportalen.splice(TVBportalen.indexOf(property), 1);
						}
					}
				}
			}
    		document.getElementById('TVBdemo').innerHTML = 'Alle pagina\'s in deze categorie tonen deze box(en): ';
    		for (var y = 0; y < TVBportalen.length; y++) { 
    			document.getElementById('TVBdemo').innerHTML += TVBportalen[y] + ', ';
    		}
    	} else {
    		document.getElementById('TVBdemo').innerHTML = 'Geen boxen in deze categorie.' ;
    	}
    }, 500);
}

function TVBgetPageCountPT(apinr, pageName) {
    return api[apinr].get({
        action: "query",
        prop: "linkshere",
        titles: pageName,
        lhlimit: "100",
    }).then(function (data) {
        temp = data.query.pages;
        for (const property in temp) {
        	temp = temp[property].linkshere;
        }
        if (typeof temp === 'undefined') {
            return 0;
        } else {
            var tempgetal = 0;
            while (temp[tempgetal]) {
                if (temp[tempgetal]["title"].startsWith("Gebruiker:Rots61/Portalen")) {
                    TVBportalen.push(temp[tempgetal]["title"].split("/Portalen/").pop());
                }
                tempgetal += 1;
            }
            if (TVBportalen.length) {
                return TVBportalen;
            } else {
                return 0;
            }
        }
    });
}

function TVBstartCats() {
	api[1] = new mw.Api();
	TVBgetPageCountPT(1, "Categorie:" + mw.config.get('wgTitle'));
    setTimeout( function () { // The page count we got will be passed here.
    	if (TVBportalen.length !== 0) {
    		TVBportalen = TVBportalen.filter(function(item, pos, self) {
			    return self.indexOf(item) == pos;
			});
			if (TVBportalen.length > 1) { //Zorgt ervoor dat veel pagina's niet 'standaard' gekoppeld worden aan woordenschat. 
				TVBportalen.splice(TVBportalen.indexOf('Woordenschat'), 1);
			}
			for (const property in hoofdportalen) {
				if (TVBportalen.includes(property)) {
					for (var a = 0; a < hoofdportalen[property].length; a++) {
						if (TVBportalen.includes(hoofdportalen[property][a])) {
							TVBportalen.splice(TVBportalen.indexOf(property), 1);
						}
					}
				}
			}
    		document.getElementById('TVBdemo').innerHTML = 'Alle pagina\'s in deze categorie tonen deze box(en): ';
    		for (var y = 0; y < TVBportalen.length; y++) { 
    			document.getElementById('TVBdemo').innerHTML += TVBportalen[y] + ', ';
    		}
    	} else {
    		document.getElementById('TVBdemo').innerHTML = 'Geen boxen in deze categorie.' ;
    	}
    }, 500);
}

if (mw.config.get('wgNamespaceNumber') === 0 && mw.config.get('wgAction') === 'view') {
	if (navigator.userAgent === "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1") {
		document.getElementById('mw-content-text').outerHTML += '<div id="TVBdemo" style="display:none;"></div>';
		TVBstart0();
	} 
} else if (mw.config.get('wgNamespaceNumber') === 14 && mw.config.get('wgAction') === 'view') {
	if (navigator.userAgent === "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1") {
		document.getElementById('mw-content-text').outerHTML += '<div id="TVBdemo" style="display:none;"></div>';
		TVBstartCats();
	}
}
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=Gebruiker:MakiBoy/Gadget-TestGadget.js&oldid=784519"