-
Notifications
You must be signed in to change notification settings - Fork 0
/
paste.js
2 lines (2 loc) · 3.23 KB
/
paste.js
1
2
/*! For license information please see paste.js.LICENSE.txt */
(async()=>{function e(e){const t={key:e,code:`Key${e.toUpperCase()}`,keyCode:e.toUpperCase().charCodeAt(0),which:e.toUpperCase().charCodeAt(0),bubbles:!0,cancelable:!0};document.body.dispatchEvent(new KeyboardEvent("keydown",t)),document.body.dispatchEvent(new KeyboardEvent("keypress",t)),document.body.dispatchEvent(new KeyboardEvent("keyup",t))}async function t(t,o,n){for(let n of t)e(n),await new Promise((e=>setTimeout(e,o)));const r={key:"Enter",code:"Enter",keyCode:13,which:13,bubbles:!0,cancelable:!0};document.body.dispatchEvent(new KeyboardEvent("keydown",r)),document.body.dispatchEvent(new KeyboardEvent("keypress",r)),document.body.dispatchEvent(new KeyboardEvent("keyup",r)),await new Promise((e=>setTimeout(e,n)))}await async function(){const e=function(){let e="slow";const t=document.querySelectorAll(".keys-button.hex"),o=document.querySelector(".keys-button.middle.hex");if(7===t.length&&o){let n=Array.from(t).map((e=>e.textContent.toLowerCase())),r=o.textContent.toLowerCase();return n.includes(r)&&n.splice(n.indexOf(r),1),n.unshift(r),console.log(`Detected letters (Method 1): ${n.join(" ")}`),e="fast",{letters:n.join(" "),mode:e}}const n=document.querySelector(".hive-cell.center .cell-letter"),r=document.querySelectorAll(".hive-cell.outer .cell-letter");if(n&&6===r.length){let t=n.textContent.toLowerCase(),o=Array.from(r).map((e=>e.textContent.toLowerCase()));return o.unshift(t),console.log(`Detected letters (Method 2): ${o.join(" ")}`),e="fast",{letters:o.join(" "),mode:e}}const s=document.querySelectorAll("#hexGrid .hex p"),l=document.querySelector("#center-letter p");if(7===s.length&&l){const t=Array.from(s).map((e=>e.textContent.toLowerCase())),o=l.textContent.toLowerCase();return t.includes(o)&&t.splice(t.indexOf(o),1),t.unshift(o),console.log(`Detected letters: ${t.join(" ")}`),{letters:t.join(" "),mode:e}}const c=document.querySelector(".hex.middle"),d=document.querySelectorAll(".hex:not(.middle)");if(c&&6===d.length){const t=c.textContent.toLowerCase(),o=Array.from(d).map((e=>e.textContent.toLowerCase()));return o.unshift(t),console.log(`Detected letters (General Format): ${o.join(" ")}`),{letters:o.join(" "),mode:e}}const a=window.prompt("Unable to detect letters. Please enter the 7 letters (first one is the center letter), separated by spaces:","");return a?{letters:a,mode:e}:(console.error("No letters provided."),null)}();if(!e)return;const{letters:o,mode:n}=e;console.log(`Using ${n} mode`);const r=await async function(){try{const e=await fetch("https://raw.githubusercontent.com/words/an-array-of-english-words/refs/heads/master/index.json");return e.ok?await e.json():(console.error("Failed to fetch word list:",e.statusText),[])}catch(e){return console.error("Error:",e),[]}}();if(0===r.length)return void console.error("Failed to load word list.");let[s,...l]=o.split(" "),c=[s,...l];const d=r.filter((e=>e.length>=4&&function(e,t,o){const n=function(e,t){const o=t.join("");return new RegExp(`^[${o}]*${e}[${o}]*$`,"i")}(t,o),r=e.split("").filter((e=>e===t)).length;return n.test(e)&&r>=1}(e,s,c)));let a,i;console.log(`Found ${d.length} matching words:`),console.log(d),"fast"===n?(a=10,i=100):(a=30,i=2300);for(let e of d)console.log(`Typing word: ${e}`),await t(e,a,i)}()})();