cyp/app/js/yt.js

39 lines
859 B
JavaScript
Raw Normal View History

2019-03-29 04:43:18 +08:00
import * as mpd from "./lib/mpd.js";
import * as html from "./lib/html.js";
import * as pubsub from "./lib/pubsub.js";
import * as ui from "./lib/ui.js";
2019-03-31 05:05:33 +08:00
import * as conf from "./conf.js";
2019-03-29 04:43:18 +08:00
let node;
async function onClick(e) {
let url = prompt("Please enter a YouTube URL:");
if (!url) { return; }
2019-03-31 05:05:33 +08:00
let button = e.target;
button.disabled = true;
let p = node.querySelector("p");
p.textContent = "";
2019-03-29 04:43:18 +08:00
let body = new URLSearchParams();
body.set("url", url);
let response = await fetch("/youtube", {method:"POST", body});
let text = await response.text();
2019-03-31 05:05:33 +08:00
button.disabled = false;
p.textContent = text;
if (response.status == 200) {
mpd.command(`update ${mpd.escape(conf.ytPath)}`);
}
2019-03-29 04:43:18 +08:00
}
export async function activate() {}
export function init(n) {
node = n;
2019-03-29 05:52:57 +08:00
let button = node.querySelector(".go").addEventListener("click", onClick);
2019-03-29 04:43:18 +08:00
}