This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// addAudioAndVideoShortcuts.js v1.1 | |
function addAudioAndVideoShortcuts(videos) { | |
if (typeof videos == 'undefined') { | |
// if defined | |
videos = document.querySelectorAll('audio:not(.key-shortcuts), video:not(.key-shortcuts)'); | |
} else if (typeof videos.length == 'undefined') { | |
// if node | |
videos = [videos]; | |
}; | |
videos.forEach(function(element) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// force-to-https.js v1 | |
function forceToHttps() { | |
if (location.protocol == 'http:') { | |
var linkHttps = location.href.replace('http', 'https'); | |
// via location | |
window.location.protocol = 'https:'; | |
window.location.href = linkHttps; | |
// via click | |
var a = document.createElement('a'); | |
a.setAttribute('href', linkHttps); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// uniqueObjs.js v1 | |
function uniqueObjs(array_) { | |
let compare = []; | |
let unique = []; | |
for (let i = 0; i < array_.length; i++) { | |
let thisObj = array_[i]; | |
let objAsString = JSON.stringify(thisObj).toLowerCase(); | |
if (compare.indexOf(objAsString) == -1) { | |
compare.push(objAsString); | |
unique.push(thisObj); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// throttle.js v1 | |
function throttle(func, wait) { | |
let wasCalled = false; | |
return function() { | |
if (!wasCalled) { | |
func(); | |
wasCalled = true; | |
setTimeout(function() { | |
wasCalled = false; | |
}, wait); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sort-json.js v1 | |
function sortJson(json, rules) { | |
let keys = Object.keys(json); | |
keys = keys.sort(typeof rules == 'function' ? rules() : rules); | |
let newJson = {}; | |
for (let i = 0; i < keys.length; i++) { | |
newJson[keys[i]] = json[keys[i]]; | |
}; | |
return newJson; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create-style.js v1 | |
function createStyle(cssString) { | |
const head = document.querySelector("head"), | |
style = document.createElement("style") | |
style.setAttribute("type", "text/css") | |
style.append(document.createTextNode(cssString)) | |
head.append(style) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// require-script.js v1 | |
function requireScript(url, scope = document.querySelector('head')) { | |
let script = document.createElement('script'); | |
get(url, function(xhr, data) { | |
script.innerHTML = data; | |
scope.appendChild(script); | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if-this-type-changes.js v1 | |
function ifThisTypeChanges(observed, callback, scope = window) { | |
let originalType = typeof scope[observed]; | |
let interval = setInterval(function() { | |
let newType = scope[observed]; | |
if (originalType != newType) { | |
clearInterval(interval); | |
callback(originalType, newType); | |
}; | |
}, 10); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get.js v1 | |
function get(url, callback) { | |
let request = new XMLHttpRequest(); | |
request.open('GET', url, true); | |
request.onload = function() { | |
callback(this, this.responseText); | |
}; | |
request.send(); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// capitalizeCase.js v1 | |
function capitalizeCase(text){ | |
return text.toLowerCase().replace(/\b[a-z]/g, function(value){ | |
return value.toUpperCase(); | |
}); | |
}; | |
String.prototype.capitalizeCase = function(){ | |
return capitalizeCase(this.toString()); | |
}; |