Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Add an option to show/hide article tools #25

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
{
"name": "Readability Redux",
"version": "1.3.4",
"background": {
"page": "redux/background.html"
},
"browser_action": {
"default_icon": "icons/readability-toolbar.png"
},
"content_scripts": [
{
"js": [
"redux/contentscript.js"
],
"matches": [
"http://*/*",
"https://*/*",
"ftp://*/*",
"file://*/*"
]
}
],
"description": "Readability for Chrome. Now fully customizable!",
"background_page": "redux/background.html",
"browser_action": { "default_icon": "icons/readability-toolbar.png" },
"icons": {
"16": "icons/readability-16.png",
"48": "icons/readability-48.png",
"128": "icons/readability-128.png"
"128": "icons/readability-128.png",
"16": "icons/readability-16.png",
"48": "icons/readability-48.png"
},
"permissions": [ "tabs", "http://*/*", "https://*/*"],
"manifest_version": 2,
"name": "Readability Redux",
"options_page": "redux/options.html",
"content_scripts": [ { "matches": ["http://*/*", "https://*/*", "ftp://*/*", "file://*/*"], "js": ["redux/contentscript.js"] } ]
"permissions": [
"tabs",
"http://*/*",
"https://*/*"
],
"version": "1.3.4",
"web_accessible_resources": [
"/readability/readability.js",
"/readability/readability.css",
"/readability/readability-print.css"
]
}
Empty file modified readability/arc90-logo-large.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified readability/arc90-logo-small.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified readability/arc90lab-logo-small.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified readability/footer.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified readability/kindling-logo-small.gif
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified readability/readability-drag.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified readability/readability-logo-small.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified readability/readability-orig.js
100755 → 100644
Empty file.
Empty file modified readability/readability-print.css
100755 → 100644
Empty file.
8 changes: 5 additions & 3 deletions readability/readability-x.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*jslint undef: true, nomen: true, eqeqeq: true, plusplus: true, newcap: true, immed: true, browser: true, devel: true, passfail: false */
/*global window: false, readConvertLinksToFootnotes: false, readStyle: false, readSize: false, readMargin: false, Typekit: false, ActiveXObject: false */
/*global window: false, showArticleTools: true, readConvertLinksToFootnotes: false, readStyle: false, readSize: false, readMargin: false, Typekit: false, ActiveXObject: false */

