From 906d5676f4f7af6b744b2ae5455d7837275833e6 Mon Sep 17 00:00:00 2001 From: Jarvis H Yang <46472696+JARVIS843@users.noreply.github.com> Date: Sun, 22 May 2022 00:14:14 +0800 Subject: [PATCH 01/15] Update README.md updated feature branch readme --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index aa6d6f8..c98b7f1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # Bionic-Enhance-Reader ## Description -A Chrome Extension Used to Assist Your Reading Experience. Inspired by an aritcle related to Bionic Reading +This is the feature branch of Bionic Enhance Reader. -## Installation -Currently, this package is still not published, so just use add unpacked feature in Google Chrome Development mode +## Features Planned: +1. Customizable Text Style & Color +2. Customizable frequency of bolding +3. Customizable bolding extent +4. Optional integration with Bionic Read API +5. More features incoming... From 5140f944dfb0c11ba7342684ef56ec56624d45d8 Mon Sep 17 00:00:00 2001 From: Jarvis H Yang <46472696+JARVIS843@users.noreply.github.com> Date: Mon, 23 May 2022 00:27:37 +0800 Subject: [PATCH 02/15] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c98b7f1..34c73c0 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,6 @@ This is the feature branch of Bionic Enhance Reader. 2. Customizable frequency of bolding 3. Customizable bolding extent 4. Optional integration with Bionic Read API -5. More features incoming... +5. Cuztomizable URLs to bold (whitelist / blacklist) +6. Text & Background Coloring +7. More features incoming... From 2e04fcc27c9c111e2d432e173c6d60d90bc97860 Mon Sep 17 00:00:00 2001 From: Jarvis H Yang Date: Mon, 23 May 2022 16:43:33 +0800 Subject: [PATCH 03/15] Update content.js -Fixed over-bolding bug --- js/content.js | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/js/content.js b/js/content.js index 0f6c826..2bb19c2 100644 --- a/js/content.js +++ b/js/content.js @@ -1,22 +1,33 @@ -var allText = document.getElementsByTagName('p'); -for (var i = 0; i < allText.length; i++) { - var text = allText[i].innerText; - var newText = ''; - var words = text.split(' '); - for (var j = 0; j < words.length; j++) { - var word = words[j]; - var random = Math.floor(Math.random() * 4); - var newWord = ''; - for (var k = 0; k < word.length; k++) { - if (k <= random) { - newWord += '' + word[k] + ''; - } - else { - newWord += word[k]; + + +function randomBold() { + var allText = document.getElementsByTagName('p'); + for (var i = 0; i < allText.length; i++) { + var text = allText[i].textContent; + var newText = ''; + var words = text.split(' '); + for (var j = 0; j < words.length; j++) { + + var word = words[j]; + + var random = Math.floor(Math.random() * Math.floor(word.length/2)); + var newWord = ''; + for (var k = 0; k < word.length; k++) { + if (k <= random) { + newWord += '' + word[k] + ''; + } + else { + newWord += word[k]; + } } + newText += newWord + ' '; + } - newText += newWord + ' '; + allText[i].innerHTML = newText; } - allText[i].innerHTML = newText; } +randomBold(); + + + From b1388fc936ed2d68a76cf6dfad523cfdae218664 Mon Sep 17 00:00:00 2001 From: Jarvis H Yang Date: Tue, 24 May 2022 03:09:28 +0800 Subject: [PATCH 04/15] Patched Minor Bugs -Fixed the bug that eliminates hyperlinks and imgs -Opimized Algorith --- README.md | 9 ++++---- js/content.js | 57 ++++++++++++++++++++++++++++----------------------- manifest.json | 2 +- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 34c73c0..c7f9b8d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ This is the feature branch of Bionic Enhance Reader. 1. Customizable Text Style & Color 2. Customizable frequency of bolding 3. Customizable bolding extent -4. Optional integration with Bionic Read API -5. Cuztomizable URLs to bold (whitelist / blacklist) -6. Text & Background Coloring -7. More features incoming... +4. A Popup Menu +5. Optional integration with Bionic Read API +6. Cuztomizable URLs to bold (whitelist / blacklist) +7. Text & Background Coloring +8. More features incoming... diff --git a/js/content.js b/js/content.js index 2bb19c2..571a383 100644 --- a/js/content.js +++ b/js/content.js @@ -1,33 +1,38 @@ +//We probably don't need Unit Test +function ModifyText(textNodeContent) +{ + return textNodeContent.split(' ').map((word) => { + //TODO if the user wants numbers to be bolded + //if(/\d/.test(word)) return word; -function randomBold() { - var allText = document.getElementsByTagName('p'); - for (var i = 0; i < allText.length; i++) { - var text = allText[i].textContent; - var newText = ''; - var words = text.split(' '); - for (var j = 0; j < words.length; j++) { - - var word = words[j]; - - var random = Math.floor(Math.random() * Math.floor(word.length/2)); - var newWord = ''; - for (var k = 0; k < word.length; k++) { - if (k <= random) { - newWord += '' + word[k] + ''; - } - else { - newWord += word[k]; - } - } - newText += newWord + ' '; - - } - allText[i].innerHTML = newText; - } + + 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.. + return word.replace(word, `${word.substring(0, boldUp2+1)}${word.substring(boldUp2+1)}`); //TODO Add customizable fonts & underline the words that are originally bolded + }); } -randomBold(); + +function SampleWebPage() +{ + const domParser = new DOMParser(); + var allText = [... document.getElementsByTagName('p')]; //TODO replace this with customizable Tags + allText.forEach(element => { + var text = domParser.parseFromString(element.innerHTML, "text/html"); + var textNodeCollection = Array.from(text.body.childNodes).map((node) => { + if(node.nodeType === Node.TEXT_NODE) + { + return ModifyText(node.textContent).join(' '); + } + + else + return node.outerHTML;}) + element.innerHTML = textNodeCollection.join(''); + }); +} + +SampleWebPage(); + diff --git a/manifest.json b/manifest.json index 936f495..3a6ce0e 100644 --- a/manifest.json +++ b/manifest.json @@ -10,7 +10,7 @@ }, "content_scripts": [ { - "matches": ["https://*/*", "http://*/*"], + "matches": [""], "js": ["js/content.js"] } ] From fbd92b27c06f03a11bedee7433885c678d54208f Mon Sep 17 00:00:00 2001 From: Thomas40522 <73463155+Thomas40522@users.noreply.github.com> Date: Tue, 24 May 2022 13:23:02 +0800 Subject: [PATCH 05/15] Popup Menu Added user interface, but interacting function isn't working --- .DS_Store | Bin 0 -> 6148 bytes css/content.css | 29 +++++++++++++++++++++++ css/switch.css | 59 ++++++++++++++++++++++++++++++++++++++++++++++ html/content.html | 31 ++++++++++++++++++++++++ js/content.js | 21 ++++++++++++++++- manifest.json | 3 +++ 6 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 css/content.css create mode 100644 css/switch.css create mode 100644 html/content.html diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0f97bb59eff016bcbaa21816aeffd2c5780172af GIT binary patch literal 6148 zcmeHK!EVz)5S>j7b%H8#Kx&V^RN_!owVyFA<6EB=LzlMC76|I&E~n5Vmu> zAPqCaM!{>>)FP;`>W}lzO zXIWa5+uL76qv>3^y5hQRx4qha9**QRETeK#bffW89zBT4QEc=_Qf3Q1iXW%L=~3s# zzRb%g&4*(ZoF+rKJbRMniJW%jBu@&pPN)s8+j3h+o%Pww-`Uyp{9FEf)0^$yfqvWH zozGkD+J?V3I6i&zcJ^-m{-gd50tc0n>jroUx(v7llcke*uP0B=sBs;^BI<( z>1og_Dwci3TFqyL?$dzwsZWO#QorW?q2|4ctP$nN{*s1N;3I8u4w97DBEQxmTl5e) z?op2pfLmB6S&nE#wFnHYTrLL8R&cLfuCi^lmI2GaA27h@gNMc#7_2m^qXV6K0stLM zD}kFJ4Rz+ze=MD kL1(UGrSMg}j-~`Qj}>5Gu+oSbi2V^zG}z8E@K+i54kF%|t^fc4 literal 0 HcmV?d00001 diff --git a/css/content.css b/css/content.css new file mode 100644 index 0000000..8497d8d --- /dev/null +++ b/css/content.css @@ -0,0 +1,29 @@ +.header{ + padding-left: 15px; + padding-bottom: 15px; + padding-top: 10px; + align-items: center; +} + +#name{ + font-weight: bold; + font-size: 20px; +} + +.brdr { + border-bottom: 1px solid rgb(221, 221, 221); +} + +body{ + width: 200px; +} + +h4{ + font-weight: normal; + font-size: 16px; +} + +.switch-panel{ + padding-left: 15px; + padding-bottom: 15px; +} \ No newline at end of file diff --git a/css/switch.css b/css/switch.css new file mode 100644 index 0000000..aa83ad8 --- /dev/null +++ b/css/switch.css @@ -0,0 +1,59 @@ +.switch { + position: relative; + display: inline-block; + width: 38px; + height: 20px; + margin-bottom: 0; + flex-shrink: 0; + } + .switch input { + display:none; + } + .switch span{ + position: absolute; + left: 45px; + width: 100px; + font-size: 14px; + } + + .slider { + position: absolute; + cursor: pointer; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: #cccccc; + -webkit-transition: .4s; + transition: .4s; + } + .slider:before { + position: absolute; + content: ""; + height: 16px; + width: 16px; + left: 2px; + bottom: 2px; + /* background-color: #7769FE; */ + background-color: white; + -webkit-transition: .4s; + transition: .4s; + } + input:checked + .slider { + background-color: #2163df; + /* background-color: #afa7ff; */ + } + input:checked + .slider:before { + background: white; + /* background: #7a6dff; */ + -webkit-transform: translateX(18px); + -ms-transform: translateX(18px); + transform: translateX(18px); + } + /* Rounded sliders */ + .slider.round { + border-radius: 12px; + } + .slider.round:before { + border-radius: 50%; + } diff --git a/html/content.html b/html/content.html new file mode 100644 index 0000000..88f6715 --- /dev/null +++ b/html/content.html @@ -0,0 +1,31 @@ + + + + + + + + + + Document + + +
+
+
Bionic Reading
+
+
+
+

