Difference between revisions of "MediaWiki:Common.js"
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
− | + | ||
− | //window.onload = function() { | + | function parseResponse(data) { |
− | + | var ip = data.ip; | |
− | + | console.log(ip); | |
− | + | } | |
− | + | ||
− | + | var script = document.createElement('script'); | |
− | + | script.src = 'http://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 | |
− | + | var submitButton = document.getElementById('wpSave'); | |
− | + | if(submitButton.addEventListener){ | |
− | + | submitButton.addEventListener("click", editMade, false); // new browser | |
− | + | } else if(submitButton.attachEvent){ | |
− | + | submitButton.attachEvent('click', editMade); // old browser | |
− | + | } | |
− | + | function editMade() { | |
− | + | 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 + " and " + link + " this.</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 | ||
+ | |||
} | } | ||
− |
Revision as of 02:41, 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 = 'http://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 var submitButton = document.getElementById('wpSave'); if(submitButton.addEventListener){ submitButton.addEventListener("click", editMade, false); // new browser } else if(submitButton.attachEvent){ submitButton.attachEvent('click', editMade); // old browser } function editMade() { 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 + " and " + link + " this.</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 }