Skip to content

Commit 6354147

Browse files
authored
Merge pull request #5 from JARVIS843/Feature-Branch
Added Several Features. Patched Bugs and Optimized Code
2 parents 2b6eef2 + 793bb0a commit 6354147

File tree

8 files changed

+232
-31
lines changed

8 files changed

+232
-31
lines changed

css/Popup.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.header{
2+
padding-left: 10px;
3+
padding-bottom: 5px;
4+
align-items: center;
5+
}
6+
7+
#name{
8+
font-weight: bold;
9+
font-size: 16px;
10+
}
11+
12+
.brdr {
13+
border-bottom: 1px solid rgb(221, 221, 221);
14+
}
15+
16+
body{
17+
width: 300px;
18+
}
19+
20+
h4{
21+
font-weight: normal;
22+
font-size: 16px;
23+
}
24+
25+
.switch-panel{
26+
padding-left: 15px;
27+
padding-bottom: 15px;
28+
}

css/switch.css

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.switch {
2+
position: relative;
3+
display: inline-block;
4+
width: 38px;
5+
height: 20px;
6+
margin-bottom: 0;
7+
flex-shrink: 0;
8+
}
9+
.switch input {
10+
display:none;
11+
}
12+
.switch span{
13+
position: absolute;
14+
left: 45px;
15+
width: 220px;
16+
font-size: 14px;
17+
}
18+
19+
.slider {
20+
position: absolute;
21+
cursor: pointer;
22+
top: 0;
23+
left: 0;
24+
right: 0;
25+
bottom: 0;
26+
background-color: #cccccc;
27+
-webkit-transition: .4s;
28+
transition: .4s;
29+
}
30+
.slider:before {
31+
position: absolute;
32+
content: "";
33+
height: 16px;
34+
width: 16px;
35+
left: 2px;
36+
bottom: 2px;
37+
/* background-color: #7769FE; */
38+
background-color: white;
39+
-webkit-transition: .4s;
40+
transition: .4s;
41+
}
42+
input:checked + .slider {
43+
background-color: #2163df;
44+
/* background-color: #afa7ff; */
45+
}
46+
input:checked + .slider:before {
47+
background: white;
48+
/* background: #7a6dff; */
49+
-webkit-transform: translateX(18px);
50+
-ms-transform: translateX(18px);
51+
transform: translateX(18px);
52+
}
53+
/* Rounded sliders */
54+
.slider.round {
55+
border-radius: 12px;
56+
}
57+
.slider.round:before {
58+
border-radius: 50%;
59+
}

html/Popup.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<!-- CSS only -->
6+
<!-- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous"> -->
7+
<link rel="stylesheet" href="../css/switch.css">
8+
<link rel="stylesheet" href="../css/Popup.css">
9+
<title>Document</title>
10+
</head>
11+
<body>
12+
<header>
13+
<div class="header brdr">
14+
<div id="name">Bionic Enhance Reading</div>
15+
</div>
16+
</header>
17+
<div class="switch-panel">
18+
<h4>Settings: </h4>
19+
<label class="switch">
20+
<input class="switcher" type="checkbox" id="Auto_Bold" checked="checked">
21+
<div class="slider round"></div>
22+
<span>Automatically Bold Websites</span>
23+
</label>
24+
<br>
25+
</div>
26+
<script src="../js/Popup.js"></script>
27+
</body>
28+
29+
30+
</html>

