-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
1 lines (1 loc) · 4.96 KB
/
index.js
1
window.addEventListener("load",function e(){window.removeEventListener("load",e);var t=document.getElementById("screen");function n(e){var t=new XMLHttpRequest;if(t.open("GET",e,!1),t.send(),200==t.status&&4==t.readyState)return t.responseText}setTimeout(()=>{t.contentDocument.write(n("./src/index.html").replace(/href="/g,'href="src/').replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"")),setTimeout(()=>{t.contentWindow.stop(),t.contentWindow.eval(n("./src/js/app.js"));var e=t.contentDocument.createElement("style");e.innerHTML="*{scrollbar-width:thin;}@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;500;600;700&display=swap');\n\t\t",t.contentDocument.body.appendChild(e)},1500),setTimeout(()=>{var e=t.contentDocument.createEvent("Event");e.initEvent("load",!1,!1),t.contentWindow.dispatchEvent(e)},3e3)},1e3),setTimeout(()=>{!function e(){let n=t.contentDocument.querySelector("[name=theme-color]").content;document.getElementById("statusbar").style.backgroundColor=n;let o=n.split("rgb(")[1].split(")")[0].split(",");var r=Math.round((299*parseInt(o[0])+587*parseInt(o[1])+114*parseInt(o[2]))/1e3);document.getElementById("statusbar").style.color=r>125?"#4A4D4A":"white","text"==t.contentDocument.activeElement.type?document.getElementById("ime").innerText=i[c].name:document.getElementById("ime").innerText="",setTimeout(e,400)}()},2e3);const o={1:[".",",","?","!","1",";",":","/","@"],2:["a","b","c","2"],3:["d","e","f","3"],4:["g","h","i","4"],5:["j","k","l","5"],6:["m","n","o","6"],7:["p","q","r","s","7"],8:["t","u","v","8"],9:["w","x","y","z","9"],0:[" ","0"]},i=[{name:"ab",fn:function(e,t){return t.map(e=>e.toLowerCase())}},{name:"AB",fn:function(e,t){return t.map(e=>e.toUpperCase())}},{name:"12",fn:function(e){return e}}];let c=0;const r=function(e){e.style.visibility="hidden";let t,n=[],o=null,i=null;const c=function(){t&&t.dispatchEvent(new InputEvent("input")),e.style.visibility="hidden"};return function(r,a){let s;if(t=a,"hidden"===e.style.visibility)n=r,o=r[0],s=!1;else if(function(e,t){if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}(n,r)){let e=n.indexOf(o)+1;e>=n.length&&(e=0),o=n[e],s=!0}else t.dispatchEvent(new InputEvent("input")),n=r,o=r[0],s=!1;return e.innerHTML="",n.forEach(function(t){const n=document.createElement("div");t===o&&n.classList.add("selected"),n.appendChild(document.createTextNode(t)),e.appendChild(n)}),e.style.visibility="visible",clearTimeout(i),i=setTimeout(c,1e3),[o,s]}}(document.querySelector("#keyselector")),a=function(e,n){t.contentWindow.document.activeElement.focus();const o=new KeyboardEvent(n||"keydown",{target:t.contentWindow.document.activeElement,key:e,composed:!0,bubbles:!0,cancelable:!1});t.contentWindow.dispatchEvent(o)},s=function(e){return"INPUT"===e.tagName&&"text"===e.type||"TEXTAREA"===e.tagName},u={".sk":function(e,t){a(e.currentTarget.getAttribute("data-key"),t)},".backspace":function(e,n){const o=t.contentDocument.activeElement;if(s(o)){if(""==o.value)return void a("Backspace",n);if("keyup"==n)return;if(""!==o.value&&o.selectionStart>0){const e=o.value,t=o.selectionStart-1;o.value=e.substring(0,t)+e.substring(t+1),o.setSelectionRange(t,t),o.dispatchEvent(new InputEvent("input"))}}else a("Backspace",n)},".lr":function(e,n){const o=t.contentDocument.activeElement,i=e.currentTarget.getAttribute("data-key");if(s(o)){if("ArrowRight"===i){if(o.selectionStart<o.value.length){const e=o.selectionStart+1;o.setSelectionRange(e,e)}}else if("ArrowLeft"===i&&o.selectionStart>0){const e=o.selectionStart-1;o.setSelectionRange(e,e)}}else a(i,n)},".char":function(e,n){const u=(l=e.currentTarget.getAttribute("data-key"),i[c].fn(l,o[l]));var l;const d=Array.isArray(u),m=t.contentDocument.activeElement;if(s(m)){if("keyup"==n)return void a(u[0],n);if(m.value.length==m.maxLength)return;const[e,t]=d?r(u,m):[u,!1];let o=m.value,i=m.selectionStart;t?o=o.substring(0,i-1)+e+o.substring(i):(i++,o=o.substring(0,i)+e+o.substring(i)),m.value=o,m.setSelectionRange(i,i),m.dispatchEvent(new InputEvent("input",{isComposing:d}))}else a(u[0],n)},".mode":function(){c=c===i.length-1?0:c+1}},l={".sk":e=>{u[".sk"](e,"keyup")},".lr":e=>{u[".lr"](e,"keyup")},".char":e=>{u[".char"](e,"keyup")},".backspace":e=>{u[".backspace"](e,"keyup")}};var d,m;Object.keys(u).forEach(function(e){Array.from(document.querySelectorAll(e)).forEach(function(t){t.addEventListener("mousedown",u[e]),".mode"!=e&&t.addEventListener("mouseup",l[e])})}),["keypress","keydown","keyup","mousedown","mouseup","click"].forEach(function(e){window.addEventListener(e,function(e){e.target.getAttribute("data-allowlist")||e.preventDefault()},!0)}),["keypress","keydown","keyup","mousedown","mouseup","click"].forEach(function(e){t.contentWindow.addEventListener(e,function(e){e.cancelable&&(e.preventDefault(),e.stopPropagation())},!0)}),updateTime=(()=>{var e=new Date,t=e.getHours()+":"+e.getMinutes();document.getElementById("time").innerText=t}),updateTime(),d=updateTime,m=new Date,setTimeout(function(){d(),setInterval(d,6e4)},6e4-m%6e4)});