Skip to content

Instantly share code, notes, and snippets.

Array.from(document.querySelectorAll('text')).forEach((text) => {
Array.from(text.querySelectorAll('textPath')).forEach((textPath) => {
let textContent = textPath.textContent.replace(/\n[ ]*/g, ' ').replace(/^[\n ]/, '');
const g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
const computedStyle = getComputedStyle(textPath);
g.setAttribute('fill', computedStyle.fill);
g.setAttribute('font-size', computedStyle.fontSize);
g.setAttribute('font-family', computedStyle.fontFamily);
g.setAttribute('font-weight', computedStyle.fontWeight);
g.setAttribute('font-style', computedStyle.fontStyle);
const rules = [];
function collectRules(rule) {
if(rule instanceof CSSMediaRule && window.matchMedia(rule.conditionText).matches) {
rule.rules.forEach(collectRules);
} else if(rule instanceof CSSSupportsRule) {
try {
if(CSS.supports(rule.conditionText)) {
rule.cssRules.forEach(collectRules);
}
} catch(e) {}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dice</title>
</head>
@sczesny
sczesny / graph-plotter.html
Last active November 10, 2022 21:23
Plot JavaScript function as graph
<!DOCTYPE html>
<html>
<head>
<title>Graph Plotter</title>
<script>
let f = (x) => {
return x * x;
}