var dbg = /*(typeof console !== 'undefined') ? function(s) {
console.log("Readability: " + s);
Expand Down Expand Up @@ -148,8 +148,10 @@ var readability = {
innerDiv.appendChild( articleTitle );
innerDiv.appendChild( articleContent );
innerDiv.appendChild( articleFooter );
overlay.appendChild( articleTools );
overlay.appendChild( innerDiv );
if (showArticleTools === true) {
overlay.appendChild( articleTools );
}
overlay.appendChild( innerDiv );

/* Clear the old HTML, insert the new content. */
document.body.innerHTML = "";
Expand Down
9 changes: 2 additions & 7 deletions readability/readability.css
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@charset "utf-8";
/* Document */
body{font-size:10px;line-height:1;}
#readability-logo,#arc90-logo,.footer-twitterLink,#readTools a,a.rdbTK-powered span{background-color:transparent!important;background-image:url(http://lab.arc90.com/experiments/readability/images/sprite-readability.png)!important;background-repeat:no-repeat!important;}
#readOverlay{text-rendering:optimizeLegibility;display:block;position:absolute;top:0;left:0;width:100%;}
#readInner{max-width:800px;margin:1em auto;}
#readInner a{color:#039;text-decoration:none;}
Expand All @@ -23,10 +22,6 @@ body{font-size:10px;line-height:1;}
#rdb-footer-left{display:inline;float:left;margin-top:15px;width:285px;background-position:0 -36px;}
.rdbTypekit #rdb-footer-left{width:475px;}
#rdb-footer-left a,#rdb-footer-left a:link{float:left;}
#readability-logo{display:inline;background-position:0 -36px;height:29px;width:189px;text-indent:-9000px;}
#arc90-logo{display:inline;background-position:right -36px;height:29px;width:96px;text-indent:-9000px;}
.style-apertura #readability-logo,.style-terminal #readability-logo{background-position:0 -67px;}
.style-apertura #arc90-logo,.style-terminal #arc90-logo{background-position:right -67px;}
#rdb-footer-right{display:inline;float:right;text-align:right;font-size:.75em;margin-top:18px;}
#rdb-footer-right a{display:inline-block;float:left;overflow:visible;line-height:16px;vertical-align:baseline;}
.footer-twitterLink{height:20px;margin-left:20px;background-position:0 -123px;font-size:12px;padding:4px 0 0 28px;}
Expand Down Expand Up @@ -54,8 +49,8 @@ a.rdbTK-powered span{display:inline-block;height:22px;margin-left:2px;background
.size-x-small h1,.size-small h1,.size-medium h1,.size-large h1{font-size:1.6em;line-height:1.5em;}
.size-x-large h1{font-size:1.6em;line-height:1.3em;}
/* Style */
.style-newspaper {font-family:Georgia,"Times New Roman", Times, serif;background:#fbfbfb;color:#080000;}
.style-newspaper h1 {text-transform:capitalize;font-family:Georgia, "Times New Roman", Times, serif;}
.style-newspaper {font-family:Baskerville, "Baskerville Old Face", "Hoefler Text", georgia, Garamond, times, serif;background:#fff;color:#000;}
.style-newspaper h1 {text-transform:capitalize;font-family:Baskerville, "Baskerville Old Face", "Hoefler Text", georgia, Garamond, times, serif;}
.style-newspaper #readInner a {color:#0924e1;}
.style-novel {font-family:"Palatino Linotype", "Book Antiqua", Palatino, serif;background:#f4eed9;color:#1d1916;}
.style-novel #readInner a {color:#1856ba;}
Expand Down
8 changes: 5 additions & 3 deletions readability/readability.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*jslint undef: true, nomen: true, eqeqeq: true, plusplus: true, newcap: true, immed: true, browser: true, devel: true, passfail: false */
/*global window: false, readConvertLinksToFootnotes: false, readStyle: false, readSize: false, readMargin: false, Typekit: false, ActiveXObject: false */
/*global window: false, showArticleTools: true, readConvertLinksToFootnotes: false, readStyle: false, readSize: false, readMargin: false, Typekit: false, ActiveXObject: false */

var dbg = /*(typeof console !== 'undefined') ? function(s) {
console.log("Readability: " + s);
Expand Down Expand Up @@ -134,8 +134,10 @@ var readability = {
innerDiv.appendChild( articleTitle );
innerDiv.appendChild( articleContent );
innerDiv.appendChild( articleFooter );
overlay.appendChild( articleTools );
overlay.appendChild( innerDiv );
if (showArticleTools === true) {
overlay.appendChild( articleTools );
}
overlay.appendChild( innerDiv );

/* Clear the old HTML, insert the new content. */
document.body.innerHTML = "";
Expand Down
Empty file modified readability/readability.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified readability/title-small.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified readability/title.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions redux/background.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<html>
<head>
<script type="text/javascript" src="underscore-0.6.js"></script>
<script type="text/javascript" src="background.js"></script>
<script type="text/javascript">
</script>
<script type="text/javascript" src="underscore-0.6.js"></script>
<script type="text/javascript" src="background.js"></script>
</head>
<body>
</body>
</html>
172 changes: 76 additions & 96 deletions redux/background.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,51 @@

function createJavascript(settings)
{
if(settings['remote'])
{
//console.log('Using remote Readability.');

js_url = "http://lab.arc90.com/experiments/readability/js/readability.js?x="+(Math.random());
css_url = "http://lab.arc90.com/experiments/readability/css/readability.css";
print_url = "http://lab.arc90.com/experiments/readability/css/readability-print.css";
} else
{
if(settings.enable_experimental)
{
// console.log('Using local, experimental Readability.');
var js_url = chrome.extension.getURL('readability/readability-x.js');
} else
{
//console.log('Using local Readability.');
var js_url = chrome.extension.getURL('readability/readability.js');
}

var css_url = chrome.extension.getURL('readability/readability.css');
var print_url = chrome.extension.getURL('readability/readability-print.css');
function createJavascript (settings) {
if (settings.enable_experimental) {
// console.log('Using local, experimental Readability.');
var js_url = chrome.extension.getURL('readability/readability-x.js');
} else {
//console.log('Using local Readability.');
var js_url = chrome.extension.getURL('readability/readability.js');
}

var code = "(function(){readConvertLinksToFootnotes=" + settings['enable_links'] + ";readStyle='" + settings['style'] + "';readSize='" + settings['size'] + "';readMargin='" + settings['margin'] + "';_readability_script=document.createElement('SCRIPT');_readability_script.type='text/javascript';_readability_script.src='" + js_url + "';document.getElementsByTagName('head')[0].appendChild(_readability_script);_readability_css=document.createElement('LINK');_readability_css.rel='stylesheet';_readability_css.href='" + css_url + "';_readability_css.type='text/css';_readability_css.media='screen';document.getElementsByTagName('head')[0].appendChild(_readability_css);_readability_print_css=document.createElement('LINK');_readability_print_css.rel='stylesheet';_readability_print_css.href='" + print_url + "';_readability_print_css.media='print';_readability_print_css.type='text/css';document.getElementsByTagName('head')[0].appendChild(_readability_print_css);})();";
var css_url = chrome.extension.getURL('readability/readability.css');
var print_url = chrome.extension.getURL('readability/readability-print.css');

var code = "(function(){showArticleTools=" + settings['show_article_tools'] + ";readConvertLinksToFootnotes=" + settings['enable_links'] + ";readStyle='" + settings['style'] + "';readSize='" + settings['size'] + "';readMargin='" + settings['margin'] + "';_readability_script=document.createElement('SCRIPT');_readability_script.type='text/javascript';_readability_script.src='" + js_url + "';document.getElementsByTagName('head')[0].appendChild(_readability_script);_readability_css=document.createElement('LINK');_readability_css.rel='stylesheet';_readability_css.href='" + css_url + "';_readability_css.type='text/css';_readability_css.media='screen';document.getElementsByTagName('head')[0].appendChild(_readability_css);_readability_print_css=document.createElement('LINK');_readability_print_css.rel='stylesheet';_readability_print_css.href='" + print_url + "';_readability_print_css.media='print';_readability_print_css.type='text/css';document.getElementsByTagName('head')[0].appendChild(_readability_print_css);})();";

return code;
}

function render(tab_id)
{
function render (tab_id) {
var settings = getSettings();
//console.log(settings);

chrome.tabs.sendRequest(tab_id, {'type': 'render'});
}

function getSettings()
{
function parse(x)
{
try
{
return JSON.parse(x);
} catch(e)
{
return undefined;
}
function getSettings () {
function parse (x) {
try {
return JSON.parse(x);
} catch (e) {
return undefined;
}
}

var settings = {
style: localStorage['style'],
size: localStorage['size'],
margin: localStorage['margin'],
enable_links: !!parse(localStorage['enable_links']),
enable_experimental: !!parse(localStorage['enable_experimental']),
enable_keys: !!parse(localStorage['enable_keys']),
enable_links: parse(localStorage['enable_links']),
enable_experimental: parse(localStorage['enable_experimental']),
show_article_tools: parse(localStorage['show_article_tools']),
enable_keys: parse(localStorage['enable_keys']),
keys: parse(localStorage['keys'])
};

if(!_.isArray(settings['keys']))
if (!Array.isArray(settings['keys'])) {
settings['keys'] = [];
}

var defaults = {
style: 'style-newspaper',
Expand All @@ -70,96 +54,92 @@ function getSettings()
enable_links: false,
enable_keys: false,
enable_experimental: false,
show_article_tools: true,
keys: []
};

return _.extend(defaults, settings);
// Kill all keys with undefined values, so defaults can take over
Object.keys(settings).forEach(setting => {
const value = settings[setting];
if (typeof value === 'undefined') {
delete settings[setting];
}
});

return Object.assign(defaults, settings);
}

function setSettings(settings)
{
var keys = _.keys(settings);
function setSettings (settings) {
const keys = Object.keys(settings);

if(_.include(keys, 'style'))
if (keys.indexOf('style') >= 0) {
settings['style'] = settings['style']

if(_.include(keys, 'size'))
}
if (keys.indexOf('size') >= 0) {
settings['size'] = settings['size']

if(_.include(keys, 'margin'))
}
if (keys.indexOf('margin') >= 0) {
settings['margin'] = settings['margin']

if(_.include(_.keys(settings), 'enable_links'))
}
if (keys.indexOf('enable_links') >= 0) {
settings['enable_links'] = JSON.stringify(!!settings['enable_links']);

if(_.include(_.keys(settings), 'enable_experimental'))
}
if (keys.indexOf('enable_experimental') >= 0) {
settings['enable_experimental'] = JSON.stringify(!!settings['enable_experimental']);

if(_.include(_.keys(settings), 'enable_keys'))
}
if (keys.indexOf('show_article_tools') >= 0) {
settings['show_article_tools'] = JSON.stringify(!!settings['show_article_tools']);
}
if (keys.indexOf('enable_keys') >= 0) {
settings['enable_keys'] = JSON.stringify(!!settings['enable_keys']);

if(_.include(_.keys(settings), 'keys'))
}
if (keys.indexOf('keys') >= 0) {
settings['keys'] = JSON.stringify(settings['keys']);
}

//console.log('setSettings', settings);

_.extend(localStorage, settings);
Object.assign(localStorage, settings);

chrome.windows.getAll({'populate': true}, function(windows)
{
_.each(windows, function(window)
{
_.each(window.tabs, function(tab)
{
chrome.tabs.sendRequest(tab.id, {'type': 'newSettings', 'settings': getSettings()});
});
chrome.windows.getAll({'populate': true}, function (windows) {
windows.forEach(w => {
w.tabs.forEach(tab => chrome.tabs.sendRequest(
tab.id, {
'type': 'newSettings',
'settings': getSettings(),
}
));
});
});
}

function requestHandler(data, sender, callback)
{
if(data['type'] == 'javascript')
{
if(_.include(_.keys(data), 'settings'))
callback(createJavascript(data['settings']));
else
callback(createJavascript(getSettings()));
function requestHandler(data, sender, callback) {
if (data['type'] == 'javascript') {
if (Object.keys(data).indexOf('settings') >= 0) {
return callback(createJavascript(data['settings']));
}
return callback(createJavascript(getSettings()));
}
if(data['type'] == 'setSettings')
{
if (data['type'] == 'setSettings') {
setSettings(data['settings']);
callback();
return callback();
}
if(data['type'] == 'getSettings')
{
callback(getSettings());
if (data['type'] == 'getSettings') {
return callback(getSettings());
}
if(data['type'] == 'render')
{
if (data['type'] == 'render') {
render(data['tab_id']);
callback();
return callback();
}
}

chrome.extension.onRequest.addListener(requestHandler);
chrome.extension.onRequestExternal.addListener(requestHandler);

chrome.browserAction.onClicked.addListener(function(tab)
{
chrome.browserAction.onClicked.addListener(function (tab) {
render(tab.id);
});

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-27938065-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

/*chrome.contextMenus.create({
'title': 'Readability',
'contexts': ['page', 'selection'],
Expand Down
Loading