Skip to content

Commit

Permalink
Added auto-enable feature, close JR bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachSaucier committed Nov 7, 2016
1 parent 8e1b022 commit 94144f0
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 17 deletions.
25 changes: 24 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,27 @@ chrome.extension.onRequest.addListener(function(data, sender) {
}
});

//});
//});


chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'loading') {
// Auto enable on sites specified
chrome.storage.sync.get('auto-enable-site-list', function (siteListObj) {
var siteList = siteListObj['auto-enable-site-list'],
url = tab.url,
matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i),
domain = matches && matches[1]; // Domain will be null if no match is found

for(var i = 0; i < siteList.length; i++) {
if(domain && siteList[i] === domain) {
chrome.tabs.executeScript(null, {
code: 'var runOnLoad = true;' // Ghetto way of signaling to run on load
}, function() { // instead of using Chrome messages
startJustRead();
});
}
}
});
}
});
22 changes: 20 additions & 2 deletions content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ function mutePage() {
// State functions
/////////////////////////////////////

// Run on load functionality
function runOnLoad() {
// When the content has finished loading, enable Just Read to run
window.onload = function(event) {
isPaused = false;
}

// Make the next part wait until the content is loaded
hideLoad = false;
isPaused = true;
}

// User-selected text functionality
var last,
bgc,
Expand Down Expand Up @@ -708,6 +720,7 @@ function addGUI() {
}

datGUI.destroy();
datGUI = undefined;

closeBtn = null;
saved = false;
Expand Down Expand Up @@ -1062,16 +1075,16 @@ function continueLoading() {




/////////////////////////////////////
// Handle the stylesheet syncing
/////////////////////////////////////
var isPaused = false,
stylesheetObj = {},
stylesheetVersion = 1.9; // THIS NUMBER MUST BE CHANGED FOR THE STYLESHEETS TO KNOW TO UPDATE
stylesheetVersion = 1.10; // THIS NUMBER MUST BE CHANGED FOR THE STYLESHEETS TO KNOW TO UPDATE
// Detect past overlay - don't show another
if(document.getElementById("simple-article") == null) {
var interval = setInterval(function() {

// Check to see if the user wants to select the text
if(typeof useText != "undefined" && useText && !isPaused) {
// Start the process of the user selecting text to read
Expand All @@ -1083,6 +1096,11 @@ if(document.getElementById("simple-article") == null) {
if(!document.head.querySelector(".page-styles"))
addStylesheet(document, "page.css", "page-styles");

// Check to see if the user wants to hide the content while loading
if(typeof runOnLoad != "undefined" && runOnLoad) {
runOnLoad(document);
}

// Attempt to mute the elements on the original page
mutePage();

Expand Down
5 changes: 5 additions & 0 deletions default-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ aside,
display: none;
}

/* Very simple 'nocontent' hider */
[class *= "nocontent"] {
display: none;
}

/* Very simple popup hider */
[class *= "popup"],
[id *= "popup"] {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Just Read",
"version": "1.0.7",
"version": "1.0.8",
"manifest_version": 2,
"description": "A customizable read mode extension.",
"homepage_url": "https://github.com/ZachSaucier/Just-Read",
Expand Down
16 changes: 14 additions & 2 deletions options.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ body, .editor-container {
flex-direction: column;
}

.stylesheet-list-container {
.left-column {
display: flex;
flex-direction: column;

max-width: 250px;
margin-right: 50px;
border: 1px solid;
Expand Down Expand Up @@ -60,6 +63,15 @@ body, .editor-container {
color: grey;
}

.left-column h4 {
margin-top: 20px;
margin-bottom: 5px;
}
#domainList {
width: 100%;
flex-grow: 1;
}

.controls-container {
margin-bottom: 10px;
}
Expand Down Expand Up @@ -112,7 +124,7 @@ body, .editor-container {
flex-direction: column;
}

.stylesheet-list-container {
.left-column {
margin-bottom: 10px;
}

Expand Down
17 changes: 11 additions & 6 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
<h1>Edit <i>Just Read</i> styles</h1>

<div class="flex-container">
<div class="stylesheet-list-container">
<input type="text" id="new-file" placeholder="New stylesheet..."/>
<button id="add">+</button>
<ul class="stylesheets">
<!-- This is populated by our JS -->
</ul>
<div class="left-column">
<div class="stylesheet-list-container">
<input type="text" id="new-file" placeholder="New stylesheet..."/>
<button id="add">+</button>
<ul class="stylesheets">
<!-- This is populated by our JS -->
</ul>
</div>

<h4>Auto-run domain list:</h4>
<textarea name="domainList" id="domainList"></textarea>
</div>

<div class="editor-container">
Expand Down
30 changes: 25 additions & 5 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,23 @@ function byteLength(str) {
return s;
}

// Given a chrome storage object add them to our local stylsheet obj
// Given a chrome storage object, add them to our domain list
function setDomains(domains) {
var domainString = "";
for(var i = 0; i < domains.length; i++) {
domainString += domains[i] + "\n";
}

domainList.value = domainString;
}

// Given a chrome storage object, add them to our domain list
function getStylesFromStorage(storage) {
for(var key in storage) {
// Convert the old format into the new format
if(key === "just-read-stylesheets") {
if(key === "auto-enable-site-list") {
setDomains(storage[key]);
} else if(key === "just-read-stylesheets") {
// Save each stylesheet in the new format
for(var stylesheet in storage[key]) {
var obj = {};
Expand Down Expand Up @@ -388,14 +400,22 @@ function useTheme() {
alert(sheet + " is now set as the active theme");
}

getStylesheets();

var newFileInput = document.getElementById("new-file"),
addButton = document.getElementById("add"),
saveButton = document.getElementById("save"),
useButton = document.getElementById("use"),
removeButton = document.getElementById("remove"),
stylesheetListItems;
stylesheetListItems,
domainList = document.getElementById("domainList");

getStylesheets();


// Update the domain list with any new values
domainList.onkeyup = function(e) {
var domainLine = domainList.value.split("\n").filter(String);
chrome.storage.sync.set({"auto-enable-site-list": domainLine});
}

// Allow the "Enter" key to be used to add new stylesheets
newFileInput.onkeyup = function(e) {
Expand Down

0 comments on commit 94144f0

Please sign in to comment.