-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
254 lines (228 loc) · 7.24 KB
/
index.html
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<html>
<script>
const NCM21012 = `https://d1.music.126.net/dmusic/NeteaseCloudMusic_Music_official_2.10.13.202675_32.exe`;
const SAVE_FILENAME = `NeteaseCloudMusic_Music_official_2.10.13.202675_32.exe`;
const DATA_DIR = parent.window.betterncm_native.app.datapath() + '/downgrade_ok'
const CURRENT_VERSION = parent.window.APP_CONF.appver;
const TARGET_VERSION = '2.10.13.202675';
if (!parent.window.betterncm_native.fs.exists(DATA_DIR)) {
parent.window.betterncm.fs.mkdir(DATA_DIR);
}
const esc = JSON.stringify.bind(JSON);
const switchToPage = (page) => {
for (const page of document.querySelectorAll('.page')) {
page.style.opacity = '0';
page.style.pointerEvents = 'none';
page.style.maxHeight = '0';
}
const rPage = document.querySelector('.page' + page)
rPage.style.opacity = '1';
rPage.style.pointerEvents = 'all';
rPage.style.maxHeight = '1000px';
}
window.onload = () => {
switchToPage('1');
curr.innerText = `当前:${CURRENT_VERSION}\n目标:${TARGET_VERSION}`
}
const resourceList = [
'default.skin',
'native.ntpk',
'orpheus.ntpk',
]
const checkResources = () => {
for (const resource of resourceList) {
if (!parent.window.betterncm_native.fs.exists(DATA_DIR + '/data/' + resource)) {
return false;
}
}
return true;
}
const unzipResource = () => {
if (checkResources()) {
switchToPage('4');
return;
}
setTimeout(async () => {
const Path7Z = parent.window.dgOk_pluginPath + '/7z.exe';
await parent.window.betterncm.app.exec(`${esc(Path7Z)} e -o${esc(
DATA_DIR + '/data'
)} -aoa ${esc(
DATA_DIR + '/' + SAVE_FILENAME
)}`, 0, 1)
while (!checkResources()) {
await new Promise((resolve) => setTimeout(resolve, 400));
}
switchToPage('4');
}, 100)
}
const checkAndDownloadResource = async () => {
if (parent.window.betterncm_native.fs.exists(DATA_DIR + '/' + SAVE_FILENAME)) {
switchToPage('4');
// unzipResource()
return;
}
const res = await fetch(NCM21012);
// download with progress
const total = res.headers.get('content-length');
const reader = res.body.getReader();
let loaded = 0;
const chunks = [];
while (true) {
const {
done,
value
} = await reader.read();
if (done) {
break;
}
loaded += value.length;
chunks.push(value);
document.querySelector('.progressBar').style.setProperty('--progress', `${loaded / total * 100}%`);
}
// download complete
const blob = new Blob(chunks);
const url = URL.createObjectURL(blob);
parent.window.betterncm.fs.writeFile(
DATA_DIR + '/' + SAVE_FILENAME,
blob).then(() => {
switchToPage('4');
// unzipResource()
})
}
const runDowngrade = async () => {
const cmdUnlock = `powershell Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser -Force`
await parent.window.betterncm.app.exec(cmdUnlock, 1, 1)
await new Promise((resolve) => setTimeout(resolve, 500));
const PathScript = parent.window.dgOk_pluginPath + '/downgrade.ps1';
const cmd = `powershell ${esc(PathScript)} ${esc(DATA_DIR + '/' + SAVE_FILENAME)} ;pause`
console.log(cmd)
await parent.window.betterncm.app.exec(cmd, 1, 1)
}
</script>
<body>
<div class="container">
<div class="page1 page">
<div class="title">降级引导</div>
<div class="content">
<div id="curr"></div></br></br>
接下来,插件将把网易云前端版本降级至 2.10.12,以保证插件的正常运行。<br>
</div>
<div class="button">
<button onclick="switchToPage('2'); checkAndDownloadResource()">下一步</button>
<button onclick="parent.document.querySelector('body > iframe').remove()">取消</button>
</div>
</div>
<div class="page2 page">
<div class="title">下载旧版本资源</div>
<div class="content">
请稍等,正在下载资源...
</div>
<div class="progressBar" style="--progress:0%">
</div>
</div>
<div class="page3 page">
<div class="title">释放资源</div>
<div class="content">
请稍等,正在释放资源...
</div>
</div>
<div class="page4 page">
<div class="title">资源准备完成</div>
<div class="content">
点击确定以重启网易云音乐并完成前端降级。
</div>
<div class="button">
<button onclick="runDowngrade()">确定</button>
</div>
</div>
</div>
</body>
<style>
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@100;400;500;600;700;800;900&family=Noto+Sans:wght@100;200;300;400;500;600;700;800;900&display=swap');
body,
html {
background: #00000034;
border-radius: 8px;
}
* {
font-family: 'Noto Sans', 'Noto Sans SC';
}
.container {
height: max-content;
width: 400px;
min-height: 300px;
border-radius: 10px;
display: flex;
padding: 30px 50px;
background: rgba(0, 0, 0, 0.274);
transform: translate(-50%, -50%);
position: absolute;
top: 50%;
left: 50%;
backdrop-filter: blur(50px) brightness(0.5);
user-select: none;
}
.page {
transition: all .3s;
position: absolute;
top: 30px;
left: 50px;
opacity: 0;
pointer-events: none;
}
.title {
font-size: 30px;
font-weight: 800;
color: #fff;
}
.content {
font-size: 20px;
font-weight: 500;
color: #fff;
margin-top: 20px;
height: auto;
}
.button {
bottom: 40px;
position: fixed;
}
button {
background: #3e5661;
border: none;
border-radius: 500px;
padding: 10px 20px;
font-size: 20px;
font-weight: 500;
color: #ffffff;
margin-right: 20px;
cursor: pointer;
transition: 0.2s;
}
button:hover {
background: #3e5661a8;
}
button:active {
background: #3e566181;
}
.progressBar {
width: 100%;
height: 10px;
background: #ffffff23;
border-radius: 500px;
margin-top: 20px;
position: relative;
overflow: hidden;
}
.progressBar::before {
content: '';
width: var(--progress);
height: 100%;
background: #587583;
position: absolute;
top: 0;
left: 0;
transition: 0.3s;
border-radius: 500px;
}
</style>
</html>