|
| 1 | +import { getCurrentTab } from "./helpers/utils.js"; |
| 2 | + |
1 | 3 | export default {
|
2 | 4 | icon: "https://zjs.zmdcdn.me/zmp3-desktop/releases/v1.7.64/static/media/icon_zing_mp3_60.f6b51045.svg",
|
3 | 5 | name: {
|
@@ -227,16 +229,40 @@ export default {
|
227 | 229 | };
|
228 | 230 |
|
229 | 231 | (async function () {
|
230 |
| - // window.open(await ZingMp3.search('game thủ liên minh')); |
| 232 | + // window.open(await ZingMp3.search("game thủ liên minh")); |
231 | 233 | // window.open(await ZingMp3.getLastPlaying());
|
232 | 234 | // window.open(await ZingMp3.getHome());
|
233 | 235 | // window.open(await ZingMp3.getChartHome());
|
234 |
| - // window.open(await ZingMp3.getInfoMusic('ZWFE8OUO')) |
| 236 | + // window.open(await ZingMp3.getInfoMusic("ZWFE8OUO")); |
| 237 | + // window.open(await ZingMp3.getStreaming("Z6WZD78I")); |
235 | 238 |
|
236 |
| - let url = prompt("Nhap link bai hat: ", location.href); |
| 239 | + const tab = await getCurrentTab(); |
| 240 | + let url = prompt("Nhap link bai hat: ", tab.url); |
237 | 241 | if (url) {
|
238 | 242 | let songid = ZingMp3.getSongIdFromURL(url);
|
239 |
| - if (songid) window.open(await ZingMp3.getStreaming(songid)); |
| 243 | + if (songid) { |
| 244 | + try { |
| 245 | + const streamUrl = await ZingMp3.getStreaming(songid); |
| 246 | + const res = await fetch(streamUrl); |
| 247 | + const json = await res.json(); |
| 248 | + console.log(json); |
| 249 | + if (json.err) throw new Error(json.msg); |
| 250 | + if (!json.data) throw new Error("No Data"); |
| 251 | + |
| 252 | + let options = Object.keys(json.data); |
| 253 | + let choice = prompt( |
| 254 | + "Chọn chất lượng nhạc: \n" + options.join("\n"), |
| 255 | + options[options.length - 1] |
| 256 | + ); |
| 257 | + |
| 258 | + if (choice !== null) { |
| 259 | + let url = json.data[choice]; |
| 260 | + window.open(url); |
| 261 | + } |
| 262 | + } catch (error) { |
| 263 | + alert("ERROR: " + error); |
| 264 | + } |
| 265 | + } |
240 | 266 | }
|
241 | 267 | })();
|
242 | 268 | },
|
|
0 commit comments