This commit is contained in:
alexadam 2016-07-28 13:03:48 +03:00
parent 606ed53f2a
commit 8147350ce8
11 changed files with 605 additions and 64 deletions

87
chapter-editor/menu.js Normal file
View file

@ -0,0 +1,87 @@
var win = null;
document.getElementById("editChapters").onclick = function() {
win = window.open(chrome.extension.getURL('chapter-editor/editor.html'), '_blank');
win.focus();
};
function getEbookPages() { // TODO add as utils
try {
var allPages = localStorage.getItem('ebook');
if (!allPages) {
allPages = [];
} else {
allPages = JSON.parse(allPages);
}
return allPages;
} catch (e) {
console.log(e);
return [];
}
}
function saveEbookPages(pages) {
localStorage.setItem('ebook', JSON.stringify(pages));
}
document.getElementById('savePage').onclick = function() {
chrome.tabs.query({
currentWindow: true,
active: true
}, function(tab) {
console.log('aiai');
chrome.tabs.sendMessage(
tab[0].id,
{
type: 'extract-page'
},
function (response) {
var allPages = getEbookPages();
allPages.push(response);
saveEbookPages(allPages);
buildEbook();
}
);
});
};
document.getElementById('saveSelection').onclick = function() {
chrome.tabs.query({
currentWindow: true,
active: true
}, function(tab) {
chrome.tabs.sendMessage(
tab[0].id,
{
type: 'extract-selection'
},
function (response) {
console.log('Selection EXTRAcTED', response);
}
);
});
};
document.getElementById('title').onclick = function() {
chrome.tabs.query({
currentWindow: true,
active: true
}, function(tab) {
chrome.tabs.sendMessage(
tab[0].id, {
type: 'get-title'
},
function(response) {
var title = localStorage.getItem('title');
if (title === null) {
title = [];
} else {
title = JSON.parse(title);
}
title.push(response);
localStorage.setItem('title', JSON.stringify(title));
}
);
});
};