-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
82 lines (76 loc) · 2.72 KB
/
script.js
File metadata and controls
82 lines (76 loc) · 2.72 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
// ==UserScript==
// @name Netease Ruby
// @namespace http://tampermonkey.net/
// @version 2025-05-04
// @description try to take over the world!
// @author bridge
// @match https://music.163.com/*
// @include /^https://music.163.com/#/song\?id=\d+$/
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Your code here...
// const API = "http://127.0.0.1:3000/api/v1/convert"
const API = "https://netease-ruby.kingbridge.one/api/v1/convert"
function main() {
const divMore = document.querySelector("div#flag_more")
const cssRules = `
span.jpn {
color: brown;
font-size: 15px;
}
`;
const styleElement = document.createElement('style');
styleElement.textContent = cssRules;
const head = document.head || document.getElementsByTagName('head')[0];
if (head) {
head.appendChild(styleElement);
} else {
console.error('head not found');
}
convert(getLyricContent())
.then(text => {
setLyricContent(text)
return convert(divMore.innerHTML)
}).then(text => {
divMore.innerHTML = text
}).catch(e => {
console.error(e)
})
}
function getLyricContent() {
const lyricContentElement = document.getElementById('lyric-content');
const clonedElement = lyricContentElement.cloneNode(true);
const directChildDivs = clonedElement.querySelectorAll(':scope > div');
directChildDivs.forEach(div => {
clonedElement.removeChild(div);
});
return clonedElement.innerHTML;
}
function setLyricContent(newHTML) {
const parentElement = document.getElementById('lyric-content');
const childDivsNodeList = parentElement.querySelectorAll(':scope > div');
const preservedDivs = Array.from(childDivsNodeList);
parentElement.innerHTML = newHTML;
preservedDivs.forEach(div => {
parentElement.appendChild(div);
});
}
async function convert(text) {
try {
const response = await fetch(API, {
method: 'POST',
body: text
});
if (!response.ok) {
throw new Error(`backend error: ${response.status} ${response.body}`);
}
return response.text();
} catch (e) {
throw new Error(`fetch API error: ` + e);
}
}
setTimeout(main, 500)
})();