DeezerTooter/deezer-tooter/browserAction/script.js

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() {
document.getElementById("artist").innerText = message.artist
document.getElementById("title").innerText = message.title
}
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')
browser.browserAction.onClicked.addListener(getCurrentInfo)
button.onclick = tootInfo
browser.tabs.executeScript(null, { file: "/content_script.js" });