silvrgit/views/pages/cleaner.ejs
2020-05-12 15:43:28 +01:00

126 lines
2.8 KiB
Plaintext

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cleaner</title>
<link href="css/skeleton.css" rel="stylesheet" type="text/css"/>
<style>
.mcolumn {
float: left;
width: 50%;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
textarea {
resize: none;
height: 800px;
}
</style>
<script src="libs/zepto.min.js"></script>
</head>
<body>
<div class="row">
<div class="mcolumn"><textarea class="u-full-width" cols="100" rows="60" id="source"></textarea></div>
<div class="mcolumn"><textarea class="u-full-width" cols="100" rows="60" id="output"></textarea></div>
</div>
<button onclick="cleanScriptsLinks()">Clean Scripts / Links</button>
<button onclick="cleanBook()">Clean Book</button>
<button onclick="convertToBase64()">Convert To Base64</button>
<button onclick="convertFromBase64()">Convert From Base64</button>
<br>
<button class='button-primary' onclick="clearAreas()">Clear windows</button>
<script>
function cleanBook() {
const step1 = /(\n\n+)/g;
const step2 = /(\n)/g;
const step3 = /(—)/g;
const source = document.getElementById('source').value;
let output = source.replace(step1, '—'); // replace double or more line feeds
output = output.replace(step2, ' '); // remove all single line feeds
output = output.replace(step3, '\n\n'); // replace for paragraphs
document.getElementById('output').value = output;
}
// ucs-2 string to base64 encoded ascii
function clearAreas(){
console.log('clear');
document.getElementById('source').value = '';
document.getElementById('output').value = '';
}
function utoa(str) {
return window.btoa(unescape(encodeURIComponent(str)));
}
// base64 encoded ascii to ucs-2 string
function atou(str) {
return decodeURIComponent(escape(window.atob(str)));
}
function cleanScriptsLinks() {
const source = document.getElementById('source').value;
let output = source.replace(/(\<\bscript\b[\S\s]+?<\/\bscript\b\>)/g, '');
output = output.replace(/<\/?link[^>]*>/g,'');
output = output.replace(/(?:src\s*?=\s*?['"])(.+?)(?:['"])/g,'');
document.getElementById('output').value = output;
}
function convertToBase64() {
const source = document.getElementById('source').value;
const output = utoa(source);
document.getElementById('output').value = output;
}
function convertFromBase64() {
const source = document.getElementById('source').value;
const output = atou(source);
document.getElementById('output').value = output;
}
</script>
</body>
</html>