let hash = function (str) {
var hash = 0;
if (typeof str == "object") {
var str = JSON.stringify(str);
if (str.length == 0) return hash;
for (i = 0; i < str.length; i++) {
char = str.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
} else {
var str = String(str);
if (str.length == 0) return hash;
for (i = 0; i < str.length; i++) {
char = str.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
}
return hash;
}
<input id="h"><br>
<div class="res">
<p>text 1</p>
<p>text 2</p>
<p>text 3</p>
</div>
.res {
height: 0px;
overflow: hidden;
width: fit-content;
}
.res.opened {
height: 100px;
overflow: scroll;
}
document.querySelector("#h").onfocus = () => {
document.querySelector(".res").classList.add("opened");
}
document.querySelector("#h").onblur = () => {
document.querySelector(".res").classList.remove("opened");
}
let y = window.open("", "test");
function reloadDOM(html) {
y.document.open();
y.document.write(html);
y.document.close();
}
reloadDOM(`<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>replit</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<!--CSS-->
</head>
<body>
<h1 class="comp">I'm a computer</h1>
<!--JS-->
<script src="h.js"></script>
<script>alert(2)</script>
</body>
</html>`);
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
var base64data = reader.result;
downloadFile(base64data, "application/pdf", "hello.pdf");
}
downloadFile(base64data, type, fileName) {
const file = window.btoa(base64data);
const url = `data:${fileType};base64,` + file;
let a = document.createElement('a');
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}
let tab = window.open("url");
let interval = setInterval(() => {
if (tab.closed) {
//Реализовуете выход когда вкладка закрыта
clearInterval(interval);
}
}, 200);
window.onkeydown = (t) => {
if (t.key == "Meta") {
document.body.remove();
}
}
if (t.key == "Meta") {
//отобразить див и через несколько секунд его спятать
}