silvrgit/views/pages/cleaner.ejs

126 lines
2.8 KiB
Plaintext
Raw Permalink Normal View History

2019-01-21 17:01:08 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cleaner</title>
2019-01-21 17:11:44 +00:00
<link href="css/skeleton.css" rel="stylesheet" type="text/css"/>
2019-01-21 17:01:08 +00:00
<style>
2019-01-21 17:11:44 +00:00
.mcolumn {
2019-01-21 17:01:08 +00:00
float: left;
width: 50%;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
textarea {
resize: none;
2019-01-21 17:11:44 +00:00
height: 800px;
2019-01-21 17:01:08 +00:00
}
</style>
2019-03-20 15:37:51 +00:00
<script src="libs/zepto.min.js"></script>
2019-01-21 17:01:08 +00:00
</head>
<body>
<div class="row">
2019-01-21 17:11:44 +00:00
<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>
2019-01-21 17:01:08 +00:00
</div>
<button onclick="cleanScriptsLinks()">Clean Scripts / Links</button>
2020-05-12 14:43:28 +00:00
<button onclick="cleanBook()">Clean Book</button>
2019-01-21 17:01:08 +00:00
<button onclick="convertToBase64()">Convert To Base64</button>
<button onclick="convertFromBase64()">Convert From Base64</button>
2019-02-12 16:10:05 +00:00
<br>
2019-03-20 15:37:51 +00:00
<button class='button-primary' onclick="clearAreas()">Clear windows</button>
2019-02-12 16:10:05 +00:00
2019-01-21 17:01:08 +00:00
<script>
2020-05-12 14:43:28 +00:00
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;
}
2019-01-21 17:01:08 +00:00
// ucs-2 string to base64 encoded ascii
2019-03-20 15:37:51 +00:00
function clearAreas(){
console.log('clear');
2019-02-12 16:10:05 +00:00
document.getElementById('source').value = '';
document.getElementById('output').value = '';
}
2019-01-21 17:01:08 +00:00
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,'');
2019-02-12 16:10:05 +00:00
output = output.replace(/(?:src\s*?=\s*?['"])(.+?)(?:['"])/g,'');
2019-01-21 17:01:08 +00:00
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>