-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
266bcd2
commit 9586fa8
Showing
9 changed files
with
137 additions
and
14 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.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Kick off the scripts conditional to if the base url | ||
* is a news site or not. | ||
* | ||
* @param {*} tab_id | ||
* @param {*} tab | ||
*/ | ||
async function kick_off_script(tab_id, tab) { | ||
try { | ||
await chrome.scripting.executeScript({ | ||
target: { tabId: tab_id }, | ||
files: ["./content.js"], | ||
}); | ||
} catch(error) { | ||
console.debug(error) | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Fires on selecting new tabs. | ||
*/ | ||
chrome.tabs.onActivated.addListener(async (activeInfo) => { | ||
chrome.tabs.query({ | ||
active: true, | ||
lastFocusedWindow: true | ||
}, async function(tabs) { | ||
const tab_id = activeInfo.tabId; | ||
const tab = tabs[0] | ||
await kick_off_script(tab_id, tab); | ||
}); | ||
}); | ||
|
||
|
||
/** | ||
* Fires on tabs updating, such as reloads. | ||
*/ | ||
chrome.tabs.onUpdated.addListener(async (tabID, changeInfo, tab) => { | ||
if(changeInfo.status == "complete") | ||
await kick_off_script(tabID, tab); | ||
}); |
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,44 @@ | ||
async function main() { | ||
const page_content = get_page_content(); | ||
await set_local_storage(page_content); | ||
} | ||
|
||
|
||
function get_page_content() { | ||
const considered_tags = ["h1"]; | ||
let content = ""; | ||
|
||
for (const tag of considered_tags) { | ||
const element_arr = document.getElementsByTagName(tag); | ||
for (const element of element_arr) { | ||
content += element.textContent | ||
content += " " | ||
} | ||
} | ||
const sample_size = 800; | ||
const body_text = document.body.innerText; | ||
const start_sample = parseInt(body_text.length/10); | ||
let body_text_sample = body_text.slice(start_sample, start_sample+sample_size); | ||
content += body_text_sample; | ||
|
||
return content; | ||
} | ||
|
||
|
||
async function set_local_storage(page_content) { | ||
return new Promise(function(resolve, reject) { | ||
const website_url = window.location.toString(); | ||
let url_to_content_map = {} | ||
url_to_content_map[website_url] = page_content; | ||
|
||
chrome.storage.local.set( | ||
{page_content: url_to_content_map}, | ||
function() { | ||
resolve(); | ||
} | ||
); | ||
}); | ||
} | ||
|
||
|
||
main(); |
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