Skip to content

Instantly share code, notes, and snippets.

View beziehungsweise's full-sized avatar

beziehungsweise

View GitHub Profile
(function(){try{function $(s,c){return (c||document).querySelector(s)}function $$(s,c){return Array.from((c||document).querySelectorAll(s))}function pickDoc(){var cands=[window].concat(Array.from(document.querySelectorAll('iframe')).map(f=>f.contentWindow).filter(Boolean));var sample=['space-s','text-m','h2','primary'];function score(w){try{var cs=w.getComputedStyle(w.document.documentElement);return sample.reduce((n,v)=>n+((cs.getPropertyValue('--'+v)||'').trim()?1:0),0)}catch(e){return -1}}return cands.sort((a,b)=>score(b)-score(a))[0]||window}var W=pickDoc(),D=W.document;function pxToRem(px){var f=parseFloat(px);if(!isFinite(f))return'';var fs=parseFloat(W.getComputedStyle(D.documentElement).fontSize)||16;return(Math.round(f/fs*100)/100).toFixed(2)+'rem'}function definedVar(n){return (W.getComputedStyle(D.documentElement).getPropertyValue('--'+n)||'').trim()!==''}function copy(t){if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(t)}else{var ta=D.createElement('textarea');