Skip to content

Instantly share code, notes, and snippets.

View olemak's full-sized avatar
❄️
Crushing it

Ole Martin Kristiansen olemak

❄️
Crushing it
View GitHub Profile
@olemak
olemak / ready.js
Last active October 16, 2017 19:53
`JavaScript (ES2015) native "on document ready"
(() => { function fn() {
// "On document ready" commands:
console.log(document.readyState);
};
if (document.readyState != 'loading') {fn()}
else {document.addEventListener('DOMContentLoaded', fn)}
})();
@olemak
olemak / JavaScript: Copy Button for Defined Tags
Last active May 20, 2016 10:32
Adds a copy button after the tags you define (like code or pre). Clicking the button copies the preceeding element/tag text content to the OS clipboard.
function reactionaryCopybutton() {
var container = arguments.length <= 0 || arguments[0] === undefined ? document.getElementsByTagName('body')[0] : arguments[0];
var tags = arguments.length <= 1 || arguments[1] === undefined ? ['blockquote', 'pre', 'code'] : arguments[1];
var errorExplanation = 'Try to invoke reactionaryCopybutton() without parameters, or write something like this:';
var codesuggestion = '\tvar main = document.getElementById(\'#yourContentContainer\');\n\tvar tags = [\'pre\'];\n\treactionaryCopybutton(main, tags);';
try {
container.nodeType !== 1;
container['typeof'] !== 'undefined';
container !== 'NULL';
// Slap this into an SVG logo for a cool, changing look.
// src: http://www.gradient-animator.com/
background: linear-gradient(222deg, #41ceaa, #f3b902, #bc02f3, #e2ee43);
background-size: 800% 800%;
-webkit-animation: AnimationName 21s ease infinite;
-moz-animation: AnimationName 21s ease infinite;
animation: AnimationName 21s ease infinite;