Skip to content

Instantly share code, notes, and snippets.

View netsi1964's full-sized avatar

Sten Hougaard netsi1964

View GitHub Profile
@netsi1964
netsi1964 / styleKeysSVG_chrome.js
Last active February 23, 2017 06:54
CSS SVG style properties , Chrome, Win. 7
var styleKeysSVG_chrome = [
"alignContent",
"alignItems",
"alignSelf",
"alignmentBaseline",
"all",
"animation",
"animationDelay",
"animationDirection",
"animationDuration",
@netsi1964
netsi1964 / FB_syntheticEvents.js
Last active January 7, 2017 06:56
Console: Get Facebook syntheticEvents
// Works at: https://facebook.github.io/react/docs/events.html
var domNodes = document.querySelectorAll('blockquote:nth-of-type(2)~ul li a');
var documentation = {};
Array.prototype.map.call(domNodes, function(ele) {
var name = ele.getAttribute('href').replace(/\#/ig, '');
var group = [];
var groupName = ele.innerText.replace(' Events','');
var h3 = document.querySelector(`[name="${name}"]`).parentNode;
var events = h3.nextElementSibling.nextElementSibling.querySelector('.language-text').innerText;
@netsi1964
netsi1964 / ChromeGetInfoAboutDimensionsjs
Last active December 6, 2016 10:33
Chrome Get dimensions info about elements from selector
var CSSSelector = window.localStorage.getItem('CSSSelector');
CSSSelector = prompt('Enter a selector', (window.localStorage.getItem('CSSSelector').toString()!=='null') ? CSSSelector : 'body');
window.localStorage.setItem('CSSSelector', CSSSelector);
var elements = document.querySelectorAll(CSSSelector);
var q = '`';
var report = `Selector: ${q}${CSSSelector}${(elements.length>1) ? ' (FOUND '+elements.length+' OCCURANCES)' : ''}${q}\n------------\n`;
if (elements.length>0) {
var element = elements[0];
var computedRules = window.getComputedStyle(element);
report+=`${q}${q}${q}\npadding: ${computedRules['padding']}\nmargin: ${computedRules['margin']}\nwidth:${computedRules['width']}\nheight:${computedRules['height']}\nbox-sizing:${computedRules['box-sizing']}\n${q}${q}${q}\n`;
@netsi1964
netsi1964 / ChromeGetDefinedRulesjs
Last active December 6, 2016 09:56
Chrome developer tool: Get defined rules for element as MarkDown table
var computedRules = window.getComputedStyle(document.body);
var md = '| Rule | Value |\n';
md+='|---------|---:|\n';
Array.from(computedRules).sort().map(function cssRule(rule) {
md+=`| ${rule.replace(/-/g,'\-')} | ${computedRules[rule].replace(/-/g,'\-')} |\n`;
});
copy(md)
@netsi1964
netsi1964 / ChromeGetUsedClassesAsCSS.js
Created December 1, 2016 10:56
Chrome developer toolbar util: Get CSS containing used CSS classes used below a specified selector
var allClasses = {}, css = '';
var startFrom = prompt('Where should I start?', '#application');
Array.prototype.forEach.call(document.querySelectorAll(startFrom+' *[class]'), function(element) {
Array.prototype.forEach.call(element.classList, function(className) {
if (!allClasses[className]) {
allClasses[className] = 0;
}
allClasses[className]++;
})
});
@netsi1964
netsi1964 / JSONselect.js
Created November 15, 2016 07:06
A basic JSON select function
// obj: JSON object
// selector: The path to the data you want to extract
function JSONselect(obj, selector) {
var levels = selector.split('.')
var object = obj;
levels.map(function(path) {
console.log(path)
object = object[path];
})
return object;
@netsi1964
netsi1964 / cleanReactHTML.js
Last active November 10, 2016 13:04
Function to get cleaned HTML from generated React HTML (for Chrome console)
function cleanReactHTML(html) {
var result = html.replace(/data-reactid="[\.\d:\D]{1,23}"/g,'');
result = result.replace(/data-reactroot="[\.\d:\D]{1,23}"/g,'');
result = result.replace(/<!--[\s\S]*?-->/g,'');
return result
}
copy(cleanReactHTML(document.querySelector('.app').innerHTML));
@netsi1964
netsi1964 / waitFor.js
Created November 6, 2016 09:09
waitFor lets you pause code execution
function waitFor(ms, cb) {
var waitTill = new Date(new Date().getTime() + ms);
while(waitTill > new Date()){};
if (cb) {
cb()
} else {
return true
}
}
@netsi1964
netsi1964 / readme.md
Created November 2, 2016 13:14
The world in SVG

The world in SVG

Found on a pen by Magnus Kjelland on codepen

@netsi1964
netsi1964 / exampleScrape.css
Last active May 7, 2025 00:37
This gist will create CSS variables from SalesForce Design tokens
:root {
/*
From: https://www.lightningdesignsystem.com/design-tokens/
Using Gist: https://gist.github.com/netsi1964/d8b688c3cd7a22f80087436af249b877
Date: Wed Nov 02 2016 13:58:42 GMT+0100 (Romance Standard Time)
*/
--color-background: rgb(244, 246, 249);
--color-background-alt: rgb(255, 255, 255);
--color-background-alt-2: rgb(238, 241, 246);