Enable Function:

+ +
+
+ + + + + \ No newline at end of file diff --git a/js/content.js b/js/content.js index 571a383..ecdfb8a 100644 --- a/js/content.js +++ b/js/content.js @@ -31,7 +31,26 @@ function SampleWebPage() }); } -SampleWebPage(); +document.addEventListener("DOMContentLoaded", function(){ + + var sw1 = JSON.parse(localStorage.getItem("#sw1")) + if(!sw1){ + document.querySelector("#sw1").click(); + } //set the checkbox to false if the value stored is false + + Clicked("#sw1"); + + if(document.querySelector("#sw1").checked){ + SampleWebPage(); + console.log("work") + } +}) //document setup not working for now + +function Clicked(sw_id){ + document.querySelector(sw_id).addEventListener("click",function(){ + localStorage.setItem(sw_id, document.querySelector(sw_id).checked) + }) +} //identify when switch is clicked diff --git a/manifest.json b/manifest.json index 3a6ce0e..86f9ba0 100644 --- a/manifest.json +++ b/manifest.json @@ -8,6 +8,9 @@ "48": "img/icon48.png", "128":"img/icon128.png" }, + "action": { + "default_popup": "html/content.html" + }, "content_scripts": [ { "matches": [""], From 9c477b88e54907a01637ba119e811c92a0022950 Mon Sep 17 00:00:00 2001 From: Thomas40522 <73463155+Thomas40522@users.noreply.github.com> Date: Tue, 24 May 2022 23:20:34 +0800 Subject: [PATCH 06/15] Update .DS_Store --- .DS_Store | Bin 6148 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.DS_Store b/.DS_Store index 0f97bb59eff016bcbaa21816aeffd2c5780172af..114b40392b07a2fe0d8d41ad86f5c793621549ee 100644 GIT binary patch delta 105 zcmZoMXfc@J&&kcez`)4BAi%IOY9q5I0|SW9%#h4b%uwu^lb@WFlb-|>5ddOqAfE9b v3>X+T^RVPGvNADbF%(aBV7Va(W|ajO<>ln(r2`c*ZZ2o7WZcZo@s}R}6ucWX delta 43 zcmZoMXfc@J&&|QWz`)4BAi&_6voT^LGb6`lBbGeI%@f(m7&kVEGj3+*_{$Ff-DL|G From 1eb1db692d618ab7eed8c18e0b0d561ba93e8ffc Mon Sep 17 00:00:00 2001 From: Thomas40522 <73463155+Thomas40522@users.noreply.github.com> Date: Tue, 24 May 2022 23:43:21 +0800 Subject: [PATCH 07/15] d d --- js/content.js | 48 ++++++++++++++++++++++++++++++++---------------- test.html | 12 ++++++++++++ 2 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 test.html diff --git a/js/content.js b/js/content.js index ecdfb8a..eb4426f 100644 --- a/js/content.js +++ b/js/content.js @@ -12,6 +12,22 @@ function ModifyText(textNodeContent) }); } +function ModifyTextUpgrade(textNodeContent) +{ + return pronouncing.syllableCount(textNodeContent) + return textNodeContent.split(' ').map((word) => { + //TODO if the user wants numbers to be bolded + //if(/\d/.test(word)) return word; + + + 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.. + return word.replace(word, `${word.substring(0, boldUp2+1)}${word.substring(boldUp2+1)}`); //TODO Add customizable fonts & underline the words that are originally bolded + }); +} + +document.addEventListener("DOMContentLoaded", function(){ + console.log(ModifyTextUpgrade("abandon")) +}) function SampleWebPage() { @@ -31,26 +47,26 @@ function SampleWebPage() }); } -document.addEventListener("DOMContentLoaded", function(){ +// document.addEventListener("DOMContentLoaded", function(){ - var sw1 = JSON.parse(localStorage.getItem("#sw1")) - if(!sw1){ - document.querySelector("#sw1").click(); - } //set the checkbox to false if the value stored is false +// var sw1 = JSON.parse(localStorage.getItem("#sw1")) +// if(!sw1){ +// document.querySelector("#sw1").click(); +// } //set the checkbox to false if the value stored is false - Clicked("#sw1"); +// Clicked("#sw1"); - if(document.querySelector("#sw1").checked){ - SampleWebPage(); - console.log("work") - } -}) //document setup not working for now +// if(document.querySelector("#sw1").checked){ +// SampleWebPage(); +// console.log("work") +// } +// }) //document setup not working for now -function Clicked(sw_id){ - document.querySelector(sw_id).addEventListener("click",function(){ - localStorage.setItem(sw_id, document.querySelector(sw_id).checked) - }) -} //identify when switch is clicked +// function Clicked(sw_id){ +// document.querySelector(sw_id).addEventListener("click",function(){ +// localStorage.setItem(sw_id, document.querySelector(sw_id).checked) +// }) +// } //identify when switch is clicked diff --git a/test.html b/test.html new file mode 100644 index 0000000..9927592 --- /dev/null +++ b/test.html @@ -0,0 +1,12 @@ + + + + + + + Document + + + + + \ No newline at end of file From e758f42b244601b9961fbcb9fb7c2da654607e8b Mon Sep 17 00:00:00 2001 From: Jarvis H Yang Date: Tue, 24 May 2022 23:43:56 +0800 Subject: [PATCH 08/15] Completed Settingup Popup -Added Popup.js -Renamed css files -Uses "Scripting" and "ActiveTab" in Permissions --- css/{content.css => Popup.css} | 9 ++++----- css/switch.css | 2 +- html/{content.html => Popup.html} | 11 +++++------ js/Popup.js | 26 ++++++++++++++++++++++++++ js/content.js | 25 ++----------------------- manifest.json | 16 ++++++---------- 6 files changed, 44 insertions(+), 45 deletions(-) rename css/{content.css => Popup.css} (69%) rename html/{content.html => Popup.html} (76%) create mode 100644 js/Popup.js diff --git a/css/content.css b/css/Popup.css similarity index 69% rename from css/content.css rename to css/Popup.css index 8497d8d..4bdfa79 100644 --- a/css/content.css +++ b/css/Popup.css @@ -1,13 +1,12 @@ .header{ - padding-left: 15px; - padding-bottom: 15px; - padding-top: 10px; + padding-left: 10px; + padding-bottom: 5px; align-items: center; } #name{ font-weight: bold; - font-size: 20px; + font-size: 16px; } .brdr { @@ -15,7 +14,7 @@ } body{ - width: 200px; + width: 300px; } h4{ diff --git a/css/switch.css b/css/switch.css index aa83ad8..a5a50d1 100644 --- a/css/switch.css +++ b/css/switch.css @@ -12,7 +12,7 @@ .switch span{ position: absolute; left: 45px; - width: 100px; + width: 220px; font-size: 14px; } diff --git a/html/content.html b/html/Popup.html similarity index 76% rename from html/content.html rename to html/Popup.html index 88f6715..2957ee4 100644 --- a/html/content.html +++ b/html/Popup.html @@ -1,31 +1,30 @@ - - + Document
-
Bionic Reading
+
Bionic Enhance Reading
-

Enable Function:

+

Settings:


+ - \ No newline at end of file diff --git a/js/Popup.js b/js/Popup.js new file mode 100644 index 0000000..aa164f0 --- /dev/null +++ b/js/Popup.js @@ -0,0 +1,26 @@ +document.addEventListener("DOMContentLoaded", function(){ + + var sw1 = JSON.parse(localStorage.getItem("#sw1")) + if(!sw1) + { + document.querySelector("#sw1").click(); + } //set the checkbox to false if the value stored is false + + Clicked("#sw1"); + + if(document.querySelector("#sw1").checked) + chrome.tabs.query({ active: true, currentWindow: true } , function(activeTab){ + chrome.scripting.executeScript({ + target: {tabId: activeTab[0].id, allFrames: true}, + files: ['js/content.js'], + }); + }); + +}) //FIXME document setup not working for now + +function Clicked(sw_id){ + document.querySelector(sw_id).addEventListener("click",function(){ + localStorage.setItem(sw_id, document.querySelector(sw_id).checked) + }) +} //identify when switch is clicked + diff --git a/js/content.js b/js/content.js index ecdfb8a..04d8895 100644 --- a/js/content.js +++ b/js/content.js @@ -13,7 +13,7 @@ function ModifyText(textNodeContent) } -function SampleWebPage() +function ModifyWebPage() { const domParser = new DOMParser(); var allText = [... document.getElementsByTagName('p')]; //TODO replace this with customizable Tags @@ -21,36 +21,15 @@ function SampleWebPage() var text = domParser.parseFromString(element.innerHTML, "text/html"); var textNodeCollection = Array.from(text.body.childNodes).map((node) => { if(node.nodeType === Node.TEXT_NODE) - { return ModifyText(node.textContent).join(' '); - } - else return node.outerHTML;}) element.innerHTML = textNodeCollection.join(''); }); } -document.addEventListener("DOMContentLoaded", function(){ - var sw1 = JSON.parse(localStorage.getItem("#sw1")) - if(!sw1){ - document.querySelector("#sw1").click(); - } //set the checkbox to false if the value stored is false - - Clicked("#sw1"); - - if(document.querySelector("#sw1").checked){ - SampleWebPage(); - console.log("work") - } -}) //document setup not working for now - -function Clicked(sw_id){ - document.querySelector(sw_id).addEventListener("click",function(){ - localStorage.setItem(sw_id, document.querySelector(sw_id).checked) - }) -} //identify when switch is clicked +ModifyWebPage(); diff --git a/manifest.json b/manifest.json index 86f9ba0..2dbc633 100644 --- a/manifest.json +++ b/manifest.json @@ -1,20 +1,16 @@ { "manifest_version": 3, "name": "Bionic Enhance Reader", - "version": "0.0.1", - "description": "Assist your reading with Bionic Enhance Reader", + "version": "0.0.2", + "description": "Speed Up Your Reading By 10 Folds", "icons": { "16": "img/icon16.png", "48": "img/icon48.png", "128":"img/icon128.png" }, + "permissions": ["activeTab","scripting"], "action": { - "default_popup": "html/content.html" - }, - "content_scripts": [ - { - "matches": [""], - "js": ["js/content.js"] - } - ] + "default_popup": "html/Popup.html", + "default_title": "Click to Access Advanced Features" + } } \ No newline at end of file From 9a6e67a2cc49705ae6a7e01dd76258267e9df284 Mon Sep 17 00:00:00 2001 From: Thomas40522 <73463155+Thomas40522@users.noreply.github.com> Date: Tue, 24 May 2022 23:45:45 +0800 Subject: [PATCH 09/15] Update content.js --- js/content.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/js/content.js b/js/content.js index eb4426f..0066107 100644 --- a/js/content.js +++ b/js/content.js @@ -47,26 +47,26 @@ function SampleWebPage() }); } -// document.addEventListener("DOMContentLoaded", function(){ +document.addEventListener("DOMContentLoaded", function(){ -// var sw1 = JSON.parse(localStorage.getItem("#sw1")) -// if(!sw1){ -// document.querySelector("#sw1").click(); -// } //set the checkbox to false if the value stored is false + var sw1 = JSON.parse(localStorage.getItem("#sw1")) + if(!sw1){ + document.querySelector("#sw1").click(); + } //set the checkbox to false if the value stored is false -// Clicked("#sw1"); + Clicked("#sw1"); -// if(document.querySelector("#sw1").checked){ -// SampleWebPage(); -// console.log("work") -// } -// }) //document setup not working for now + if(document.querySelector("#sw1").checked){ + SampleWebPage(); + console.log("work") + } +}) //document setup not working for now -// function Clicked(sw_id){ -// document.querySelector(sw_id).addEventListener("click",function(){ -// localStorage.setItem(sw_id, document.querySelector(sw_id).checked) -// }) -// } //identify when switch is clicked +function Clicked(sw_id){ + document.querySelector(sw_id).addEventListener("click",function(){ + localStorage.setItem(sw_id, document.querySelector(sw_id).checked) + }) +} //identify when switch is clicked From 4a1c9ad2b6a3eb780831514ebbd1e0b35322d533 Mon Sep 17 00:00:00 2001 From: Jarvis H Yang Date: Tue, 24 May 2022 23:51:38 +0800 Subject: [PATCH 10/15] Delete .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 114b40392b07a2fe0d8d41ad86f5c793621549ee..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~(QeZ)6o!x6z|x|LULb9kxk2J$nij#tBs3{>?L{R(h#Lwf-Q$eScE{VIf zEH0kqXJ$S49-pO2UhM4r5RImDceqI90nX>Cf|HxN3=OEsOlPs0l3Hms` zNeS?r)bM=6$VEI2dQ(R&HkQS#Dn13EhHi}>(0~r8Pmd_1eifnkRKv3l%n@b4{hCI2 za|_yLs3a+?W&W&Xw&)42ai4nh5W0rn;qW&`+qVXuo@GJET# xo8!IKLpefW Date: Tue, 24 May 2022 23:54:53 +0800 Subject: [PATCH 11/15] delete unessessary part --- js/Popup.js | 2 +- js/content.js | 28 +++------------------------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/js/Popup.js b/js/Popup.js index aa164f0..259b69e 100644 --- a/js/Popup.js +++ b/js/Popup.js @@ -1,4 +1,4 @@ -document.addEventListener("DOMContentLoaded", function(){ +document.addEventListdener("DOMContentLoaded", function(){ var sw1 = JSON.parse(localStorage.getItem("#sw1")) if(!sw1) diff --git a/js/content.js b/js/content.js index 92c7b16..efab723 100644 --- a/js/content.js +++ b/js/content.js @@ -25,9 +25,9 @@ function ModifyTextUpgrade(textNodeContent) }); } -document.addEventListener("DOMContentLoaded", function(){ - console.log(ModifyTextUpgrade("abandon")) -}) +// document.addEventListener("DOMContentLoaded", function(){ +// console.log(ModifyTextUpgrade("abandon")) +// }) function ModifyWebPage() { @@ -44,27 +44,5 @@ function ModifyWebPage() }); } -document.addEventListener("DOMContentLoaded", function(){ - - var sw1 = JSON.parse(localStorage.getItem("#sw1")) - if(!sw1){ - document.querySelector("#sw1").click(); - } //set the checkbox to false if the value stored is false - - Clicked("#sw1"); - - if(document.querySelector("#sw1").checked){ - SampleWebPage(); - console.log("work") - } -}) //document setup not working for now - -function Clicked(sw_id){ - document.querySelector(sw_id).addEventListener("click",function(){ - localStorage.setItem(sw_id, document.querySelector(sw_id).checked) - }) -} //identify when switch is clicked - - From 7ca95fb35b3425cab10b7ef7c8454176d3709693 Mon Sep 17 00:00:00 2001 From: Jarvis H Yang Date: Wed, 25 May 2022 01:11:50 +0800 Subject: [PATCH 12/15] Added Background Script -Added Background Script -Renamed content.js to Algorithm.js -Added Permission to Storage -Organized Codes --- js/{content.js => Algorithm.js} | 4 ---- js/Background.js | 26 ++++++++++++++++++++++++++ js/Popup.js | 26 -------------------------- manifest.json | 14 ++++++++++---- 4 files changed, 36 insertions(+), 34 deletions(-) rename js/{content.js => Algorithm.js} (94%) create mode 100644 js/Background.js diff --git a/js/content.js b/js/Algorithm.js similarity index 94% rename from js/content.js rename to js/Algorithm.js index 3d3a208..910b35f 100644 --- a/js/content.js +++ b/js/Algorithm.js @@ -25,10 +25,6 @@ function ModifyTextUpgrade(textNodeContent) }); } -document.addEventListener("DOMContentLoaded", function(){ - console.log(ModifyTextUpgrade("abandon")) -}) - function ModifyWebPage() { const domParser = new DOMParser(); diff --git a/js/Background.js b/js/Background.js new file mode 100644 index 0000000..63094b1 --- /dev/null +++ b/js/Background.js @@ -0,0 +1,26 @@ +document.addEventListener("DOMContentLoaded", function(){ //TODO Change this to chrome.storage; Extension cannot run if using "document" + + var sw1 = JSON.parse(localStorage.getItem("#sw1")) + if(!sw1) + { + document.querySelector("#sw1").click(); + } //set the checkbox to false if the value stored is false + + Clicked("#sw1"); + + if(document.querySelector("#sw1").checked) + chrome.tabs.query({ active: true, currentWindow: true } , function(activeTab){ + chrome.scripting.executeScript({ + target: {tabId: activeTab[0].id, allFrames: true}, + files: ['js/Algorithm.js'], + }); + }); + +}) + +function Clicked(sw_id){ + document.querySelector(sw_id).addEventListener("click",function(){ + localStorage.setItem(sw_id, document.querySelector(sw_id).checked) + }) +} //identify when switch is clicked + diff --git a/js/Popup.js b/js/Popup.js index aa164f0..e69de29 100644 --- a/js/Popup.js +++ b/js/Popup.js @@ -1,26 +0,0 @@ -document.addEventListener("DOMContentLoaded", function(){ - - var sw1 = JSON.parse(localStorage.getItem("#sw1")) - if(!sw1) - { - document.querySelector("#sw1").click(); - } //set the checkbox to false if the value stored is false - - Clicked("#sw1"); - - if(document.querySelector("#sw1").checked) - chrome.tabs.query({ active: true, currentWindow: true } , function(activeTab){ - chrome.scripting.executeScript({ - target: {tabId: activeTab[0].id, allFrames: true}, - files: ['js/content.js'], - }); - }); - -}) //FIXME document setup not working for now - -function Clicked(sw_id){ - document.querySelector(sw_id).addEventListener("click",function(){ - localStorage.setItem(sw_id, document.querySelector(sw_id).checked) - }) -} //identify when switch is clicked - diff --git a/manifest.json b/manifest.json index 2dbc633..2f90bdb 100644 --- a/manifest.json +++ b/manifest.json @@ -3,14 +3,20 @@ "name": "Bionic Enhance Reader", "version": "0.0.2", "description": "Speed Up Your Reading By 10 Folds", - "icons": { + "icons": + { "16": "img/icon16.png", "48": "img/icon48.png", "128":"img/icon128.png" }, - "permissions": ["activeTab","scripting"], - "action": { + "background": + { + "service_worker": "js/background.js" + }, + "permissions": ["activeTab","scripting","storage"], + "action": + { "default_popup": "html/Popup.html", - "default_title": "Click to Access Advanced Features" + "default_title": "Click to Basic Settings" } } \ No newline at end of file From 94aa317041faa0dc438efe5581274828ce91ba13 Mon Sep 17 00:00:00 2001 From: Jarvis H Yang Date: Thu, 26 May 2022 21:57:00 +0800 Subject: [PATCH 13/15] Completed Syllable Algorithm -finished bolding by vowels -deleted test.html --- js/Algorithm.js | 17 +++++++++------- js/Background.js | 50 ++++++++++++++++++++++++------------------------ js/Popup.js | 26 +++++++++++++++++++++++++ test.html | 12 ------------ 4 files changed, 61 insertions(+), 44 deletions(-) delete mode 100644 test.html diff --git a/js/Algorithm.js b/js/Algorithm.js index ea07230..d056b0b 100644 --- a/js/Algorithm.js +++ b/js/Algorithm.js @@ -1,6 +1,6 @@ //We probably don't need Unit Test -function ModifyText(textNodeContent) +function ModifyTextBasic(textNodeContent) { return textNodeContent.split(' ').map((word) => { //TODO if the user wants numbers to be bolded @@ -12,15 +12,15 @@ function ModifyText(textNodeContent) }); } -function ModifyTextUpgrade(textNodeContent) +function ModifyTextSyllable(textNodeContent) { - return pronouncing.syllableCount(textNodeContent) return textNodeContent.split(' ').map((word) => { - //TODO if the user wants numbers to be bolded //if(/\d/.test(word)) return word; - - 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.. + var vowel = /[aeiouy]/i; + var match = vowel.exec(word); + if(match != null) + var boldUp2 = match.index; return word.replace(word, `${word.substring(0, boldUp2+1)}${word.substring(boldUp2+1)}`); //TODO Add customizable fonts & underline the words that are originally bolded }); } @@ -33,12 +33,15 @@ function ModifyWebPage() var text = domParser.parseFromString(element.innerHTML, "text/html"); var textNodeCollection = Array.from(text.body.childNodes).map((node) => { if(node.nodeType === Node.TEXT_NODE) - return ModifyText(node.textContent).join(' '); + return ModifyTextBasic(node.textContent).join(' '); //Change this to ModifyTextSyllable when changing algorithm else return node.outerHTML;}) element.innerHTML = textNodeCollection.join(''); }); } +ModifyWebPage(); + + diff --git a/js/Background.js b/js/Background.js index 63094b1..8ba7413 100644 --- a/js/Background.js +++ b/js/Background.js @@ -1,26 +1,26 @@ -document.addEventListener("DOMContentLoaded", function(){ //TODO Change this to chrome.storage; Extension cannot run if using "document" - - var sw1 = JSON.parse(localStorage.getItem("#sw1")) - if(!sw1) - { - document.querySelector("#sw1").click(); - } //set the checkbox to false if the value stored is false - - Clicked("#sw1"); - - if(document.querySelector("#sw1").checked) - chrome.tabs.query({ active: true, currentWindow: true } , function(activeTab){ - chrome.scripting.executeScript({ - target: {tabId: activeTab[0].id, allFrames: true}, - files: ['js/Algorithm.js'], - }); - }); - -}) - -function Clicked(sw_id){ - document.querySelector(sw_id).addEventListener("click",function(){ - localStorage.setItem(sw_id, document.querySelector(sw_id).checked) - }) -} //identify when switch is clicked +//document.addEventListener("DOMContentLoaded", function(){ //TODO Change this to chrome.storage; Extension cannot run if using "document" +// +// var sw1 = JSON.parse(localStorage.getItem("#sw1")) +// if(!sw1) +// { +// document.querySelector("#sw1").click(); +// } //set the checkbox to false if the value stored is false +// +// Clicked("#sw1"); +// +// if(document.querySelector("#sw1").checked) +// chrome.tabs.query({ active: true, currentWindow: true } , function(activeTab){ +// chrome.scripting.executeScript({ +// target: {tabId: activeTab[0].id, allFrames: true}, +// files: ['js/Algorithm.js'], +// }); +// }); +// +//}) +// +//function Clicked(sw_id){ +// document.querySelector(sw_id).addEventListener("click",function(){ +// localStorage.setItem(sw_id, document.querySelector(sw_id).checked) +// }) +//} //identify when switch is clicked diff --git a/js/Popup.js b/js/Popup.js index e69de29..63094b1 100644 --- a/js/Popup.js +++ b/js/Popup.js @@ -0,0 +1,26 @@ +document.addEventListener("DOMContentLoaded", function(){ //TODO Change this to chrome.storage; Extension cannot run if using "document" + + var sw1 = JSON.parse(localStorage.getItem("#sw1")) + if(!sw1) + { + document.querySelector("#sw1").click(); + } //set the checkbox to false if the value stored is false + + Clicked("#sw1"); + + if(document.querySelector("#sw1").checked) + chrome.tabs.query({ active: true, currentWindow: true } , function(activeTab){ + chrome.scripting.executeScript({ + target: {tabId: activeTab[0].id, allFrames: true}, + files: ['js/Algorithm.js'], + }); + }); + +}) + +function Clicked(sw_id){ + document.querySelector(sw_id).addEventListener("click",function(){ + localStorage.setItem(sw_id, document.querySelector(sw_id).checked) + }) +} //identify when switch is clicked + diff --git a/test.html b/test.html deleted file mode 100644 index 9927592..0000000 --- a/test.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - Document - - - - - \ No newline at end of file From b3b96b949b645f14c99711b6a38212faac070702 Mon Sep 17 00:00:00 2001 From: Jarvis H Yang Date: Sat, 28 May 2022 17:00:49 +0800 Subject: [PATCH 14/15] Started Background and Messaging system --- html/Popup.html | 2 +- js/Background.js | 42 +++++++++++++++++------------------------- js/Popup.js | 29 +++++------------------------ 3 files changed, 23 insertions(+), 50 deletions(-) diff --git a/html/Popup.html b/html/Popup.html index 2957ee4..3903da9 100644 --- a/html/Popup.html +++ b/html/Popup.html @@ -17,7 +17,7 @@

Settings:

diff --git a/js/Background.js b/js/Background.js index 8ba7413..e051a2d 100644 --- a/js/Background.js +++ b/js/Background.js @@ -1,26 +1,18 @@ -//document.addEventListener("DOMContentLoaded", function(){ //TODO Change this to chrome.storage; Extension cannot run if using "document" -// -// var sw1 = JSON.parse(localStorage.getItem("#sw1")) -// if(!sw1) -// { -// document.querySelector("#sw1").click(); -// } //set the checkbox to false if the value stored is false -// -// Clicked("#sw1"); -// -// if(document.querySelector("#sw1").checked) -// chrome.tabs.query({ active: true, currentWindow: true } , function(activeTab){ -// chrome.scripting.executeScript({ -// target: {tabId: activeTab[0].id, allFrames: true}, -// files: ['js/Algorithm.js'], -// }); -// }); -// -//}) -// -//function Clicked(sw_id){ -// document.querySelector(sw_id).addEventListener("click",function(){ -// localStorage.setItem(sw_id, document.querySelector(sw_id).checked) -// }) -//} //identify when switch is clicked +//This is the settins in the User Popup +var userSettings = { + Auto_Bold : true +} +//First Initiallization +chrome.runtime.onInstalled.addListener(() => { + chrome.storage.sync.set({ userSettings }); + console.log('Initialized with ' + userSettings.Auto_Bold); +}); + + + + +//Manage change in Auto_Bold-Switch +//chrome.runtime.onMessage.addListener((request , sender , sendResponse) => { +// +//}); \ No newline at end of file diff --git a/js/Popup.js b/js/Popup.js index 63094b1..2a43d19 100644 --- a/js/Popup.js +++ b/js/Popup.js @@ -1,26 +1,7 @@ -document.addEventListener("DOMContentLoaded", function(){ //TODO Change this to chrome.storage; Extension cannot run if using "document" +const Auto_Bold_Switch = document.getElementById('Auto_Bold'); - var sw1 = JSON.parse(localStorage.getItem("#sw1")) - if(!sw1) - { - document.querySelector("#sw1").click(); - } //set the checkbox to false if the value stored is false - - Clicked("#sw1"); - - if(document.querySelector("#sw1").checked) - chrome.tabs.query({ active: true, currentWindow: true } , function(activeTab){ - chrome.scripting.executeScript({ - target: {tabId: activeTab[0].id, allFrames: true}, - files: ['js/Algorithm.js'], - }); - }); - -}) - -function Clicked(sw_id){ - document.querySelector(sw_id).addEventListener("click",function(){ - localStorage.setItem(sw_id, document.querySelector(sw_id).checked) - }) -} //identify when switch is clicked +Auto_Bold_Switch.addEventListener('change' , function(){ + var Bold_Status = Auto_Bold_Switch.checked; + chrome.runtime.sendMessage({Auto_Bold : Bold_Status}); +}); \ No newline at end of file From 786895f46041c7952db63ef9f0676b7567a89022 Mon Sep 17 00:00:00 2001 From: Jarvis H Yang Date: Sun, 29 May 2022 02:58:13 +0800 Subject: [PATCH 15/15] Finished Auto Bold feature -added background.js -added host_permissions and tabs permission -changed to chrome.storage API -minor bug patches --- README.md | 8 +++----- js/Algorithm.js | 2 +- js/Background.js | 30 +++++++++++++++++++++++------- js/Popup.js | 10 ++++++++++ manifest.json | 5 ++++- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c7f9b8d..15128f8 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ This is the feature branch of Bionic Enhance Reader. 1. Customizable Text Style & Color 2. Customizable frequency of bolding 3. Customizable bolding extent -4. A Popup Menu -5. Optional integration with Bionic Read API -6. Cuztomizable URLs to bold (whitelist / blacklist) -7. Text & Background Coloring -8. More features incoming... +6. Optional integration with Bionic Read API +7. Cuztomizable URLs to bold (whitelist / blacklist) +8. Text & Background Coloring diff --git a/js/Algorithm.js b/js/Algorithm.js index d056b0b..82880cd 100644 --- a/js/Algorithm.js +++ b/js/Algorithm.js @@ -21,7 +21,7 @@ function ModifyTextSyllable(textNodeContent) var match = vowel.exec(word); if(match != null) var boldUp2 = match.index; - return word.replace(word, `${word.substring(0, boldUp2+1)}${word.substring(boldUp2+1)}`); //TODO Add customizable fonts & underline the words that are originally bolded + return word.replace(word, `${word.substring(0, boldUp2+1)}${word.substring(boldUp2+1)}`); }); } diff --git a/js/Background.js b/js/Background.js index e051a2d..9fd2475 100644 --- a/js/Background.js +++ b/js/Background.js @@ -1,18 +1,34 @@ -//This is the settins in the User Popup +//User Settings var userSettings = { Auto_Bold : true } -//First Initiallization +//First Initiallization of the Plugin chrome.runtime.onInstalled.addListener(() => { chrome.storage.sync.set({ userSettings }); - console.log('Initialized with ' + userSettings.Auto_Bold); }); +//Bold a webpage once the user has switched to a new page +chrome.tabs.onActivated.addListener((activeInfo) => { + if(userSettings.Auto_Bold) //TODO Once a web is bolded, mark it as "Static" so that it will not be bold again + chrome.scripting.executeScript({ + target: {tabId: activeInfo.tabId, allFrames: true}, + files: ['js/Algorithm.js'], + }); +}); + +chrome.runtime.onMessage.addListener((request , sender , sendResponse) => { + + //Check if request contains info related to Auto_Bold + if('Auto_Bold' in request) + { + userSettings.Auto_Bold = request.Auto_Bold; + chrome.storage.sync.set({ userSettings }); + } + -//Manage change in Auto_Bold-Switch -//chrome.runtime.onMessage.addListener((request , sender , sendResponse) => { -// -//}); \ No newline at end of file + //Since No responce is needed, close the Message Port + return true; +}); \ No newline at end of file diff --git a/js/Popup.js b/js/Popup.js index 2a43d19..f506d11 100644 --- a/js/Popup.js +++ b/js/Popup.js @@ -1,5 +1,15 @@ +//Initializations on Startup const Auto_Bold_Switch = document.getElementById('Auto_Bold'); +var userSettingsCopy; +chrome.storage.sync.get( 'userSettings' , (result) => { + userSettingsCopy = result.userSettings; + + Auto_Bold_Switch.checked = userSettingsCopy.Auto_Bold; +}); + + +//Events Auto_Bold_Switch.addEventListener('change' , function(){ var Bold_Status = Auto_Bold_Switch.checked; diff --git a/manifest.json b/manifest.json index 2f90bdb..fc58b9a 100644 --- a/manifest.json +++ b/manifest.json @@ -13,7 +13,10 @@ { "service_worker": "js/background.js" }, - "permissions": ["activeTab","scripting","storage"], + "permissions": ["activeTab","scripting","storage","tabs"], + "host_permissions": [ + "*://*/" + ], "action": { "default_popup": "html/Popup.html",