Difference between revisions of "MediaWiki:Common.js"

From DKC Speedruns
Jump to: navigation, search
Line 88: Line 88:
 
}
 
}
 
*/
 
*/
 +
 +
window.onload = function () {
 +
if (window.location.pathname == "/Krow_bot" && window.location.hash.indexOf('access_token') > -1) {
 +
var token = window.location.hash.substring(14, 44);
 +
document.getElementById("prompt").innerHTML = "krow_b0t is now an editor for your channel! Copy and paste this access token into your chat to enable editor commands.";
 +
document.getElementById("token").innerHTML = "krow_" + token;
 +
} else {
 +
document.getElementById("prompt").innerHTML = "In order to use these commands, you must allow krow_b0t to be an editor of your channel. Visit this page and select 'Authorize' to give krow_b0t editor access to your channel.";
 +
}
 +
}

Revision as of 19:54, 29 March 2017

/* Any JavaScript here will be loaded for all users on every page load. */
/*
function parseResponse(data) {
    var ip = data.ip;
    console.log(ip);
}

var script = document.createElement('script');
script.src = 'https://ipinfo.io?callback=parseResponse';
document.getElementsByTagName('head')[0].appendChild(script);

window.onload = function() {

if (ip = '108.184.181.197' || '108.184.181.197') { // testing

    if (window.location.href.indexOf('action=edit') > -1) { // edit page
        localStorage.setItem('edit', 'yes');
        //localStorage.setItem('edit', 'no');
    };

    if (localStorage.getItem('edit') === 'yes') { // edit was made
    // check everything
        var links = [],
            lnk = document.links,
            images = [],
            img = document.images;
    
        for(var i = 0; i < lnk.length; i++) {
            links.push(lnk[i].getAttribute('href'));
        }
        
        for(var i = 0; i < img.length; i++) {
            images.push(img[i].getAttribute('src'));
        }
        
        //console.log(links);
        //console.log(images);
        
        links.forEach(function(link) {
            //console.log(link);
            if (link.includes('dkcspeedruns') && !link.includes('mediawiki')) {
                localStorage.setItem('status', 'fail');
                console.log('bad link found');
                if (link.includes('jpg') || link.includes('png') || link.includes('gif')) {
                    console.log('bad image link found');
                }
                var warning = document.createElement('div');
                warning.className = 'warning';
                var pathname = link.replace(/^.*\/\/[^\/]+/, '');
                //console.log(pathname);
                var oops = "<div><p>Oops! Looks like you've formatted something incorrectly. Please refer <a href=\"/Contributing\">here</a> for information on how to fix this error. Thanks! (Still need to make this say better stuff.)</p>";
                var error = "<p>Error: Internal Link<p></p><p>" + pathname + " " + link + "</div>";
                warning.innerHTML = oops + error;
                //console.log(link);
                //console.log(oops);
                //console.log(error);
                var body = document.getElementsByTagName('body')[0];
                body.appendChild(warning);
                warning.onclick = function() {
                    body.removeChild(warning);
                };
            } else {
                localStorage.setItem('status', 'pass');
                console.log('no bad links or image links found');
            }
        });
        
        images.forEach(function(image) {
            console.log(image);
            if (!image.includes('mediawiki')) {
                localStorage.setItem('status', 'fail');
                console.log('bad image found');
            } else {
                localStorage.setItem('status', 'pass');
                console.log('no bad images found');
            }
        });
        
        // do something after check
        if (localStorage.getItem('status') === 'pass') {
            //localStorage.setItem('edit', 'no');
        }
        
    } // user made an edit
    
} // testing

}
*/

window.onload = function () {
	if (window.location.pathname == "/Krow_bot" && window.location.hash.indexOf('access_token') > -1) {
		var token = window.location.hash.substring(14, 44);
		document.getElementById("prompt").innerHTML = "krow_b0t is now an editor for your channel! Copy and paste this access token into your chat to enable editor commands.";
		document.getElementById("token").innerHTML = "krow_" + token;
	} else {
		document.getElementById("prompt").innerHTML = "In order to use these commands, you must allow krow_b0t to be an editor of your channel. Visit this page and select 'Authorize' to give krow_b0t editor access to your channel.";
	}
}