Difference between revisions of "MediaWiki:Common.js"

From DKC Speedruns
Jump to: navigation, search
Line 13: Line 13:
  
 
if (ip = '108.184.181.197' || '108.184.181.197') { // testing
 
if (ip = '108.184.181.197' || '108.184.181.197') { // testing
 
    window.localStorage.clear();
 
  
 
     if (window.location.href.indexOf('action=edit') > -1) { // edit page
 
     if (window.location.href.indexOf('action=edit') > -1) { // edit page

Revision as of 03:30, 4 November 2016

/* 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

}