|
19 | 19 | // ==/UserScript== |
20 | 20 |
|
21 | 21 | ;(async function () { |
| 22 | + const simpleUrl: string = (location.hostname + location.pathname) |
| 23 | + .replace(/^www\./, '') |
| 24 | + .replace(/\/$/, '') |
| 25 | + |
22 | 26 | let accountEmails: string[] = [] |
23 | 27 | let accountEmailsInput = await GM_getValue<string>('accountEmails', '') |
24 | 28 |
|
|
84 | 88 | accountEmails = accountEmailsInput.split(/, */) |
85 | 89 | } |
86 | 90 |
|
| 91 | + async function renderAccountEmails(): Promise<void> { |
| 92 | + await wait(2000) |
| 93 | + const siblingEl = document.querySelector<HTMLAnchorElement>('a[href="/search"]')! |
| 94 | + const emailName = queryContentIncludes('.chakra-text', '@gmail.com', true) |
| 95 | + ?.textContent?.replace('@gmail.com', '') |
| 96 | + .toLowerCase() |
| 97 | + for (const accountEmail of accountEmails.slice().reverse()) { |
| 98 | + const el = document.createElement('button') |
| 99 | + el.style.paddingLeft = '40px' |
| 100 | + el.style.textAlign = 'left' |
| 101 | + el.textContent = accountEmail |
| 102 | + if (accountEmail === emailName) { |
| 103 | + el.style.color = 'limegreen' |
| 104 | + el.style.paddingLeft = '26px' |
| 105 | + el.textContent = `> ${accountEmail}` |
| 106 | + } |
| 107 | + el.addEventListener('click', (): void => { |
| 108 | + switchAccount(accountEmail) |
| 109 | + }) |
| 110 | + siblingEl.after(el) |
| 111 | + } |
| 112 | + } |
| 113 | + |
87 | 114 | function css(strs: TemplateStringsArray, ...vals: unknown[]): string { |
88 | 115 | let result: string = '' |
89 | 116 | for (let i = 0; i < strs.length - 1; i++) { |
|
152 | 179 | } |
153 | 180 | }) |
154 | 181 |
|
155 | | - if (location.href === 'https://suno.com/') { |
| 182 | + if (simpleUrl === 'suno.com') { |
156 | 183 | location.pathname = '/me' |
157 | 184 | } |
158 | 185 | // |
159 | | - else if (location.href === 'https://suno.com/me') { |
160 | | - await GM_deleteValue('accountEmail') |
| 186 | + else if (simpleUrl === 'suno.com/me') { |
161 | 187 | await wait(2000) |
162 | 188 | clickIfContentIncludes('button', 'Liked') |
163 | 189 | ;(document.activeElement as HTMLElement).blur() |
164 | | - const siblingEl = document.querySelector<HTMLAnchorElement>('a[href="/search"]')! |
165 | | - const emailName = queryContentIncludes('.chakra-text', '@gmail.com', true) |
166 | | - ?.textContent?.replace('@gmail.com', '') |
167 | | - .toLowerCase() |
168 | | - for (const accountEmail of accountEmails.slice().reverse()) { |
169 | | - const el = document.createElement('button') |
170 | | - el.style.paddingLeft = '40px' |
171 | | - el.style.textAlign = 'left' |
172 | | - el.textContent = accountEmail |
173 | | - if (accountEmail === emailName) { |
174 | | - el.style.color = 'limegreen' |
175 | | - el.style.paddingLeft = '26px' |
176 | | - el.textContent = `> ${accountEmail}` |
177 | | - } |
178 | | - el.addEventListener('click', (): void => { |
179 | | - switchAccount(accountEmail) |
180 | | - }) |
181 | | - siblingEl.after(el) |
182 | | - } |
| 190 | + renderAccountEmails() |
| 191 | + } |
| 192 | + // |
| 193 | + else if (simpleUrl === 'suno.com/create') { |
| 194 | + renderAccountEmails() |
| 195 | + } |
| 196 | + // |
| 197 | + else if (simpleUrl === 'suno.com/search') { |
| 198 | + renderAccountEmails() |
183 | 199 | } |
184 | 200 | // |
185 | | - else if (location.href.startsWith('https://accounts.suno.com/sign-in')) { |
| 201 | + else if (simpleUrl.startsWith('accounts.suno.com/sign-in')) { |
186 | 202 | await wait(500) |
187 | 203 | click('.cl-socialButtonsIconButton__google') |
188 | 204 | } |
189 | 205 | // |
190 | | - else if (location.href.startsWith('https://accounts.google.com/o/oauth2/')) { |
| 206 | + else if (simpleUrl.startsWith('accounts.google.com/o/oauth2/')) { |
191 | 207 | const accountEmail = await GM_getValue('accountEmail') |
192 | 208 | if (typeof accountEmail === 'string') { |
193 | 209 | await GM_deleteValue('accountEmail') |
|
197 | 213 | } |
198 | 214 | } |
199 | 215 | // |
200 | | - else if (location.href.startsWith('https://www.google.com/search?')) { |
| 216 | + else if (simpleUrl.startsWith('google.com/search')) { |
201 | 217 | const els = document.querySelectorAll<HTMLDivElement>( |
202 | 218 | '[data-lyricid] > div > :nth-child(2) > div' |
203 | 219 | ) |
|
0 commit comments