js/Algorithm.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//We probably don't need Unit Test
2+
3+
function ModifyTextBasic(textNodeContent)
4+
{
5+
return textNodeContent.split(' ').map((word) => {
6+
//TODO if the user wants numbers to be bolded
7+
//if(/\d/.test(word)) return word;
8+
9+
10+
var boldUp2 = Math.floor(Math.random() * Math.floor(word.length/2)); //TODO Add customizable length: 1/4 , 1/2 , 3/4 of a word etc..
11+
return word.replace(word, `<b>${word.substring(0, boldUp2+1)}</b>${word.substring(boldUp2+1)}`); //TODO Add customizable fonts & underline the words that are originally bolded
12+
});
13+
}
14+
15+
function ModifyTextSyllable(textNodeContent)
16+
{
17+
return textNodeContent.split(' ').map((word) => {
18+
//if(/\d/.test(word)) return word;
19+
20+
var vowel = /[aeiouy]/i;
21+
var match = vowel.exec(word);
22+
if(match != null)
23+
var boldUp2 = match.index;
24+
return word.replace(word, `<b>${word.substring(0, boldUp2+1)}</b>${word.substring(boldUp2+1)}`);
25+
});
26+
}
27+
28+
function ModifyWebPage()
29+
{
30+
const domParser = new DOMParser();
31+
var allText = [... document.getElementsByTagName('p')]; //TODO replace this with customizable Tags
32+
allText.forEach(element => {
33+
var text = domParser.parseFromString(element.innerHTML, "text/html");
34+
var textNodeCollection = Array.from(text.body.childNodes).map((node) => {
35+
if(node.nodeType === Node.TEXT_NODE)
36+
return ModifyTextBasic(node.textContent).join(' '); //Change this to ModifyTextSyllable when changing algorithm
37+
else
38+
return node.outerHTML;})
39+
element.innerHTML = textNodeCollection.join('');
40+
});
41+
}
42+
43+
ModifyWebPage();
44+
45+
46+
47+

js/Background.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//User Settings
2+
var userSettings = {
3+
Auto_Bold : true
4+
}
5+
6+
//First Initiallization of the Plugin
7+
chrome.runtime.onInstalled.addListener(() => {
8+
chrome.storage.sync.set({ userSettings });
9+
});
10+
11+
12+
//Bold a webpage once the user has switched to a new page
13+
chrome.tabs.onActivated.addListener((activeInfo) => {
14+
if(userSettings.Auto_Bold) //TODO Once a web is bolded, mark it as "Static" so that it will not be bold again
15+
chrome.scripting.executeScript({
16+
target: {tabId: activeInfo.tabId, allFrames: true},
17+
files: ['js/Algorithm.js'],
18+
});
19+
});
20+
21+
22+
chrome.runtime.onMessage.addListener((request , sender , sendResponse) => {
23+
24+
//Check if request contains info related to Auto_Bold
25+
if('Auto_Bold' in request)
26+
{
27+
userSettings.Auto_Bold = request.Auto_Bold;
28+
chrome.storage.sync.set({ userSettings });
29+
}
30+
31+
32+
//Since No responce is needed, close the Message Port
33+
return true;
34+
});

js/Popup.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//Initializations on Startup
2+
const Auto_Bold_Switch = document.getElementById('Auto_Bold');
3+
var userSettingsCopy;
4+
chrome.storage.sync.get( 'userSettings' , (result) => {
5+
userSettingsCopy = result.userSettings;
6+
7+
8+
Auto_Bold_Switch.checked = userSettingsCopy.Auto_Bold;
9+
});
10+
11+
12+
//Events
13+
Auto_Bold_Switch.addEventListener('change' , function(){
14+
var Bold_Status = Auto_Bold_Switch.checked;
15+
16+
chrome.runtime.sendMessage({Auto_Bold : Bold_Status});
17+
});

js/content.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

manifest.json

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
{
22
"manifest_version": 3,
33
"name": "Bionic Enhance Reader",
4-
"version": "0.0.1",
5-
"description": "Assist your reading with Bionic Enhance Reader",
6-
"icons": {
4+
"version": "0.0.2",
5+
"description": "Speed Up Your Reading By 10 Folds",
6+
"icons":
7+
{
78
"16": "img/icon16.png",
89
"48": "img/icon48.png",
910
"128":"img/icon128.png"
1011
},
11-
"content_scripts": [
12-
{
13-
"matches": ["https://*/*", "http://*/*"],
14-
"js": ["js/content.js"]
15-
}
16-
]
12+
"background":
13+
{
14+
"service_worker": "js/background.js"
15+
},
16+
"permissions": ["activeTab","scripting","storage","tabs"],
17+
"host_permissions": [
18+
"*://*/"
19+
],
20+
"action":
21+
{
22+
"default_popup": "html/Popup.html",
23+
"default_title": "Click to Basic Settings"
24+
}
1725
}

0 commit comments

Comments
 (0)