misc bug fixes

This commit is contained in:
Alex Adam 2018-03-24 20:45:41 +02:00
parent 4d14fd5baf
commit d3ea23f3bf
7 changed files with 126 additions and 321 deletions

View file

@ -120,6 +120,10 @@ display: none;
];
chrome.commands.onCommand.addListener((command) => {
executeCommand({type: command})
});
function executeCommand(command) {
if (isBusy) {
chrome.tabs.query({
currentWindow: true,
@ -131,24 +135,24 @@ chrome.commands.onCommand.addListener((command) => {
})
return;
}
if (command === 'save-page') {
if (command.type === 'save-page') {
dispatch('extract-page', false, []);
isBusy = true;
} else if (command === 'save-selection') {
} else if (command.type === 'save-selection') {
dispatch('extract-selection', false, []);
isBusy = true;
} else if (command === 'add-page') {
} else if (command.type === 'add-page') {
dispatch('extract-page', true, []);
isBusy = true;
} else if (command === 'add-selection') {
} else if (command.type === 'add-selection') {
dispatch('extract-selection', true, []);
isBusy = true;
}
});
}
function dispatch(action, justAddToBuffer, appliedStyles) {
if (!justAddToBuffer) {
removeEbook();
_execRequest({type: 'remove'});
}
chrome.browserAction.setBadgeBackgroundColor({color:"red"});
chrome.browserAction.setBadgeText({text: "Busy"});
@ -200,13 +204,6 @@ function dispatch(action, justAddToBuffer, appliedStyles) {
}
}
chrome.tabs.executeScript(tab[0].id, {file: '/jquery.js'});
chrome.tabs.executeScript(tab[0].id, {file: '/utils.js'});
chrome.tabs.executeScript(tab[0].id, {file: '/filesaver.js'});
chrome.tabs.executeScript(tab[0].id, {file: '/jszip.js'});
chrome.tabs.executeScript(tab[0].id, {file: '/jszip-utils.js'});
chrome.tabs.executeScript(tab[0].id, {file: '/saveEbook.js'});
chrome.tabs.sendMessage(tab[0].id, {
type: action,
appliedStyles: appliedStyles
@ -265,7 +262,9 @@ function dispatch(action, justAddToBuffer, appliedStyles) {
});
}
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
chrome.runtime.onMessage.addListener(_execRequest);
function _execRequest(request, sender, sendResponse) {
if (request.type === 'get') {
chrome.storage.local.get('allPages', function (data) {
if (!data || !data.allPages) {
@ -296,130 +295,6 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.type === 'get styles') {
chrome.storage.local.get('styles', function (data) {
if (!data || !data.styles) {
// TODO move defaultStyles in a different file/location ?
var defaultStyles = [
{
title: 'Reddit Comments',
url: 'reddit\\.com\\/r\\/[^\\/]+\\/comments',
style: `.side {
display: none;
}
#header {
display: none;
}
.arrow, .expand, .score, .live-timestamp, .flat-list, .buttons, .morecomments, .footer-parent, .icon {
display: none !important;
}
`
},{
title: 'Wikipedia Article',
url: 'wikipedia\\.org\\/wiki\\/',
style: `#mw-navigation {
display: none;
}
#footer {
display: none;
}
#mw-panel {
display: none;
}
#mw-head {
display: none;
}
`
},{
title: 'YCombinator News Comments',
url: 'news\\.ycombinator\\.com\\/item\\?id=[0-9]+',
style: `#hnmain > tbody > tr:nth-child(1) > td > table {
display: none;
}
* {
background-color: white;
}
.title, .storylink {
text-align: left;
font-weight: bold;
font-size: 20px;
}
.score {
display: none;
}
.age {
display: none;
}
.hnpast {
display: none;
}
.togg {
display: none;
}
.votelinks, .rank {
display: none;
}
.votearrow {
display: none;
}
.yclinks {
display: none;
}
form {
display: none;
}
a.hnuser {
font-weight: bold;
color: black !important;
padding: 3px;
}
.subtext > span, .subtext > a:not(:nth-child(2)) {
display: none;
}
`
},{
title: 'Medium Article',
url: 'medium\\.com',
style: `.metabar {
display: none !important;
}
header.container {
display: none;
}
.js-postShareWidget {
display: none;
}
footer, canvas {
display: none !important;
}
.u-fixed, .u-bottom0 {
display: none;
}
`
},{
title: 'Twitter',
url: 'twitter\\.com\\/.+',
style: `.topbar {
display: none !important;
}
.ProfileCanopy, .ProfileCanopy-inner {
display: none;
}
.ProfileSidebar {
display: none;
}
.ProfileHeading {
display: none !important;
}
.ProfileTweet-actionList {
display: none;
}
`
}
/*
*/
];
sendResponse({styles: defaultStyles});
} else {
sendResponse({styles: data.styles});
@ -459,5 +334,9 @@ footer, canvas {
if (request.type === 'set is busy') {
isBusy = request.isBusy
}
if (request.type === 'save-page' || request.type === 'save-selection' ||
request.type === 'add-page' || request.type === 'add-selection') {
executeCommand({type: request.type})
}
return true;
});
}