/* GOGO JS by Gopal Othayoth (cerebraldatabank@gmail.com, https://cerebraldatabank.neocities.org/)
* Version: v24.6.0
* Last Updated: 2023-07-17
* This code may not be distributed without express written/typed permission by Gopal Othayoth (cerebraldatabank@gmail.com).
* The GOGO JS API was made by Gopal Othayoth (cerebraldatabank@gmail.com). All rights reserved.
* All Data URI images are also created by Gopal Othayoth and can be treated as part of the GOGO JS API
*/
var gogo = {};
var $$ = gogo;
if (localStorage.getItem("gogo:storagePrefs")) {}
else {
localStorage.setItem("gogo:storagePrefs", JSON.stringify({
storage: {
all: true,
choiceRemembrance: true,
viewedRemembrance: true
}
}));
}
gogo.storage = {
setItem: function(key, val) {
if (JSON.parse(localStorage.getItem("gogo:storagePrefs")).all) {}
else if (JSON.parse(localStorage.getItem("gogo:storagePrefs")).viewedRemembrance == false && key.startsWith("hasViewedInfobar")) {}
else if (JSON.parse(localStorage.getItem("gogo:storagePrefs")).viewedRemembrance == false && key.startsWith("noshow")) {}
else if (JSON.parse(localStorage.getItem("gogo:storagePrefs")).choiceRemembrance == false && key.startsWith("settings")) {}
else if (JSON.parse(localStorage.getItem("gogo:storagePrefs")).choiceRemembrance == false && key.startsWith("choice")) {}
else {
return localStorage.setItem(key, val);
}
},
getItem: function(key) {
if (JSON.parse(localStorage.getItem("gogo:storagePrefs")).all) {}
else if (JSON.parse(localStorage.getItem("gogo:storagePrefs")).viewedRemembrance == false && (key.startsWith("hasViewedInfobar") || key.startsWith("noshow"))) {}
else if (JSON.parse(localStorage.getItem("gogo:storagePrefs")).choiceRemembrance == false && (key.startsWith("choice") || key.startsWith("settings"))) {}
else {
return localStorage.getItem(key);
}
},
removeItem: function(key) {
return localStorage.removeItem(key);
},
clear: function() {
return localStorage.clear();
}
};
gogo.isOffline = "Unknown";
gogo.expendables = {ctx_menu: null, currentCtxLink: null, notification_container: null, notification_wrapper: null, infobar: null};
gogo.enableCustomContextMenu = true;
gogo.preventCustomContextMenuAutoFill = false;
gogo.disableCtxDisabling = true;
gogo.disableServiceWorkers = false;
gogo.feedbackEmail = "Unknown";
gogo.ctxMenuExtraLinks = {};
gogo.ctxMenuExtraActions = {};
gogo.customContextMenuActions = {};
gogo.specializedContextMenuActions = {};
gogo.noop = function() {return;}; /*"Noop" stands for "No Operation" (a useless function)*/
gogo.doNothing = function() {return;};
window.onerror = function() {return true;};
var $ = function(selector) {
return document.querySelectorAll(selector);
};
var $i = function(selector) {
return document.getElementById(selector);
};
var $t = function(selector) {
return document.getElementsByTagName(selector);
};
var $c = function(selector) {
return document.getElementsByClassName(selector);
};
var $q = function(selector) {
return document.querySelector(selector);
};
gogo.getURLParam = function(name, decode) {
var query = window.location.search.substring(1);
if (decode == true) {
query = String(decodeURIComponent(query)).replace(/\+/g, " ");
}
else {}
var vars = query.split("&");
for (let i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == name) {
return pair[1];
}
else {}
}
};
gogo.getURLQueryParam = function(name, decode) {return gogo.getURLParam(name, decode);};
gogo.blockDevtools = false;
gogo.devtoolsChecker = setInterval(function() {
if (gogo.blockDevtools == true) {
gogo.devtoolsResponse = 100;
gogo.beforeDebuggerStatement = new Date().getTime();
debugger;
gogo.afterDebuggerStatement = new Date().getTime();
if (gogo.afterDebuggerStatement - gogo.beforeDebuggerStatement > gogo.devtoolsResponse) {
document.body.innerHTML = "
DevTools detected
Your browser\'s developer tools are open. Please close them and reload the page.
";
}
else {}
}
else {}
}, 100);
gogo.capFirstLetter = function(stringToCap) {
return stringToCap.charAt(0).toUpperCase() + stringToCap.slice(1);
}
/*The below function, gogo.copyText(), will only work if run in a short running user-generated event handler.*/
gogo.copyText = function(textToCopy) {
var copyTextarea = document.createElement("textarea");
copyTextarea.style.transform = "translate(99999px, 99999px)";
document.body.appendChild(copyTextarea);
copyTextarea.value = textToCopy;
copyTextarea.select();
document.execCommand("copy");
copyTextarea.parentNode.removeChild(copyTextarea);
};
gogo.generateRandomIntIncl = function(minNum, maxNum) {
minNum = Math.ceil(minNum);
maxNum = Math.floor(maxNum);
return Math.floor(Math.random() * (maxNum - minNum + 1) + minNum);
console.warn("GOGO JS: Do not use the legacy gogo.generateRandomIntIncl(), use gogo.rand() where the third parameter is a Boolean indicating inclusiveness or not.");
};
gogo.rand = function(minNum, maxNum, isIncl) {
if (isIncl == false) {
minNum = Math.ceil(minNum);
maxNum = Math.floor(maxNum);
return Math.floor(Math.random() * (maxNum - minNum)) + minNum;
}
else {
minNum = Math.ceil(minNum);
maxNum = Math.floor(maxNum);
return Math.floor(Math.random() * (maxNum - minNum + 1) + minNum);
}
};
gogo.genRandomInt = function(minNum, maxNum, isIncl) {return gogo.rand(minNum, maxNum, isIncl);};
gogo.randBin = function() {
if (gogo.rand(0, 1) == 0) {
return false;
}
else {
return true;
}
};
gogo.genRandomBin = function() {return gogo.randBin();};
gogo.randStr = function(rStringLength, rStringParams, isAllowedChars) {
var allowedChars = "";
var rStrResult = "";
if (isAllowedChars) {
allowedChars = rStringParams;
}
else {
if (rStringParams.indexOf("a") > -1) {
allowedChars += "abcdefghijklmnopqrstuvwxyz";
}
else {}
if (rStringParams.indexOf("A") > -1) {
allowedChars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
else {}
if (rStringParams.indexOf("#") > -1) {
allowedChars += "0123456789";
}
else {}
if (rStringParams.indexOf("!") > -1) {
allowedChars += "!?/<>,.~`:;\"\'{}[]|\\+=_-@#$%^&*()";
}
else {}
if (rStringParams.indexOf("\\") > -1) {
allowedChars += rStringParams.search(/\{.\}/g);
}
else {}
}
for (var i = rStringLength; i > 0; --i) {
rStrResult += allowedChars[Math.floor(Math.random() * allowedChars.length)];
}
return rStrResult;
};
gogo.genRandomStr = function(rStringLength, rStringParams) {return gogo.randStr(rStringLength, rStringParams);};
gogo.decodeHTMLEntities = function(decodableText) {
var htxt = document.createElement("textarea");
htxt.innerHTML = decodableText;
return htxt.value;
};
gogo.syntaxHighlight = function(lang, starget) {
/*if (lang == "html") {
starget.innerHTML = String(starget.innerHTML).replace(/(.*)/g, "$1");
}
else*/ if (lang == "js") {
/*starget.innerHTML = String(starget.innerHTML).replace(/"(.*)"/g, "\"$1\"");*/
starget.innerHTML = String(starget.innerHTML).replace(/(var|this|if|else|for|\sin\s|typeof|Math|return|function|true|false|undefined)/g, "$1");
starget.innerHTML = String(starget.innerHTML).replace(/document/g, "document");
starget.innerHTML = String(starget.innerHTML).replace(/window/g, "window");
starget.innerHTML = String(starget.innerHTML).replace(/(getElementById|getElementsByTagName|setAttribute|alert|confirm|prompt|\.alert|\.confirm|\.prompt|getAttribute|querySelector|querySelectorAll|PI|search|substr|replace|createElement|removeChild|parentNode|childNodes|setAttribute|setProperty|match|sin|cos|tan|asin|acos|atan|sqrt|pow|assert|error||||||)/g, "$1");
}
else {
gogo.noop();
}
};
gogo.drag = function() {
return {
move: function(elem, xPos, yPos) {
elem.style.left = xPos + "px";
elem.style.top = yPos + "px";
},
startMoving: function(elem, container, ev) {
ev = ev || window.event;
var elemLeft = parseInt(elem.style.left) || ev.clientX;
var elemTop = parseInt(elem.style.top) || ev.clientY;
var topDiff = ev.clientY - elemTop;
var leftDiff = ev.clientX - elemLeft;
document.getElementById(container).style.cursor = "move";
window.onmousemove = function(ev) {
ev = ev || window.event;
var xPos = ev.clientX;
var yPos = ev.clientY;
var aX = xPos - leftDiff;
var aY = yPos - topDiff;
if (aY < 0) {aY = 0;}
elem.style.left = aX + "px";
elem.style.top = aY + "px";
};
},
stopMoving: function(container) {
document.getElementById(container).style.cursor = "default";
window.onmousemove = function() {};
}
};
}();
gogo.getBrowserName = function() {
var ua = navigator.userAgent,
tem,
M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(M[1])) {
tem = /\brv[ :]+(\d+)/g.exec(ua) || [];
return "IE " + (tem[1] || "");
}
if (M[1] === "Chrome") {
tem = ua.match(/\b(OPR|Edge)\/(\d+)/);
if (tem != null) {
return tem.slice(1).join(" ").replace("OPR", "Opera");
}
}
M = M[2] ? [M[1], M[2]]: [navigator.appName, navigator.appVersion, "-?"];
if ((tem = ua.match(/version\/(\d+)/i)) != null) {
M.splice(1, 1, tem[1]);
}
return M.join(" ");
};
gogo.getOSName = function(hide_arch) {
if (hide_arch) {
return navigator.oscpu.replace(/;\sWin64;\sx64|;\sWOW64/g, "");
}
else {
return navigator.oscpu;
}
};
gogo.decodeHTMLEntities = function(decodableText) {
var htxt = document.createElement("textarea");
htxt.innerHTML = decodableText;
return htxt.value;
}
gogo.loadScript = function(theurl, thecallback) {
return new Promise((resolve, reject) => {
var thehead = document.querySelector("head");
var thescript = document.createElement("script");
thescript.type = "text/javascript";
thescript.src = theurl;
thescript.onreadystatechange = thecallback;
thescript.onload = thecallback;
thehead.appendChild(thescript);
resolve(true);
});
}
gogo.getScript = gogo.loadScript;
gogo.getJSON = function(theurl, thecallback) {
var therequest = new XMLHttpRequest();
therequest.open("GET", theurl, true);
therequest.onreadystatechange = function() {
if (therequest.status >= 200 && therequest.status < 400) {}
else {
alert("AJAX JSON Request Error\n====================\n\nHTTP Status Code: " + therequest.status + "\nURL: " + theurl + "\nCallback: " + thecallback + "\n\n====================");
}
}
};
gogo.hash = function(hashfunc, hashstr) {
var buffer = new TextEncoder("utf-8").encode(hashstr);
return window.crypto.subtle.digest(hashfunc, buffer).then(hash => {
return gogo.rawHashToHex(hash);
});
};
gogo.rawHashToHex = function(buffer, hashfunc) {
var hashHexCodes = [];
var dataView = new DataView(buffer);
for (let i = 0; i < dataView.byteLength; i += 4) {
var currentVal = dataView.getUint32(i);
var currentStr = currentVal.toString(16);
var padding = "00000000";
var currentPaddedStr = (padding + currentStr).slice(-padding.length)
hashHexCodes.push(currentPaddedStr);
}
return hashHexCodes.join("").toLowerCase();
};
gogo.returnVal = function(val) {
return val;
}
gogo.returnPromise = function(promise) {
return promise().then(val => {return val});
};
gogo.expendables.obtainIP = function(json) {
return json.ip;
};
gogo.IP = "Unknown";
gogo.ip = gogo.IP;
gogo.ipAddress = gogo.IP;
gogo.loadScript("https://api.ipify.org/?format=jsonp&callback=gogo.expendables.IPObj%20%3D%20gogo.returnVal", function() {gogo.IP = gogo.expendables.obtainIP(gogo.expendables.IPObj);});
gogo.websiteRatings = {
"cerebraldatabank.neocities.org": "Safe",
"neuroncrossroads.neocities.org": "Safe",
"downloads.cnet.com": "Unsafe",
"download.com": "Unsafe"
};
/*window.addEventListener("offline", function() {
alert("WARNING!\n----------\n\nYou appear to be offline.");
gogo.isOffline = true;
});
window.addEventListener("online", function() {
if (gogo.isOffline == true) {
alert("NOTICE!\n----------\n\nYou are now online!");
gogo.isOffline = false;
}
else {}
});*/
window.addEventListener("contextmenu", function(event) {
if (gogo.enableCustomContextMenu != true || gogo.storage.getItem("gogo-disable-custom-context-menu") == "true") {}
else {
if (gogo.expendables.ctx_menu) {}
else {
gogo.expendables.ctx_menu = document.createElement("div");
}
event.preventDefault();
gogo.expendables.ctx_menu.classList.add("gogo-contextmenu");
gogo.expendables.ctx_menu.style.position = "fixed";
gogo.expendables.ctx_menu.style.left = event.clientX + "px";
gogo.expendables.ctx_menu.style.top = event.clientY + "px";
/*if (gogo.expendables.ctx_menu.style.top >= document.documentElement.getBoundingClientRect().height - gogo.expendables.ctx_menu.style.height) {
console.log(event.clientY + "\n" + gogo.expendables.ctx_menu.style.top + "\n" + document.documentElement.getBoundingClientRect().height + "\n" + gogo.expendables.ctx_menu.style.height);
gogo.expendables.ctx_menu.style.top -= gogo.expendables.ctx_menu.style.height;
}
else {}*/
var divposition = gogo.expendables.ctx_menu.getBoundingClientRect();
if (divposition.left + divposition.width < 0) {
/* element is off to the left of the view */
}
else {}
if (divposition.top + divposition.height < 0) {
/* element is off the top of the view */
}
else {}
if (divposition.top > window.innerHeight) {
/* element is off the bottom of the view */
gogo.expendables.ctx_menu.style.removeProperty("top");
gogo.expendables.ctx_menu.style.bottom = event.clientY + "px";
}
else {}
if (divposition.left > window.innerWidth) {
/* element is off to the right of the view */
}
else {}
gogo.expendables.ctx_menu.style.zIndex = 1000000;
gogo.expendables.ctx_menu.setAttribute("id", "gogo_ctx_menu");
gogo.expendables.ctx_menu.onclick = function() {document.getElementById("gogo_ctx_menu").style.display = "none";};
document.body.appendChild(gogo.expendables.ctx_menu);
gogo.expendables.ctx_menu.style.display = "block";
currentEventTarget = event.target;
if (gogo.preventCustomContextMenuAutoFill == true) {}
else {
document.getElementById("gogo_ctx_menu").innerHTML = "Reload Page
Ignore Cache and Reload Page
";
if (gogo.feedbackEmail != ("Unknown" || undefined || null)) {
document.getElementById("gogo_ctx_menu").innerHTML += "Provide Feedback...
";
}
else {}
if (gogo.disableCtxDisabling == true) {}
else {
document.getElementById("gogo_ctx_menu").innerHTML += "Disable Custom Context Menu
Disable Forever
";
}
if (gogo.preventCustomContextMenuAutoFill != true && event.target.tagName.toLowerCase() == "a") {
gogo.expendables.currentCtxLink = event.target;
document.getElementById("gogo_ctx_menu").innerHTML = "Open Link
Open Link in New Tab
Copy Link Address
" + document.getElementById("gogo_ctx_menu").innerHTML;
}
else {}
if (gogo.preventCustomContextMenuAutoFill != true && event.target.tagName.toLowerCase() == "input" && event.target.type == "password") {
gogo.expendables.currentCtxPwdField = event.target;
document.getElementById("gogo_ctx_menu").innerHTML = "Show Password
" + document.getElementById("gogo_ctx_menu").innerHTML;
}
else {}
if (gogo.preventCustomContextMenuAutoFill != true && gogo.getSelection() != "") {
document.getElementById("gogo_ctx_menu").innerHTML = "Search Google for \"" + gogo.shortenText(gogo.getSelection(), 10) + "\"
" + document.getElementById("gogo_ctx_menu").innerHTML;
document.getElementById("gogo_ctx_menu").innerHTML = "Copy
" + document.getElementById("gogo_ctx_menu").innerHTML;
}
else {}
if (gogo.preventCustomContextMenuAutoFill != true && event.target.tagName.toLowerCase() == "img") {
gogo.expendables.currentCtxLink = event.target;
document.getElementById("gogo_ctx_menu").innerHTML = "View Image
Open Image in New Tab
Copy Image Location
Copy Image Location as Data URI
Download Image
" + document.getElementById("gogo_ctx_menu").innerHTML;
console.log(currentEventTarget.src);
gogo.toDataURI(currentEventTarget.src, result => {console.log("result: " + result); currentDataURI = result; console.log("currentDataURI: " + currentDataURI);});
}
else {}
if (gogo.preventCustomContextMenuAutoFill != true && event.target.tagName.toLowerCase() == "summary") {
document.getElementById("gogo_ctx_menu").innerHTML = "Expand All
" + document.getElementById("gogo_ctx_menu").innerHTML;
}
else {}
if (Object.keys(gogo.ctxMenuExtraActions).length > 0) {
for (gogo.expendables.aaa = 0; gogo.expendables.aaa < Object.keys(gogo.ctxMenuExtraActions).length; gogo.expendables.aaa++) {
gogo.expendables.bbb = document.getElementById("gogo_ctx_menu");
gogo.expendables.bbb.innerHTML += "" + Object.keys(gogo.ctxMenuExtraActions)[gogo.expendables.aaa] + "
";
gogo.expendables.bbb.onclick = Object.values(gogo.ctxMenuExtraActions)[gogo.expendables.aaa];
}
}
else {}
if (Object.keys(gogo.ctxMenuExtraLinks).length > 0) {
for (gogo.expendables.aaa2 = 0; gogo.expendables.aaa2 < Object.keys(gogo.ctxMenuExtraLinks).length; gogo.expendables.aaa2++) {
document.getElementById("gogo_ctx_menu").innerHTML += "" + Object.keys(gogo.ctxMenuExtraLinks)[gogo.expendables.aaa2] + "
";
}
}
else {}
}
if (Object.keys(gogo.customContextMenuActions).length > 0) {
document.getElementById("gogo_ctx_menu").innerHTML = "";
for (gogo.expendables.aaa3 = 0; gogo.expendables.aaa3 < Object.keys(gogo.customContextMenuActions).length; gogo.expendables.aaa3++) {
gogo.expendables.bbb2 = document.createElement("div");
gogo.expendables.bbb2.innerHTML = Object.keys(gogo.customContextMenuActions)[gogo.expendables.aaa3];
document.getElementById("gogo_ctx_menu").appendChild(gogo.expendables.bbb2);
gogo.expendables.bbb2.onclick = Object.values(gogo.customContextMenuActions)[gogo.expendables.aaa3];
}
}
else {}
Object.keys(gogo.specializedContextMenuActions).forEach(function(k, ki) {
/*console.log(event + "\n" + k + "\n" + String(event.target.getAttribute("data-gogo-ctx-id") == k) + "\n\n" + ki);*/
if (event.target.getAttribute("data-gogo-ctx-id") == k) {
for (let si = 0; si < gogo.specializedContextMenuActions[k].length; si++) {
debugger;
document.getElementById("gogo_ctx_menu").insertAdjacentHTML("afterbegin", "" + gogo.specializedContextMenuActions[k][si].name + "
");
/*console.log(document.getElementById("gogo_ctx_menu").firstChild.onclick);*/
document.getElementById("gogo_ctx_menu").firstChild.onclick = eval("() => {gogo.specializedContextMenuActions[\"" + String(k) + "\"][" + String(Number(si)) + "].action(currentEventTarget);};");
/*console.log("k: " + k);
console.log("si: " + si);
console.log(gogo.specializedContextMenuActions[k]);
console.log(gogo.specializedContextMenuActions[k][si]);
console.log(gogo.specializedContextMenuActions[k][si].action);
console.log(document.getElementById("gogo_ctx_menu").firstChild);
console.log(document.getElementById("gogo_ctx_menu").firstChild.onclick);*/
}
}
else {}
});
/*currentEventTarget = event.target;
console.log(currentEventTarget);*/
return false;
}
});
var currentEventTarget = null;
var currentDataURI = null;
window.addEventListener("click", function(event) {
if (document.getElementById("gogo_ctx_menu").contains(event.target) != true) {
document.getElementById("gogo_ctx_menu").style.display = "none";
}
else {}
});
gogo.speakText = function(textToSpeak) {
var u = new SpeechSynthesisUtterance();
u.voice = speechSynthesis.getVoices().filter(function(voice) {return voice.name == "mike";})[0];
u.text = textToSpeak;
u.lang = "en-US";
u.volume = 1;
u.rate = 0.7;
u.pitch = 1.55;
speechSynthesis.speak(u);
}
gogo.decimalToHex = function(num) {
return ("0" + (Number(num).toString(16))).slice(-2).toUpperCase();
}
gogo.hexToRGBA = function(hex, alpha) {
var r = parseInt(hex.slice(1, 3), 16),
g = parseInt(hex.slice(3, 5), 16),
b = parseInt(hex.slice(5, 7), 16);
if (alpha) {
return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
}
else {
return "rgb(" + r + ", " + g + ", " + b + ")";
}
}
gogo.hexToRGB = function() {};
gogo.getTime = function(showseconds) {
if (showseconds == false) {
return ("0" + (new Date()).getHours()).slice(-2) + ":" + ("0" + (new Date()).getMinutes()).slice(-2);
}
else {
return ("0" + (new Date()).getHours()).slice(-2) + ":" + ("0" + (new Date()).getMinutes()).slice(-2) + ":" + ("0" + (new Date()).getSeconds()).slice(-2);
}
};
gogo.getMilliseconds = function() {
return ("0" + (new Date()).getMilliseconds()).slice(-3);
};
gogo.showNotification = function(text, title, action) {
if (gogo.expendables.notification_container) {}
else {
gogo.expendables.notification_container = document.createElement("div");
gogo.expendables.notification_container.classList.add("gogo-notification-container");
document.body.appendChild(gogo.expendables.notification_container);
/*gogo.expendables.notification_container.outerHTML = "";*/
/*gogo.expendables.notification_wrapper = document.createElement("div");
gogo.expendables.notification_wrapper.classList.add("gogo-notification-wrapper");
gogo.expendables.notification_container.appendChild(gogo.expendables.notification_wrapper);*/
}
var not = document.createElement("div");
not.innerHTML = "" + title + "
" + text + "
×
";
not.classList.add("gogo-notification");
if (action) {
not.onclick = function(evt) {if (evt.target == this.children[2]) {} else {action(); this.parentNode.removeChild(this);}};
}
else {
not.onclick = function(evt) {if (evt.target == this.children[2]) {} else {this.parentNode.removeChild(this);}};
}
gogo.expendables.notification_container.appendChild(not);
};
gogo.isNthChild = function(elem) {
Array(elem.parentNode.children).forEach(function(celem, nc) {
if (elem == celem) {
return nc;
}
else {
nc += 1;
}
});
}
/*Function.prototype.clone = function() {
var newfunc;
eval("newfunc=" + this.toString());
for (var key in this)
newfunc[key] = this[key];
return newfunc;
};*/
gogo.allowedMessageOrigins = [
"https://cerebraldatabank.neocities.org/"
];
window.addEventListener("message", function(event) {
if (gogo.allowedMessageOrigins.indexOf(event.origin.toString()) < 0) {
console.group("Unauthorized cross-window message received");
console.warn("Unauthorized cross-window message received.");
console.log("Message origin: " + event.origin);
console.log("Message data (below):");
console.log(event.data);
console.groupEnd();
return;
}
else {
console.group("Cross-window message received");
console.log("Allowed cross-window message received.");
console.log("Message origin: " + event.origin);
console.log("Message data (below):");
console.log(event.data);
console.groupEnd();
}
});
/*gogo.openNewFile = function(filecontent, mimetype) {
if (mimetype) {
document.open("data:" + mimetype + "," + encodeURIComponent(filecontent));
}
else {
document.open("data:application/octet-stream," + encodeURIComponent(filecontent));
}
}*/
gogo.saveXMLFile = function(xmltext, filename) {
var pom = document.createElement("a");
var bb = new Blob([xmltext], {type: "text/plain"});
pom.setAttribute("href", window.URL.createObjectURL(bb));
pom.setAttribute("download", filename);
pom.dataset.downloadurl = ["text/plain", pom.download, pom.href].join(":");
pom.draggable = true;
pom.classList.add("dragout");
pom.click();
}
gogo.getDate = function(format, shortenyear) {
var thedate = new Date();
var day = String(thedate.getDate());
var month = String(thedate.getMonth() + 1);
if (shortenyear == true) {
var year = String(thedate.getFullYear()).substr(-2);
}
else {
var year = String(thedate.getFullYear());
}
if (format == "slash") {
return month.padStart(2, "0") + "/" + day.padStart(2, "0") + "/" + year.padStart(2, "0");
console.log(year);
}
else if (format == "dash") {
return month.padStart(2, "0") + "-" + day.padStart(2, "0") + "-" + year.padStart(2, "0");
}
else if (format == "string") {
return year.padStart(2, "0") + month.padStart(2, "0") + day.padStart(2, "0");
}
else {
return month.padStart(2, "0") + "/" + day.padStart(2, "0") + "/" + year.padStart(2, "0");
}
};
/*document.querySelectorAll("[data-closedtext]").forEach(function(elem) {
elem.addEventListener("click", function() {elem.querySelector("summary").innerHTML});
});*/
gogo.downloadFile = function(fileurl, filename) {
var dldElem = document.createElement("a");
dldElem.href = fileurl;
if (filename == (null || undefined || "")) {
/*dldElem.setAttribute("download", "");*/
dldElem.download = "";
}
else {
/*dldElem.setAttribute("download", filename);*/
dldElem.download = filename;
}
dldElem.style.display = "none";
document.body.appendChild(dldElem);
dldElem.click();
dldElem.parentNode.removeChild(dldElem);
};
gogo.showInfobar = function(infobarText, infobarOptions) {
if (gogo.storage.getItem("gogo-disableInfoBar") == "true") {}
else {
/*if (gogo.expendables.infobar) {}
else {
gogo.expendables.infobar = document.createElement("div");
}
gogo.expendables.infobar.classList.add("gogo-infobar");
gogo.expendables.infobar.innerHTML = gogo.infobarText;
document.body.prepend(gogo.expendables.infobar);*/
/*if (document.querySelector("gogo-infobar")) {
document.querySelector("gogo-infobar").outerHTML = "" + infobarText + "×
";
}
else {
document.body.insertAdjacentHTML("afterbegin", "" + infobarText + "×
");
}*/
/*if (document.querySelector("gogo-infobar")) {
document.querySelector("gogo-infobar").outerHTML = "" + infobarText + " (Dismiss)
";
}
else {
document.body.insertAdjacentHTML("afterbegin", "" + infobarText + " (Dismiss)
");
}*/
if (infobarOptions.type) {
if (infobarOptions.id == (null || undefined || "")) {
document.body.insertAdjacentHTML("afterbegin", "" + infobarText + " (Dismiss)
");
}
else {
if (gogo.storage.getItem("hasViewedInfobar:" + infobarOptions.id) == "true" || sessionStorage.getItem("hasViewedInfobar:" + infobarOptions.id) == "true") {}
else {
document.body.insertAdjacentHTML("afterbegin", "" + infobarText + " (Dismiss)
");
}
}
}
else {
if (infobarOptions.id == (null || undefined || "")) {
document.body.insertAdjacentHTML("afterbegin", "" + infobarText + " (Dismiss)
");
}
else {
if (gogo.storage.getItem("hasViewedInfobar:" + infobarOptions.id) == "true" || sessionStorage.getItem("hasViewedInfobar:" + infobarOptions.id) == "true") {}
else {
document.body.insertAdjacentHTML("afterbegin", "" + infobarText + " (Dismiss)
");
}
}
}
}
}
gogo.clearAllData = function() {
localStorage.clear();
sessionStorage.clear();
document.cookie.split(";").forEach(function(c) {
document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/");
});
};
gogo.getSelection = function() {
var text = "";
var activeEl = document.activeElement;
var activeElTagName = activeEl ? activeEl.tagName.toLowerCase() : null;
if (
(activeElTagName == "textarea") || (activeElTagName == "input" &&
/^(?:text|search|password|tel|url)$/i.test(activeEl.type)) &&
(typeof activeEl.selectionStart == "number")
) {
text = activeEl.value.slice(activeEl.selectionStart, activeEl.selectionEnd);
} else if (window.getSelection) {
text = window.getSelection().toString();
}
return text;
};
gogo.shortenText = function(textToShorten, maxLength) {
if (textToShorten.length > maxLength) {
var newText = textToShorten.substring(0, maxLength) + "...";
console.log(textToShorten + "\n" + maxLength);
return newText;
}
else {
return textToShorten;
}
};
gogo.toDataURI = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function() {
var reader = new FileReader();
reader.onloadend = function() {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open("GET", url);
xhr.responseType = "blob";
xhr.send();
}
gogo.getComplementaryNucleotideStrand = function(strand, type) {
if (type == "RNA") {
return strand.replace(/A/gi, "X").replace(/U/gi, "A").replace(/X/gi, "U").replace(/C/gi, "Y").replace(/G/gi, "C").replace(/Y/gi, "G");
}
else {
return strand.replace(/A/gi, "X").replace(/T/gi, "A").replace(/X/gi, "T").replace(/C/gi, "Y").replace(/G/gi, "C").replace(/Y/gi, "G");
}
};
gogo.toNA = function(strand, resultType) {
if (resultType == "DNA") {
return strand.replace(/U/g, "T").replace(/u/g, "t");
}
else if (resultType == "RNA") {
return strand.replace(/T/g, "U").replace(/t/g, "u");
}
else {
console.error("Illegal type or no type provided for nucleic acid conversion.");
}
};
gogo.makeAminoAcid = function(strand, type) {
if (type == "mRNA") {
var mRNA = strand;
}
else {
}
};
gogo.addURLParam = function(URL, paramKey, paramValue) {
if (URL.indexOf("?") > -1) {
return URL + "&" + paramKey + "=" + encodeURIComponent(paramValue);
}
else {
return URL + "?" + paramKey + "=" + encodeURIComponent(paramValue);
}
};
gogo.simulateKeypress = function(thekey) {
var evt = new Event("keydown");
evt.key = "a"; // just enter the char you want to send
evt.keyCode = evt.key.charCodeAt(0);
evt.which = evt.keyCode;
evt.altKey = false;
evt.ctrlKey = false;
evt.shiftKey = false;
evt.metaKey = false;
evt.bubbles = true;
document.dispatchEvent(evt);
}
document.querySelectorAll("[data-gogo-unread]").forEach(elem => {
elem.addEventListener("click", event => {
this.removeAttribute("data-gogo-unread");
});
});
gogo.genID = function(idLength = 30) {
var idArr = new Uint8Array(idLength / 2);
window.crypto.getRandomValues(idArr);
return String(Array.from(idArr, num => {return ("0" + num.toString(16)).substr(-2);}).join("")).toUpperCase();
};
gogo.generateID = function(idLength) {return gogo.genID(idLength);};
/*gogo.Stopwatch = function(hr, min, sec) {
this.initialHours = hr;
this.initialMinutes = min;
this.initialSeconds = sec;
this.initialTime = String(hr).padStart(2, "0") + ":" + String(min).padStart(2, "0") + ":" + String(sec).padStart(2, "0");
this.currentHours = hr;
this.currentMinutes = min;
this.currentSeconds = sec;
this.now = String(hr).padStart(2, "0") + ":" + String(min).padStart(2, "0") + ":" + String(sec).padStart(2, "0");
setInterval(function() {alert(this.now);}, 1000);
};*/
window.addEventListener("load", event => {
document.querySelectorAll("input[data-gogo-deselectable]").forEach(radiobtn => {
radiobtn.addEventListener("mousedown", event => {
if (this.checked) {
this.onclick = function() {this.checked = false};
}
else {
this.onclick = null
}
});
})
});
gogo.Countdown = function(endDate, ctdwnId) {};
gogo.wait = function(time) {
return new Promise(resolve => setTimeout(resolve, time));
};
gogo.convertms = function convertMS(timeInms) {
var days, hrs, min, sec;
sec = Math.floor(timeInms / 1000);
min = Math.floor(sec / 60);
sec = sec % 60;
hrs = Math.floor(min / 60);
min = min % 60;
days = Math.floor(hrs / 24);
hrs = hrs % 24;
return days + "d" + hrs + "h" + min + "m" + sec + "s";
};
gogo.countDown = function(theid, thedate, theelemid) {
var countDownDate = new Date(thedate).getTime();
eval(`var countDownFunction_${theid} = setInterval(function() {
var now_${theid} = new Date().getTime();
var distance_${theid} = countDownDate - now;
var days_${theid} = Math.floor(distance_${theid} / (1000 * 60 * 60 * 24));
var hours_${theid} = Math.floor((distance_${theid} % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes_${theid} = Math.floor((distance_${theid} % (1000 * 60 * 60)) / (1000 * 60));
var seconds_${theid} = Math.floor((distance_${theid} % (1000 * 60)) / 1000);
document.getElementById("${theelemid}").innerHTML = days_${theid} + "d" + hours_${theid} + "h" + minutes_${theid} + "m" + seconds_${theid} + "s";
if (distance < 0) {
clearInterval(countDownFunction_${theid});
}
}, 1000);`);
};
gogo.concatJSON = function(firstObject, secondObject) {
for (var key in secondObject) {
firstObject[key] = secondObject[key];
}
return firstObject;
};
gogo.romanToDec = function(romanNum) {
const romanValues = {
I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000
};
let num = 0;
for (let i = 0; i < romanNum.length; i++) {
if (romanValues[romanNum.charAt(i)] < romanValues[romanNum.charAt(i + 1)]) {
num += romanValues[romanNum.charAt(i + 1)] - romanValues[romanNum.charAt(i)];
i += 1;
}
else {
num += romanValues[romanNum.charAt(i)];
}
}
return num;
};
for (let i = 0; i < document.querySelectorAll("[data-gogo-switch]"); i++) {
if (document.querySelectorAll("[data-gogo-switch]")[i].getAttribute("data-gogo-switch-colored")) {
document.querySelectorAll("[data-gogo-switch]")[i].onclick = "if (this.checked == true) {this.parentNode.} else {} " + new Function(document.querySelectorAll("[data-gogo-switch]")[i].getAttribute("data-gogo-switch-function"));
}
else {
throw 0;
}
}
gogo.suffix = function(num, decimals = 2, si = false, space = false) {
if (space) {
if (si) {
if (num >= 1e+24) {
return +(num / 1e+24).toFixed(decimals) + " Y";
}
else if (num >= 1e+21) {
return +(num / 1e+21).toFixed(decimals) + " Z";
}
else if (num >= 1e+18) {
return +(num / 1e+18).toFixed(decimals) + " E";
}
else if (num >= 1e+15) {
return +(num / 1e+15).toFixed(decimals) + " P";
}
else if (num >= 1e+12) {
return +(num / 1e+12).toFixed(decimals) + " T";
}
else if (num >= 1e+9) {
return +(num / 1e+9).toFixed(decimals) + " G";
}
else if (num >= 1e+6) {
return +(num / 1e+6).toFixed(decimals) + " M";
}
else if (num >= 1e+3) {
return +(num / 1e+3).toFixed(decimals) + " k";
}
else {
return num + " ";
}
}
else {
if (num >= 1e+24) {
return +(num / 1e+24).toFixed(decimals) + " Sp";
}
else if (num >= 1e+21) {
return +(num / 1e+21).toFixed(decimals) + " Sx";
}
else if (num >= 1e+18) {
return +(num / 1e+18).toFixed(decimals) + " Qt";
}
else if (num >= 1e+15) {
return +(num / 1e+15).toFixed(decimals) + " Qd";
}
else if (num >= 1e+12) {
return +(num / 1e+12).toFixed(decimals) + " T";
}
else if (num >= 1e+9) {
return +(num / 1e+9).toFixed(decimals) + " B";
}
else if (num >= 1e+6) {
return +(num / 1e+6).toFixed(decimals) + " M";
}
else if (num >= 1e+3) {
return +(num / 1e+3).toFixed(decimals) + " k";
}
else {
return num + " ";
}
}
}
else {
if (si) {
if (num >= 1e+24) {
return +(num / 1e+24).toFixed(decimals) + "Y";
}
else if (num >= 1e+21) {
return +(num / 1e+21).toFixed(decimals) + "Z";
}
else if (num >= 1e+18) {
return +(num / 1e+18).toFixed(decimals) + "E";
}
else if (num >= 1e+15) {
return +(num / 1e+15).toFixed(decimals) + "P";
}
else if (num >= 1e+12) {
return +(num / 1e+12).toFixed(decimals) + "T";
}
else if (num >= 1e+9) {
return +(num / 1e+9).toFixed(decimals) + "G";
}
else if (num >= 1e+6) {
return +(num / 1e+6).toFixed(decimals) + "M";
}
else if (num >= 1e+3) {
return +(num / 1e+3).toFixed(decimals) + "k";
}
else {
return num;
}
}
else {
if (num >= 1e+24) {
return +(num / 1e+24).toFixed(decimals) + "Sp";
}
else if (num >= 1e+21) {
return +(num / 1e+21).toFixed(decimals) + "Sx";
}
else if (num >= 1e+18) {
return +(num / 1e+18).toFixed(decimals) + "Qt";
}
else if (num >= 1e+15) {
return +(num / 1e+15).toFixed(decimals) + "Qd";
}
else if (num >= 1e+12) {
return +(num / 1e+12).toFixed(decimals) + "T";
}
else if (num >= 1e+9) {
return +(num / 1e+9).toFixed(decimals) + "B";
}
else if (num >= 1e+6) {
return +(num / 1e+6).toFixed(decimals) + "M";
}
else if (num >= 1e+3) {
return +(num / 1e+3).toFixed(decimals) + "k";
}
else {
return num;
}
}
}
};
gogo.genUUID = function() {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
};
gogo.dialog = function(content, title = "Notice", options = {}) {
if (!options.id) {
options.id = `gogo-dialog_${gogo.genUUID()}`;
}
else {}
document.body.insertAdjacentHTML("beforeend", ``);
document.getElementById(options.id).showModal();
};
gogo.playTone = function(frequency = 440, duration = 0.5, type = "sine", gain = 1) {
if (!gogo.audCtx) {
let AudioContext = window.AudioContext || window.webkitAudioContext;
gogo.audCtx = new AudioContext();
}
else {}
let oscillator = gogo.audCtx.createOscillator();
let gainNode = gogo.audCtx.createGain();
oscillator.connect(gainNode);
gainNode.connect(gogo.audCtx.destination);
oscillator.frequency.value = frequency;
gainNode.gain.value = gain;
oscillator.type = type;
oscillator.start(gogo.audCtx.currentTime);
oscillator.stop(gogo.audCtx.currentTime + duration);
}
gogo.romanNumerals = [
["M", 1000],
["CM", 900],
["D", 500],
["CD", 400],
["C", 100],
["XC", 90],
["L", 50],
["XL", 40],
["X", 10],
["IX", 9],
["V", 5],
["IV", 4],
["I", 1]
];
gogo.toRoman = function(aNum) {
let str = "";
for (let i in gogo.romanNumerals) {
let n = Math.floor(aNum / gogo.romanNumerals[i][1]);
aNum -= n * gogo.romanNumerals[i][1];
str += gogo.romanNumerals[i][0].repeat(n);
}
return str;
};
gogo.fromRoman = function(rNum) {
let num = 0;
let pairs = gogo.romanNumerals.filter(arr => arr[0].length == 2);
let singles = gogo.romanNumerals.filter(arr => arr[0].length == 1);
for (let i = 0; i < rNum.length; i++) {
let pairIndex = pairs.map(row => row[0]).indexOf(rNum[i] + rNum[i + 1]);
let singleIndex = singles.map(row => row[0]).indexOf(rNum[i]);
if (pairIndex > -1) {
num += pairs[pairIndex][1];
i++;
}
else if (singleIndex > -1) {
num += singles[singleIndex][1];
}
else {}
}
return num;
};
gogo.toBase64 = function(text) {
let encoder = new TextEncoder();
let bytes = encoder.encode(text);
return btoa(String.fromCharCode(...bytes));
};
gogo.fromBase64 = function(b64) {
let str = atob(b64);
let strLen = str.length;
let bytes = new Uint8Array(strLen);
for (let i = 0; i < strLen; i++) {
bytes[i] = str.charCodeAt(i);
}
let decoder = new TextDecoder("utf-8");
return decoder.decode(bytes);
};