Super simple event handling.
var handle = SUP.sub("points", function(data){
console.log("Oh sweet! I got "+data+" more points!");
});
SUP.pub("points",12);
function definedParameters(func) { | |
return func.toString().split("\n")[0].match(/\({1}.*\){1}/)[0].replace("(","").replace(")","").split(" ").join("").split(","); | |
} | |
// definedParameters(function (a,b,c){return a*b*c;}) returns ["a","b","c"]; |
var randID = (n)=>{var i,a="";for(i of new Array(n)){a+=("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890").charAt(~~(Math.random()*62));}return a;}; | |
//console.log(randID(6)); |
function random(a, b) { | |
if(Array.isArray(a)){ | |
return a[random(a.length)]; | |
} | |
if (typeof a === "object") { | |
var key = random(Object.keys(a)); | |
return b === "key" ? key : b === "both" ? {key:key,value:a[key]} : a[key]; | |
} | |
if (typeof a === "string" && !!a) { | |
return (a.toLowerCase() === "bool") ? (Math.floor(Math.random()*2) == 1) : random(a.split('')); |
function intToCCV(n,c) { // Character compression value | |
var c = c || "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!?"; | |
var r = [0,0,0,0]; | |
while (n - 64 >= 0) { | |
var pos = 2; | |
r[r.length-pos] += 1; | |
while (r[r.length-pos]==c.length) { | |
r[r.length-pos] = 0; | |
pos += 1; // Go to next position | |
if (r.length-pos in r) { // If that position is alread in the data |
const parseURL = function(char) { | |
var url = window.location.href, data = {}; | |
char = !!char ? char === "?" || char === "#" ? char : "check" : "check"; | |
if (char==="check") { | |
char = url.includes("?") ? "?" : url.includes("#") ? "#" : false; | |
if (char === false) { return false; } | |
} | |
url = url.substring(url.indexOf(char)+1,url.length); | |
if (url.includes("=")) { | |
var kv = url.split("&"); |
// Please note: while the returned hash would be a pain in the butt to decode, it does not ensure uniqueness for smaller strings. | |
// If you have a string at least 9 varying characters than it might be worth using. | |
function hash(s,base64){var a="";s.split('').forEach(e=>{a+=e.charCodeAt(0)>>2;});return !!base64?btoa(a):a;} | |
// Example: hash("mySuperSecretPassword",true); // Base64 | |
// Output: "MjczMDIwMjkyODI1MjgyMDI1MjQyODI1MjkyMDI0MjgyODI5MjcyODI1" | |
// Example: hash("mySuperSecretPassword"); | |
// Output: "273020292825282025242825292024282829272825" |
const AJAX = { | |
get: function(url,onGet) { | |
var xhttp = new XMLHttpRequest(); | |
xhttp.onreadystatechange = function() { | |
if (this.readyState == 4 && this.status == 200) { | |
onGet(this.responseText); | |
} | |
}; | |
xhttp.open("GET", url, true); | |
xhttp.send(); |