const handleUpdated = (tabId, changeInfo, tabInfo) => {
    if (changeInfo.url) {
        var http = "http://www.youtube.com/watch?v=";
        var https = "https://www.youtube.com/watch?v=";
        var url = changeInfo.url;

        if (url.includes(http) || url.includes(https)) {
            browser.tabs.insertCSS(tabId, {
                file: "/styles/betterYoutube.css"
            });

            browser.tabs.executeScript(tabId, {
                file: "/scripts/betterYoutube.js"
            });
        }
    }
}

const notify = (data) => {
    let port = browser.runtime.connectNative("web_video_dl");
    console.log("Downloding: " + data.url);
    port.postMessage(data.url);
}

browser.runtime.onMessage.addListener(notify);
browser.tabs.onUpdated.addListener(handleUpdated);
