replace-tool
Hub » replace-tool
.split(/SCP-XXXX/g).join("SCP-9999")
SCP-XXXX→SCP-9999
<head> <link rel="stylesheet" type="text/css" href="/local--code/7happy7:replace-tool/3"> </head> <body style="margin: 0; padding: 0;"> <table style="width:100%;"> <tbody><tr><td style="width: 50%;"> <form> .split(<input type="text" id="ex" placeholder="/xxx/g" size="18">).join("<input type="text" id="rep" size="12">")<br> <input type="button" value="register" onclick="registerEx()"><input type="button" value="reset" onclick="resetEx()"> </form> <table style="width:100%; color: #fff; background: #333;"> <tbody><tr><td><ul id="exList"></ul></td><td><ul id="repList"></ul></td></tr></tbody> </table> </td> <td> <form> <input type="button" value="reset" onclick="reset()"><input type="button" value="copy result" onclick="copyAfter()"> <textarea id="before" placeholder="insert before-text" oninput="replace()" rows="10" style="width: 99%;"></textarea> <textarea id="after" rows="10" style="width: 99%;" placeholder="result" readonly></textarea> </tr></tbody> </table> <script src="/local--code/7happy7:replace-tool/2"></script> </body>
let ex = document.getElementById("ex"); let rep = document.getElementById("rep"); let exList = document.getElementById("exList"); let repList = document.getElementById("repList"); let before = document.getElementById("before"); let after = document.getElementById("after"); let afterCode, i, exArray, repArray; afterCode = ""; function registerEx() { if(ex.value==""){;} else{ exList.insertAdjacentHTML('afterbegin',"<li>" + ex.value + "</li>"); repList.insertAdjacentHTML('afterbegin',"<li>" + rep.value + "</li>"); exArray = []; repArray = []; for(i = 0;i < exList.children.length;i++){ exArray.push(exList.children[i].innerText); repArray.push(repList.children[i].innerText); } replace(); } } function resetEx() { ex.value = ""; rep.value = ""; exArray = []; repArray = []; exList.innerHTML = ""; repList.innerHTML = ""; } function replace() { afterCode = before.value; for(i = 0;i < exArray.length;i++){ afterCode = afterCode.split(new RegExp(exArray[i].replace(/\/(.+)\/(.*)/g, "$1"), exArray[i].replace(/\/(.+)\/(.*)/g, "$2"))).join(repArray[i]); } after.value = afterCode; } function reset(){ before.value = ""; 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; } table * { margin: 0; padding: 0; } td { width: 50%; vertical-align: top; } ul { list-style: none; } ul#repList { position: relative; left: -2px; } ul#exList > li:before { content: ".split("; } ul#exList > li:after { content: ")"; } ul#repList > li:before { content: '.join("'; } ul#repList > li:after { content: '")'; } li { border-bottom: 1px solid #fff; margin-bottom: 0.2em; } li:last-child { border-bottom: none; margin-bottom: 0; }
page revision: 91, last edited: 31 Mar 2019 13:10