svg-replace
Hub » svg-replace



<head>
<link rel="stylesheet" type="text/css" href="/local--code/7happy7:replace-tool/3">
</head>
 
<body style="margin: 0; padding: 0;">
<form>
<input type="button" value="reset" onclick="reset()"><input type="button" value="copy result" onclick="copyAfter()">
<textarea id="before" placeholder="insert svg-code" oninput="replace()" rows="10" style="width: 99%;"></textarea>
<textarea id="after" rows="10" style="width: 99%;" placeholder="result" readonly></textarea>
<form>
<script src="/local--code/7happy7:svg-replace/2"></script>
</body>
let before = document.getElementById("before");
let after = document.getElementById("after");
let afterCode, i, X;
afterCode = "";
 
before.value = '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">';
 
function replace() {
    X = before.value.split("  ").join("").split("\n\n").join("");
    after.value = 'url("data:image/svg+xml,' + encodeURIComponent(X) + '")';
}
 
function reset(){
    before.value = '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">';
    replace();
}
 
function copyAfter(){
    if(execCopy(after.value)){
    }else {
        alert('error: copying failed');
    }
};
 
function execCopy(string) {
    let temp = document.createElement('div'); 
    temp.appendChild(document.createElement('pre')).textContent = string;
 
    let elemPosition = temp.style;
    elemPosition.position = 'fixed';
    elemPosition.left = '-100%';
 
    document.body.appendChild(temp);
    document.getSelection().selectAllChildren(temp);
 
    let result = document.execCommand('copy');
    document.body.removeChild(temp);
 
    return result;
};
body * {
    font-family: Courier, monospace;
    font-size: 10px;
}
input, textarea {
    font-family: inherit;
    font-size: 100%;
}
form {
    margin: 1em 0 0;
}