mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-23 09:42:49 +02:00
Ensure tabID is unchanged; fix image styles
This commit is contained in:
@@ -35,8 +35,7 @@
|
|||||||
function insertBeast(beastURL) {
|
function insertBeast(beastURL) {
|
||||||
var beastImage = document.createElement("img");
|
var beastImage = document.createElement("img");
|
||||||
beastImage.setAttribute("src", beastURL);
|
beastImage.setAttribute("src", beastURL);
|
||||||
beastImage.setAttribute("style", "width: 100vw");
|
beastImage.style.height = "100vh";
|
||||||
beastImage.setAttribute("style", "height: 100vh");
|
|
||||||
document.body.appendChild(beastImage);
|
document.body.appendChild(beastImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,23 +27,23 @@ If it's on a button which contains class "clear":
|
|||||||
*/
|
*/
|
||||||
document.addEventListener("click", (e) => {
|
document.addEventListener("click", (e) => {
|
||||||
|
|
||||||
function messageBeastify() {
|
function reportError(error) {
|
||||||
var chosenBeast = e.target.textContent;
|
console.error(`Could not beastify: ${error}`);
|
||||||
var chosenBeastURL = beastNameToURL(chosenBeast);
|
}
|
||||||
var gettingActiveTab = browser.tabs.query({active: true, currentWindow: true});
|
|
||||||
gettingActiveTab.then((tabs) => {
|
function beastify(tabs) {
|
||||||
browser.tabs.sendMessage(tabs[0].id, {beastURL: chosenBeastURL});
|
browser.tabs.executeScript(tabs[0].id, {
|
||||||
|
file: "/content_scripts/beastify.js"
|
||||||
|
}).then(() => {
|
||||||
|
var chosenBeast = e.target.textContent;
|
||||||
|
var url = beastNameToURL(chosenBeast);
|
||||||
|
browser.tabs.sendMessage(tabs[0].id, {beastURL: url});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function reportError(error) {
|
|
||||||
console.error(`Could not inject content script: ${error}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.target.classList.contains("beast")) {
|
if (e.target.classList.contains("beast")) {
|
||||||
browser.tabs.executeScript({
|
browser.tabs.query({active: true, currentWindow: true})
|
||||||
file: "/content_scripts/beastify.js"
|
.then(beastify)
|
||||||
}).then(messageBeastify)
|
|
||||||
.catch(reportError);
|
.catch(reportError);
|
||||||
}
|
}
|
||||||
else if (e.target.classList.contains("clear")) {
|
else if (e.target.classList.contains("clear")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user