DeezerTooter/deezer-tooter/browserAction/script.js
2020-09-30 09:14:04 +02:00

36 lines
1.1 KiB
JavaScript

function tootInfo(message) {
tootContent = message.artist + " - " + message.title
url = "http://localhost:5000/toot?content=" + tootContent
fetch(url)
.then(function (response) {
return response;
})
.then(function (response) {
console.log("Got response : " + response);
})
.catch(function (error) {
console.log("Error while tooting: " + error);
})
}
function handleResponse(message) {
document.getElementById("toot-info").innerHTML += message.artist + " - " + message.title
document.getElementById("toot-hashtags").value += "#radio #np #musique #music"
}
function handleError(error) {
console.log(`Error: ${error}`);
}
function getCurrentInfo () {
var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true})
gettingActiveTab.then((tabs) => {
browser.tabs.sendMessage(tabs[0].id, {command: "get-info"})
.then(handleResponse, handleError);
})
}
button = document.getElementById('toot-button')
button.onclick = tootInfo
document.addEventListener("click", getCurrentInfo)
browser.tabs.executeScript(null, { file: "/content_script.js" });