Skip to content

Commit 85522f5

Browse files
committed
fix: (Mien-AI-Music) Render danh sách email trong cả các trang khác
1 parent 9a34dcb commit 85522f5

File tree

2 files changed

+82
-50
lines changed

2 files changed

+82
-50
lines changed

scripts/Mien-AI-Music/script.user.js

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
// ==/UserScript==
2121

2222
;(async function () {
23+
const simpleUrl = (location.hostname + location.pathname)
24+
.replace(/^www\./, '')
25+
.replace(/\/$/, '')
26+
2327
let accountEmails = []
2428
let accountEmailsInput = await GM_getValue('accountEmails', '')
2529

@@ -77,6 +81,29 @@
7781
accountEmails = accountEmailsInput.split(/, */)
7882
}
7983

84+
async function renderAccountEmails() {
85+
await wait(2000)
86+
const siblingEl = document.querySelector('a[href="/search"]')
87+
const emailName = queryContentIncludes('.chakra-text', '@gmail.com', true)
88+
?.textContent?.replace('@gmail.com', '')
89+
.toLowerCase()
90+
for (const accountEmail of accountEmails.slice().reverse()) {
91+
const el = document.createElement('button')
92+
el.style.paddingLeft = '40px'
93+
el.style.textAlign = 'left'
94+
el.textContent = accountEmail
95+
if (accountEmail === emailName) {
96+
el.style.color = 'limegreen'
97+
el.style.paddingLeft = '26px'
98+
el.textContent = `> ${accountEmail}`
99+
}
100+
el.addEventListener('click', () => {
101+
switchAccount(accountEmail)
102+
})
103+
siblingEl.after(el)
104+
}
105+
}
106+
80107
function css(strs, ...vals) {
81108
let result = ''
82109
for (let i = 0; i < strs.length - 1; i++) {
@@ -145,42 +172,31 @@
145172
}
146173
})
147174

148-
if (location.href === 'https://suno.com/') {
175+
if (simpleUrl === 'suno.com') {
149176
location.pathname = '/me'
150177
}
151178
//
152-
else if (location.href === 'https://suno.com/me') {
153-
await GM_deleteValue('accountEmail')
179+
else if (simpleUrl === 'suno.com/me') {
154180
await wait(2000)
155181
clickIfContentIncludes('button', 'Liked')
156182
document.activeElement.blur()
157-
const siblingEl = document.querySelector('a[href="/search"]')
158-
const emailName = queryContentIncludes('.chakra-text', '@gmail.com', true)
159-
?.textContent?.replace('@gmail.com', '')
160-
.toLowerCase()
161-
for (const accountEmail of accountEmails.slice().reverse()) {
162-
const el = document.createElement('button')
163-
el.style.paddingLeft = '40px'
164-
el.style.textAlign = 'left'
165-
el.textContent = accountEmail
166-
if (accountEmail === emailName) {
167-
el.style.color = 'limegreen'
168-
el.style.paddingLeft = '26px'
169-
el.textContent = `> ${accountEmail}`
170-
}
171-
el.addEventListener('click', () => {
172-
switchAccount(accountEmail)
173-
})
174-
siblingEl.after(el)
175-
}
183+
renderAccountEmails()
184+
}
185+
//
186+
else if (simpleUrl === 'suno.com/create') {
187+
renderAccountEmails()
188+
}
189+
//
190+
else if (simpleUrl === 'suno.com/search') {
191+
renderAccountEmails()
176192
}
177193
//
178-
else if (location.href.startsWith('https://accounts.suno.com/sign-in')) {
194+
else if (simpleUrl.startsWith('accounts.suno.com/sign-in')) {
179195
await wait(500)
180196
click('.cl-socialButtonsIconButton__google')
181197
}
182198
//
183-
else if (location.href.startsWith('https://accounts.google.com/o/oauth2/')) {
199+
else if (simpleUrl.startsWith('accounts.google.com/o/oauth2/')) {
184200
const accountEmail = await GM_getValue('accountEmail')
185201
if (typeof accountEmail === 'string') {
186202
await GM_deleteValue('accountEmail')
@@ -190,7 +206,7 @@
190206
}
191207
}
192208
//
193-
else if (location.href.startsWith('https://www.google.com/search?')) {
209+
else if (simpleUrl.startsWith('google.com/search')) {
194210
const els = document.querySelectorAll('[data-lyricid] > div > :nth-child(2) > div')
195211
for (const el of els) {
196212
el.style.marginBottom = '-8px'

scripts/Mien-AI-Music/script.user.ts

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
// ==/UserScript==
2020

2121
;(async function () {
22+
const simpleUrl: string = (location.hostname + location.pathname)
23+
.replace(/^www\./, '')
24+
.replace(/\/$/, '')
25+
2226
let accountEmails: string[] = []
2327
let accountEmailsInput = await GM_getValue<string>('accountEmails', '')
2428

@@ -84,6 +88,29 @@
8488
accountEmails = accountEmailsInput.split(/, */)
8589
}
8690

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+
87114
function css(strs: TemplateStringsArray, ...vals: unknown[]): string {
88115
let result: string = ''
89116
for (let i = 0; i < strs.length - 1; i++) {
@@ -152,42 +179,31 @@
152179
}
153180
})
154181

155-
if (location.href === 'https://suno.com/') {
182+
if (simpleUrl === 'suno.com') {
156183
location.pathname = '/me'
157184
}
158185
//
159-
else if (location.href === 'https://suno.com/me') {
160-
await GM_deleteValue('accountEmail')
186+
else if (simpleUrl === 'suno.com/me') {
161187
await wait(2000)
162188
clickIfContentIncludes('button', 'Liked')
163189
;(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()
183199
}
184200
//
185-
else if (location.href.startsWith('https://accounts.suno.com/sign-in')) {
201+
else if (simpleUrl.startsWith('accounts.suno.com/sign-in')) {
186202
await wait(500)
187203
click('.cl-socialButtonsIconButton__google')
188204
}
189205
//
190-
else if (location.href.startsWith('https://accounts.google.com/o/oauth2/')) {
206+
else if (simpleUrl.startsWith('accounts.google.com/o/oauth2/')) {
191207
const accountEmail = await GM_getValue('accountEmail')
192208
if (typeof accountEmail === 'string') {
193209
await GM_deleteValue('accountEmail')
@@ -197,7 +213,7 @@
197213
}
198214
}
199215
//
200-
else if (location.href.startsWith('https://www.google.com/search?')) {
216+
else if (simpleUrl.startsWith('google.com/search')) {
201217
const els = document.querySelectorAll<HTMLDivElement>(
202218
'[data-lyricid] > div > :nth-child(2) > div'
203219
)

0 commit comments

Comments
 (0)