Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Hello World" Extension Tutorial - Part 4
Adding a content script to manipulate the body of the displayed message.
- Loading branch information
Showing
4 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
async function showBanner() { | ||
let bannerDetails = await browser.runtime.sendMessage({ | ||
command: "getBannerDetails", | ||
}); | ||
|
||
// Get the details back from the formerly serialized content. | ||
const { text } = bannerDetails; | ||
|
||
// Create the banner element itself. | ||
const banner = document.createElement("div"); | ||
banner.className = "thunderbirdMessageDisplayActionExample"; | ||
|
||
// Create the banner text element. | ||
const bannerText = document.createElement("div"); | ||
bannerText.className = "thunderbirdMessageDisplayActionExample_Text"; | ||
bannerText.innerText = text; | ||
|
||
// Create a button to display it in the banner. | ||
const markUnreadButton = document.createElement("button"); | ||
markUnreadButton.innerText = "Mark unread"; | ||
markUnreadButton.addEventListener("click", async () => { | ||
// Add the button event handler to send the command to the | ||
// background script. | ||
browser.runtime.sendMessage({ | ||
command: "markUnread", | ||
}); | ||
}); | ||
|
||
// Add text and button to the banner. | ||
banner.appendChild(bannerText); | ||
banner.appendChild(markUnreadButton); | ||
|
||
// Insert it as the very first element in the message. | ||
document.body.insertBefore(banner, document.body.firstChild); | ||
}; | ||
|
||
showBanner(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.thunderbirdMessageDisplayActionExample { | ||
background-color: #d70022; | ||
color: white; | ||
font-weight: 400; | ||
padding: 0.25rem 0.5rem; | ||
margin-bottom: 0.25rem; | ||
display: flex; | ||
} | ||
|
||
.thunderbirdMessageDisplayActionExample_Text { | ||
flex-grow: 1; | ||
} |