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
| var sketch = context.api(); | |
| var document = sketch.selectedDocument; | |
| var selection = document.selectedLayers; | |
| var page = document.selectedPage; | |
| var values = sketch.getStringFromUser("Enter values", "10,30,10,22,50,10,30"); | |
| var canvasWidth = parseFloat(sketch.getStringFromUser("Canvas width", "300")); | |
| var canvasHeight = parseFloat(sketch.getStringFromUser("Canvas height", "300")); | |
| var graphValues = values.split(","); | |
| var min = 1000000, max = -100000, width = canvasWidth / graphValues.length; |
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
| function flowText(text, svg, width, style) { | |
| svg.innerHTML = ""; | |
| width = width - style.padding.left; | |
| var svgText = document.createElementNS("http://www.w3.org/2000/svg", "text"); | |
| var textNode = document.createTextNode(""); | |
| svgText.appendChild(textNode); | |
| var testElement = svg.appendChild(svgText); | |
| var words = text.split(" "); |
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
| var styleKeysSVG_chrome = [ | |
| "alignContent", | |
| "alignItems", | |
| "alignSelf", | |
| "alignmentBaseline", | |
| "all", | |
| "animation", | |
| "animationDelay", | |
| "animationDirection", | |
| "animationDuration", |
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
| // 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; |
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
| 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`; |
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
| 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) |
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
| 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]++; | |
| }) | |
| }); |
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
| // 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; |
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
| 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)); |
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
| function waitFor(ms, cb) { | |
| var waitTill = new Date(new Date().getTime() + ms); | |
| while(waitTill > new Date()){}; | |
| if (cb) { | |
| cb() | |
| } else { | |
| return true | |
| } | |
| } |