-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProximity - Find nearby words.user.js
More file actions
142 lines (128 loc) · 5.08 KB
/
Proximity - Find nearby words.user.js
File metadata and controls
142 lines (128 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// ==UserScript==
// @name Proximity - Find nearby words
// @description Adds a text box to search for nearby words (a kind of hint)
// @match https://proximity.clevergoat.com/
// @match https://proximity.clevergoat.com/archive/game*
// @match https://proximity.clevergoat.com/nearest/*
// @icon https://proximity.clevergoat.com/favicon.ico
// @author Adam Katz
// @namespace https://github.com/adamhotep/userscripts
// @version 0.1.20250616.0
// @grant none
// @require https://github.com/adamhotep/nofus.js/raw/main/nofus.js
// ==/UserScript==
let exploring = 0;
let target = "_blank";
let near_box = $html('div', { id:'near_box', class:'relative' });
let near = near_box.appendChild($html('input', { type:'text', id:'near' }));
near.classList = 'w-full border-2 border-black dark:border-white px-2 py-1.5 '
+ 'rounded-md text-xl outline-none bg-white dark:bg-black ng-untouched '
+ 'ng-pristine ng-valid';
near.pattern = '[a-z]+';
let search = ev => {
let word = fix_near();
if (!word) { return; }
let path = '/nearest/' + btoa(word);
// Holding Ctrl ensures you open in a new tab (the game updates the same tab each time)
// Holding Shift ensures you open in the same tab
if (exploring && !ev.ctrlKey || ev.shiftKey) { location.href = path; }
else { window.open(location.origin + path, target).focus(); }
}
near.addEventListener('keypress', ev => {
if (ev.key == 'Enter') search(ev)
});
let fix_near = () => {
return near.value = near.value.toLowerCase().replace(/[^a-z]/g, "");
}
near.addEventListener('input', ev => {
if (!ev.target.checkValidity()) fix_near();
});
let near_btn = near_box.appendChild($html('button', {
text:"Nearby",
class:'px-3 py-1 absolute right-1 top-1 button-primary border-none'
}));
near_btn.addEventListener('click', search);
if (location.pathname.startsWith('/nearest/')) { // exploring nearby words
exploring = 1;
target = "nearest";
nf.wait$('h2', title => {
if (! title.textContent.includes("Nearby words")) return;
title.parentElement.insertBefore(near_box, title);
// set the page's title to reflect the word
let next = title.nextElementSibling;
if (next) {
let word = q$('span.clever-font-medium', next);
if (word && next.textContent.includes("nearest words to ")) {
document.title = word.textContent + " " + document.title;
}
}
});
nf.wait$('app-nearby-words button', reveal => {
if (reveal.textContent.includes("Reveal words")) reveal.click();
});
nf.wait$('.grid + .grid .col-span-2', word => {
let text = word.textContent;
if (text.match(/^[a-z]{2,}$/)) {
word.textContent = "";
let link = word.appendChild($html('a', { text:text, class:"near_link" }));
link.href = '/nearest/' + btoa(text);
}
});
} else { // playing the game
nf.wait$('button:nth-child(2):has(+ button)', giveup => {
if (! giveup.textContent.includes("Give Up")) return;
let up = giveup.parentElement;
near_box.classList.add('hidden');
up.parentElement.appendChild(near_box);
let near_button = up.insertBefore(giveup.cloneNode(true), giveup);
near_button.id = 'near_button';
near_button.textContent = "Nearby…";
near_button.addEventListener('click', ev => {
if (! near_box.classList.toggle('hidden')) { // toggle. if open, then
let guesses = [...qa$('app-guesses .w-full .text-xl')];
if (guesses.length >= 4) {
// the most recent guess is guesses[0] and its value is guesses[1]
// the previous best guess is guesses[2] and its value is guesses[3]
let away = elem => {
let txt = elem.innerText;
if (txt.includes("warm")) txt = 10e3;
else if (txt.includes("tepid")) txt = 10e4;
else if (txt.includes("cold")) txt = 10e5;
else if (txt.includes("far")) txt = 10e6;
else txt = parseInt(txt) || 10e7;
return txt;
}
if (away(guesses[3]) < away(guesses[1])) guesses.splice(0, 2);
}
let best_guess = guesses[0]?.innerText;
// prune off the light bulb (from a hint) or magnifying glass (if any)
if (best_guess) near.value = best_guess.replace(/[^a-z]+$/, "");
nf.sleep(150, () => { near.focus() });
}
});
});
// Prevent the "Input cannot be empty" toast message from the Enter keypress
// (helps for sticky keyboards & accidental multi-taps on soft keyboards)
nf.wait$('#guessInput', input => {
let no_toast = nf.style$('');
input.addEventListener('keydown', ev => {
if (ev.key == 'Enter' && input.value == '') {
// these do not work for keydown, keyup, or keypress
ev.preventDefault();
ev.stopPropagation();
// fallback: do not display the toast, remove it, then allow new toasts
no_toast.textContent = /* syn=css */ 'mpl-toast { display:none }';
nf.sleep(200, () => {
let toast = q$('mpl-toast');
if (toast) toast.remove();
no_toast.textContent = '';
});
}
});
});
}
nf.style$(`
#near_box { margin:1em 0; }
a.near_link:hover { color:#60a5fa; }
a.near_link:active { color:#f66; }
`);