-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculate the total size of the page.
- Loading branch information
Showing
7 changed files
with
154 additions
and
156 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,19 +1,18 @@ | ||
'use strict'; | ||
|
||
// With background scripts you can communicate with popup | ||
// and contentScript files. | ||
// For more information on background script, | ||
// See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Anatomy_of_a_WebExtension#Background_scripts | ||
browser.webRequest.onCompleted.addListener( | ||
function(details) { | ||
|
||
browser.runtime.onMessage.addListener((request, sender) => { | ||
if (request.type === 'GREETINGS') { | ||
const message: string = `Hi ${ | ||
sender.tab ? 'Con' : 'Pop' | ||
}, my name is Bac. I am from Background. It's great to hear from you.`; | ||
const contentLengthHeader = details.responseHeaders?.find(header => header.name.toLowerCase() === 'content-length'); | ||
|
||
// Log message coming from the `request` parameter | ||
console.log(request.payload.message); | ||
// Send a response message | ||
return Promise.resolve({ message }); | ||
} | ||
}); | ||
const responseSize = contentLengthHeader?.value ? parseInt(contentLengthHeader.value, 10) : 0; | ||
browser.storage.local.get({ totalSize: 0 }).then(function(result) { | ||
|
||
const newTotalSize = parseInt(result.totalSize,10) + responseSize; | ||
|
||
browser.storage.local.set({ totalSize: newTotalSize }); | ||
}); | ||
}, | ||
{ urls: ["<all_urls>"] }, | ||
["responseHeaders"] | ||
); |
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 |
---|---|---|
@@ -1,44 +1,20 @@ | ||
'use strict'; | ||
|
||
// Content script file will run in the context of web page. | ||
// With content script you can manipulate the web pages using | ||
// Document Object Model (DOM). | ||
// You can also pass information to the parent extension. | ||
|
||
// We execute this script by making an entry in manifest.json file | ||
// under `content_scripts` property | ||
|
||
// For more information on Content Scripts, | ||
// See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Anatomy_of_a_WebExtension#Content_scripts | ||
|
||
// Log `title` of current active web page | ||
const pageTitle: string = | ||
document.head.getElementsByTagName('title')[0].innerHTML; | ||
console.log( | ||
`Page title is: '${pageTitle}' - evaluated by the extension's 'contentScript.js' file` | ||
); | ||
|
||
// Communicate with background file by sending a message | ||
browser.runtime.sendMessage( | ||
{ | ||
type: 'GREETINGS', | ||
payload: { | ||
message: 'Hello, my name is Con. I am from ContentScript.', | ||
}, | ||
} | ||
).then((response) => { | ||
console.log(response.message); | ||
}); | ||
|
||
// Listen for message | ||
browser.runtime.onMessage.addListener((request, sender) => { | ||
console.log({ request, sender }) | ||
|
||
if (request.type === 'COUNT') { | ||
console.log(`Current count is ${request.payload.count}`); | ||
} | ||
|
||
// Send an empty response | ||
// See: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage | ||
return Promise.resolve(); | ||
}); | ||
// browser.runtime.onMessage.addListener((request, sender) => { | ||
// console.log({ request, sender }) | ||
// | ||
// if (request.type === 'COUNT') { | ||
// console.log(`Current count is ${request.payload.count}`); | ||
// } | ||
// | ||
// // Send an empty response | ||
// // See: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage | ||
// return Promise.resolve(); | ||
// }); |
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