Skip to content

Instantly share code, notes, and snippets.

@davrous
Created November 24, 2016 18:31
Show Gist options
  • Save davrous/4219e0040fa222876198c8e2cbca245b to your computer and use it in GitHub Desktop.
Save davrous/4219e0040fa222876198c8e2cbca245b to your computer and use it in GitHub Desktop.
browser.tabs.query({ active: true, currentWindow: true }, (tabs) => {
browser.tabs.sendMessage(tabs[0].id, { command: "requestImages" }, (response) => {
this._imagesList = JSON.parse(response);
this._imagesList.forEach((element) => {
var newImageHTMLElement = document.createElement("img");
newImageHTMLElement.src = element.url;
newImageHTMLElement.alt = element.alt;
newImageHTMLElement.tabIndex = this._tabIndex;
this._tabIndex++;
newImageHTMLElement.addEventListener("focus", (event) => {
if (COMPUTERVISIONKEY !== "") {
this.analyzeThisImage(event.target.src);
}
else {
var warningMsg = document.createElement("div");
warningMsg.innerHTML = "<h2>Please generate a Computer Vision key in the other tab.</h2>";
this._targetDiv.insertBefore(warningMsg, this._targetDiv.firstChild);
browser.tabs.create({ active: false, url: "https://www.microsoft.com/cognitive-services/en-US/sign-up?ReturnUrl=/cognitive-services/en-us/subscriptions?productId=%2fproducts%2f54d873dd5eefd00dc474a0f4" });
}
});
this._targetDiv.appendChild(newImageHTMLElement);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment