mirror of
https://github.com/alexadam/save-as-ebook.git
synced 2025-09-13 02:39:45 +00:00
modul1
This commit is contained in:
parent
606ed53f2a
commit
8147350ce8
11 changed files with 605 additions and 64 deletions
87
chapter-editor/menu.js
Normal file
87
chapter-editor/menu.js
Normal 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));
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue