User:KokoroSenshi/common.js

//

// // External wiki redirect prompt // Test to make a dialogue box ask whether to redirect when sent to soft redirect pages // }}

var elemSoftRedirect = document.getElementById("softredirect"); console.log("|"); console.log("| "+elemSoftRedirect); if (elemSoftRedirect != null) { console.log("| This is a softredirect"); //Check if href exists (better save than sorry) ///console.log("| "+elemSoftRedirect.children[0]); //An alternative console.log("| "+elemSoftRedirect.firstElementChild); ///.firstChild should have(?) worked but didn't if (elemSoftRedirect.firstElementChild.hasAttribute("href")) { //Redirect confirmation box var URL = elemSoftRedirect.firstElementChild.getAttribute("href"); console.log("| "+URL); ConfirmRedirect } else { console.log("| There's no href"); }; } else { //If not a soft redirect page: console.log("| There's no softredirect"); }; console.log("|---");

function ConfirmRedirect{ console.log("| "+elemSoftRedirect.lastElementChild); console.log("| "+elemSoftRedirect.lastElementChild.innerHTML); var wikiName = elemSoftRedirect.lastElementChild.innerHTML; var reply = confirm("Redirect to the page"+ URL +" on "+ wikiName +"?"); //navigates to the page with 10s delay after the confirmation box setTimeout(function{   console.log("| Will redirect since no cancel (5s delay for redirect exists to confirm end of script in log)");    console.log("|---");    setTimeout(function{ window.location = URL; },(5 * 1000)); },(10 * 1000));  if(reply == true) { console.log("| Will redirect since clicked (5s delay for redirect exists to confirm end of script in log)"); console.log("|---"); setTimeout(function{     window.location = URL;    },(5 * 1000)); } else { console.log("| Not redirecting"); }; };

// // New Element test // Q: Do we want the blackout to cover the whole page, or not exist or leave the tools and top free? //   (the blackout will go over the preceding elements //

//document.getElementById("firstHeading").appendChild( newElem("div","opacity: 0.3;", "test1", "testElem1", null) ); //document.body.appendChild( newElem("div", "opacity: 0.3; position:fixed; top:0; left:0; width:100%; height:100%; background-color:#000;",null, "blackout", null) ); //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions#Function_parameters //http://stackoverflow.com/questions/12556229/do-i-need-to-pass-empty-parameters-to-a-javascript-function //so... have to put null if the param/arg is not the last ones (i.e. can't have ,, ) console.log("test1");

document.body.appendChild(  newElem("div", null, null, "aa", "mw-dismissable-notice") ); aa.appendChild(  newElem("div", "visibility: visible;", "toReplace", null, "mw-dismissable-notice-close") ); aa.firstChild.innerHTML = '[dismiss]' aa.appendChild(  newElem("div", null, null, "bb", "mw-dismissable-notice-body") ); bb.appendChild(  newElem("div", null, null, "Content", null) ); Content.appendChild(  newElem("div", "font-size:1.25em; text-align:center;background-color: #1d578b; padding:1em; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; -khtml-border-radius: 10px; -icab-border-radius: 10px; -o-border-radius: 10px", "haha", null, null) );

function newElem(type, style, text, id, clss){ var elem = document.createElement(type); elem.setAttribute("id",id); //console.log(text); if (style != null){ elem.setAttribute("style",style); }; if (text != null){ elem.textContent = text;          }; if (clss != null){ elem.setAttribute("class",clss);  }; return elem; };

// - // mw.config variables:  https://www.mediawiki.org/wiki/Manual:Interface/JavaScript#mw.config // -

consoleLoop([ debug, skin, stylepath, wgActionPaths, wgArticlePath, wgAvailableSkins, wgCaseSensitiveNamespaces, wgTitle, wgPageName, wgRelevantPageName ]);

function consoleLoop(array){ for(i=0;i<array.length;i++){ console.log(array[i]); }; };

// -

// // Automatic purge cache after new version upload aka reupload // Notes: Only perform if both this and the prev page were the reupload page then image page //       (in simplicity, just test for existence, though could be more efficient to match, then use the reupload page's image name //        in the search string for current url) // // Ref: document.referrer    https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer //     .search( ... )        https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search //     window.location.href  https://developer.mozilla.org/en-US/docs/Web/API/Window/location //     |                       https://developer.mozilla.org/en-US/docs/Web/API/Location //     wg stuff              https://www.mediawiki.org/wiki/Manual:Interface/JavaScript //     Reg Exp checker       http://www.regexr.com/ //     Tip: Use mozilla's scratchpad to debug js // // RegExp info: encase like so / ... / ; the operations typically operate on preceding char; \ to escape; ? ops to 0 or 1 of; //             * ops to 0 or more of;. represents most characters; {1,5} ops to 1 ot 5 of; //

console.log("|---"); console.log("| Purge cache if after reupload - START"); //Get previous page URL (then later test if reupload page) prevURL = document.referrer; //It's possible for prevURL to be empty if not navigated through links, e.g. address bar/back-button, etc., so check this first(?) if (prevURL != "") { console.log("| The previous URL is: "+prevURL); var prevRE = /https?:\/\/zeldawiki\.org\/index\.php\?title=Special:Upload&wpDestFile=.*\..{1,5}&wpForReUpload=1.*/; //Test if reupload page if (prevURL.search(prevRE) != -1){ //If url appears to be that of a reupload page: console.log("| The previous URL was a reuploading page"); //Get current URL + test if the image page that would follow after upload var thisURL = window.location.href; console.log("| This URL is: "+thisURL); var thisRE = /https?:\/\/zeldawiki.org\/File:.*\..{1,5}/; if (thisURL.search(thisRE) != -1) { console.log("| Time to redirect to http://zeldawiki.org/index.php?title=File: ... &action=purge then"); setTimeout(function{        window.location = "http://zeldawiki.org/index.php?title="+wgTitle+"&action=purge";      },(5 * 1000)); }; };  console.log("|---"); } else { console.log("| No previous url - END");console.log("|---"); };

// // Wikitext test // - // //

///console.log(" KokoroSenshi "); ///console.log("~"); ///console.log(" "); ///console.log("&#126;&#126;&#126;&#126;");