|
@@ -0,0 +1,120 @@
|
|
1
|
+const copyToClipboard = (s) => {
|
|
2
|
+ document.addEventListener('copy', (e) => {
|
|
3
|
+ e.preventDefault();
|
|
4
|
+ e.clipboardData?.setData('text/plain', s);
|
|
5
|
+ document.removeEventListener('copy', listener);
|
|
6
|
+ });
|
|
7
|
+
|
|
8
|
+ if (!navigator.clipboard) {
|
|
9
|
+ document.execCommand('copy');
|
|
10
|
+ } else {
|
|
11
|
+ navigator.clipboard.writeText(s).catch(() => {
|
|
12
|
+ console.log('failed to copy');
|
|
13
|
+ });
|
|
14
|
+ }
|
|
15
|
+};
|
|
16
|
+
|
|
17
|
+const buildGuesses = () => {
|
|
18
|
+ const rows = document
|
|
19
|
+ .querySelector('game-app')
|
|
20
|
+ .shadowRoot.querySelector('game-theme-manager')
|
|
21
|
+ .querySelectorAll('game-row');
|
|
22
|
+ const isDarkMode = window.localStorage.darkTheme === 'true';
|
|
23
|
+ return [...rows]
|
|
24
|
+ .map((row) => {
|
|
25
|
+ const guess = row.attributes.letters.value;
|
|
26
|
+
|
|
27
|
+ if (!guess) {
|
|
28
|
+ return null;
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ const colors = [...row.shadowRoot.querySelectorAll('game-tile')]
|
|
32
|
+ .map((letter) => {
|
|
33
|
+ switch (letter.attributes.evaluation.value) {
|
|
34
|
+ case 'present':
|
|
35
|
+ return '🟨';
|
|
36
|
+ case 'correct':
|
|
37
|
+ return '🟩';
|
|
38
|
+ default:
|
|
39
|
+ return isDarkMode ? '⬛' : '⬜';
|
|
40
|
+ }
|
|
41
|
+ })
|
|
42
|
+ .join('');
|
|
43
|
+
|
|
44
|
+ return `${colors} [spoiler]${guess.toUpperCase()}[/spoiler]`;
|
|
45
|
+ })
|
|
46
|
+ .filter((el) => !!el);
|
|
47
|
+};
|
|
48
|
+
|
|
49
|
+const buildShareCopy = () => {
|
|
50
|
+ const app = new window.wrappedJSObject.wordle.bundle.GameApp();
|
|
51
|
+ const number = app.dayOffset;
|
|
52
|
+ const hardMode = app.isHardMode ? '*' : '';
|
|
53
|
+ const guesses = buildGuesses();
|
|
54
|
+ const guessesCopy = guesses.join('\n');
|
|
55
|
+
|
|
56
|
+ return `Wordle ${number} ${guesses.length}/6${hardMode}\n\n${guessesCopy}`;
|
|
57
|
+};
|
|
58
|
+
|
|
59
|
+const handleClick = (e) => {
|
|
60
|
+ e.preventDefault();
|
|
61
|
+ e.stopPropagation();
|
|
62
|
+
|
|
63
|
+ const shareCopy = buildShareCopy();
|
|
64
|
+ const toastContainer = document
|
|
65
|
+ .querySelector('game-app')
|
|
66
|
+ .shadowRoot.querySelector('game-theme-manager')
|
|
67
|
+ .querySelector('#system-toaster');
|
|
68
|
+ const toast = document.createElement('game-toast');
|
|
69
|
+ toast.setAttribute('text', 'Copied results to clipboard');
|
|
70
|
+ toast.setAttribute('duration', '2000');
|
|
71
|
+ toastContainer.appendChild(toast);
|
|
72
|
+ copyToClipboard(shareCopy);
|
|
73
|
+};
|
|
74
|
+
|
|
75
|
+const buildButton = () => {
|
|
76
|
+ const button = document.createElement('button');
|
|
77
|
+ button.id = 'extended-share-button';
|
|
78
|
+ button.innerText = 'Share ++';
|
|
79
|
+ button.addEventListener('click', handleClick);
|
|
80
|
+ button.style.cssText = `
|
|
81
|
+ align-items: center;
|
|
82
|
+ background-color: var(--key-bg-correct);
|
|
83
|
+ border-radius: 4px;
|
|
84
|
+ border: none;
|
|
85
|
+ color: var(--key-evaluated-text-color);
|
|
86
|
+ cursor: pointer;
|
|
87
|
+ display: flex;
|
|
88
|
+ filter: brightness(100%);
|
|
89
|
+ font-family: inherit;
|
|
90
|
+ font-size: 20px;
|
|
91
|
+ font-weight: bold;
|
|
92
|
+ height: 52px;
|
|
93
|
+ justify-content: center;
|
|
94
|
+ margin-top: 10px;
|
|
95
|
+ text-transform: uppercase;
|
|
96
|
+ userSelect: none;
|
|
97
|
+ width: 80%;
|
|
98
|
+ `;
|
|
99
|
+ return button;
|
|
100
|
+};
|
|
101
|
+
|
|
102
|
+const readyStateCheckInterval = setInterval(() => {
|
|
103
|
+ const el = document
|
|
104
|
+ .querySelector('game-app')
|
|
105
|
+ .shadowRoot.querySelector('game-theme-manager')
|
|
106
|
+ .querySelector('game-modal game-stats');
|
|
107
|
+
|
|
108
|
+ if (el && !el.querySelector('#extended-share-button')) {
|
|
109
|
+ clearInterval(readyStateCheckInterval);
|
|
110
|
+ const button = buildButton();
|
|
111
|
+ const shareContainer = el.shadowRoot.querySelector('.share');
|
|
112
|
+ shareContainer.style.flexDirection = 'column';
|
|
113
|
+
|
|
114
|
+ shareContainer
|
|
115
|
+ .querySelectorAll('#extended-share-button')
|
|
116
|
+ .forEach((el) => el.remove());
|
|
117
|
+
|
|
118
|
+ shareContainer.appendChild(button);
|
|
119
|
+ }
|
|
120
|
+}, 1000);
|