import '../../../literyz-js/extensions.dist.js';


class PopupService {

    async SendMessage(eventName, callback) {
        chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
            chrome.tabs.sendMessage(tabs[0].id, { event: eventName }, callback);
        });
    }

    async GetHyperlinks() {
        const a = this;

        return new Promise(function(resolve) {
            a.SendMessage("GetHyperlinkNodes", async function(payload) {
                resolve(payload.copy());
            });
        });

    }

    async GetImages() {
        const a = this;

        return new Promise(function(resolve) {
            a.SendMessage("GetImageNodes", async function(payload) {
                resolve(payload.copy());
            });
        });

    }

    async GetLocation() {
        const a = this;

        return new Promise(function(resolve) {
            a.SendMessage("GetLocation", function(payload) {
                resolve(payload);
            });
        });
    }

}


export default PopupService;