Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 55 #58

Open
wants to merge 4 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@ in Chrome:
- http://johnny.github.io/jquery-sortable/
- https://github.com/eligrey/FileSaver.js/
- https://www.iconfinder.com/icons/753890/book_books_education_library_study_icon#size=128
- http://www2.infocity.co.jp/epubjp/EPUB3_Japanese_Basic_Standard_E_1020.pdf
- Thanks to [pumpk0n](https://github.com/pumpk0n) and [Francois Bocquet](https://github.com/fbocquet) for helping me with the French translation
3 changes: 3 additions & 0 deletions web-extension/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"includeStyle": {
"message": "Include (Custom) Style"
},
"japaneseStyle": {
"message": "Make it Japanese"
},
"editStyles": {
"message": "Edit Custom Styles ..."
},
Expand Down
3 changes: 3 additions & 0 deletions web-extension/_locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"includeStyle": {
"message": "Inclure le style"
},
"japaneseStyle": {
"message": "A la Japonaise"
},
"styleLabel": {
"message": "Style personnalisé :"
},
Expand Down
22 changes: 22 additions & 0 deletions web-extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ function dispatch(action, justAddToBuffer, appliedStyles) {
});
}

function isJapaneseStyles(callback) {
chrome.storage.local.get('japaneseStyle', (data) => {
if (!data) {
callback({japaneseStyle: false});
} else {
callback({japaneseStyle: data.japaneseStyle});
}
});
}

function isIncludeStyles(callback) {
chrome.storage.local.get('includeStyle', (data) => {
if (!data) {
Expand Down Expand Up @@ -400,6 +410,18 @@ function _execRequest(request, sender, sendResponse) {
if (request.type === 'set current style') {
chrome.storage.local.set({'currentStyle': request.currentStyle});
}
if (request.type === 'get japanese style') {
chrome.storage.local.get('japaneseStyle', function (data) {
if (!data) {
sendResponse({japaneseStyle: false});
} else {
sendResponse({japaneseStyle: data.japaneseStyle});
}
});
}
if (request.type === 'set japanese style') {
chrome.storage.local.set({'japaneseStyle': request.japaneseStyle});
}
if (request.type === 'get include style') {
chrome.storage.local.get('includeStyle', function (data) {
if (!data) {
Expand Down
6 changes: 5 additions & 1 deletion web-extension/extractHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ var supportedCss = [
'line-height',
'list-style',
'padding',
'text-align',
'text-align',
"-epub-writing-mode",
"-webkit-writing-mode",
"writing-mode",
];
//////

Expand Down Expand Up @@ -366,6 +369,7 @@ function extractCss(includeStyle, appliedStyles) {
$pre.replaceWith('')
}
})

let mergedCss = '';
if (appliedStyles && appliedStyles.length > 0) {
for (let i = 0; i < appliedStyles.length; i++) {
Expand Down
3 changes: 3 additions & 0 deletions web-extension/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<div class="menu-holder">
<div id="menuTitle"></div>
<hr/>
<div class="optionContainer">
<input type="checkbox" name="button" id="japaneseStyleCheck"></input><span id="japaneseStyle"></span>
</div>
<div class="optionContainer">
<input type="checkbox" name="button" id="includeStyleCheck"></input><span id="includeStyle"></span>
</div>
Expand Down
21 changes: 21 additions & 0 deletions web-extension/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var appliedStyles = [];

// create menu labels
document.getElementById('menuTitle').innerHTML = chrome.i18n.getMessage('extName');
document.getElementById('japaneseStyle').innerHTML = chrome.i18n.getMessage('japaneseStyle');
document.getElementById('includeStyle').innerHTML = chrome.i18n.getMessage('includeStyle');
document.getElementById('editStyles').innerHTML = chrome.i18n.getMessage('editStyles');
document.getElementById('savePageLabel').innerHTML = chrome.i18n.getMessage('savePage');
Expand Down Expand Up @@ -89,6 +90,26 @@ function createStyleList(styles) {
});
}

function createJapaneseStyle(data) {
let japaneseStyleCheck = document.getElementById('japaneseStyleCheck');
japaneseStyleCheck.checked = data;
}

chrome.runtime.sendMessage({
type: "get japanese style"
}, function(response) {
createJapaneseStyle(response.japaneseStyle);
});

document.getElementById('japaneseStyleCheck').onclick = function () {
let japaneseStyleCheck = document.getElementById('japaneseStyleCheck');
chrome.runtime.sendMessage({
type: "set japanese style",
japaneseStyle: japaneseStyleCheck.checked
}, function(response) {
});
}

function createIncludeStyle(data) {
let includeStyleCheck = document.getElementById('includeStyleCheck');
includeStyleCheck.checked = data;
Expand Down
96 changes: 92 additions & 4 deletions web-extension/saveEbook.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var cssFileName = 'ebook.css';
var ebookTitle = null;
let japaneseStyle = false;

chrome.runtime.onMessage.addListener((obj, sender, sendResponse) => {
if (obj.shortcut && obj.shortcut === 'build-ebook') {
Expand All @@ -11,6 +12,15 @@ chrome.runtime.onMessage.addListener((obj, sender, sendResponse) => {
return true;
})

chrome.storage.local.get("japaneseStyle", function(data) {
if(typeof data.japaneseStyle == "undefined") {
japaneseStyle = false;
} else {
japaneseStyle = data.japaneseStyle;
}
});


function getImagesIndex(allImages) {
return allImages.reduce(function(prev, elem, index) {
return prev + '\n' + '<item href="images/' + elem.filename + '" id="img' + elem.filename + '" media-type="image/' + getImageType(elem.filename) + '"/>';
Expand Down Expand Up @@ -115,13 +125,56 @@ function _buildEbook(allPages, fromMenu=false) {
'</navMap>' +
'</ncx>'
);

if (japaneseStyle === true) {
var styleFolder = oebps.folder('style');
styleFolder.file('japanese.css',
'.left { text-align:left; }' +
'.center { text-align:center; }' +
'.right {text-align:right; }' +
'img.left {float:left; }' +
'img.left { float:right; }' +
'.blue { color:#0000ff; }' +
'.green {color:#008000; }' +
'.red { color:#ff0000; }' +
'.tcy { -epub-text-combine:horizontal; -webkit-text-combine:horizontal; }' +
'.em_accent { -epub-text-emphasis-style: filled sesame; }' +
'.em_dot { -epub-text-emphasis-style: filled double-circle; }' +
'.em_circle { -epub-text-emphasis-style: open dot; }' +
'.em_disc { -epub-text-emphasis-style: filled dot; }' +
'@page { margin:8%; }' +
'@media all and (orientation:portrait){ img.pagefit { width:100%; } } ' +
'@media all and (orientation:landscape){ img.pagefit { height:100%; } }' +
'body { font-size: 20px; line-height: 175%; letter-spacing: 0px; text-align: justify; -epub-writing-mode: vertical-rl; writing-mode: vertical-rl; }' +
'h1,h2,h3,h4,h5,h6 { font-size: 110%; font-weight: bold; }' +
'a { text-decoration: none; }' +
'a:link { color:#00008b; }' +
'a:visited { color:#00008b; }' +
'.indent { margin-right:1em; margin-left:1em; padding-top:1em; text-indent:-1em;}'); // Ugly but it works
}
oebps.file(cssFileName, ''); //TODO
var styleFolder = oebps.folder('style');
allPages.forEach(function(page) {
styleFolder.file(page.styleFileName, page.styleFileContent);
});


if (japaneseStyle === true) {
var pagesFolder = oebps.folder('pages');
allPages.forEach(function(page) {
var tmpPageTitle = escapeXMLChars(page.title);
pagesFolder.file(page.url,
'<?xml version="1.0" encoding="utf-8"?>' +
'<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">' +
'<head>' +
'<title>' + tmpPageTitle+ '</title>' +
'<link href="../style/japanese.css" rel="stylesheet" type="text/css" />' +
'<link href="../style/' + page.styleFileName + '" rel="stylesheet" type="text/css" />' +
'</head><body>' +
page.content +
'</body></html>'
);
});
} else {
var pagesFolder = oebps.folder('pages');
allPages.forEach(function(page) {
var tmpPageTitle = escapeXMLChars(page.title);
Expand All @@ -136,8 +189,42 @@ function _buildEbook(allPages, fromMenu=false) {
'</body></html>'
);
});

oebps.file('content.opf',
}

if (japaneseStyle === true) {
oebps.file('content.opf',
'<?xml version="1.0" encoding="UTF-8" ?>' +
'<package xmlns="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/" unique-identifier="db-id" version="3.0" xml:lang="ja">' +
'<metadata>' +
'<dc:title id="t1">'+ ebookName + '</dc:title>' +
'<dc:identifier id="db-id">isbn</dc:identifier>' +
'<meta property="dcterms:modified">' + new Date().toISOString().replace(/\.[0-9]+Z/i, 'Z') + '</meta>' +
'<dc:language>ja</dc:language>' +
'</metadata>' +
'<manifest>' +
'<item id="toc" properties="nav" href="toc.xhtml" media-type="application/xhtml+xml" />' +
'<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" />' +
'<item id="template_css" href="' + cssFileName + '" media-type="text/css" />' +
allPages.reduce(function(prev, page, index) {
return prev + '\n' + '<item id="ebook' + index + '" href="pages/' + page.url + '" media-type="application/xhtml+xml" />';
}, '') +
'<item id="style0" href="style/japanese.css" media-type="text/css" />' +
allPages.reduce(function(prev, page, index) {
return prev + '\n' + '<item id="style' + index+1 + '" href="style/' + page.styleFileName + '" media-type="text/css" />';
}, '') +
allPages.reduce(function(prev, page, index) {
return prev + '\n' + getImagesIndex(page.images);
}, '') +
'</manifest>' +
'<spine toc="ncx" page-progression-direction="rtl">' +
allPages.reduce(function(prev, page, index) {
return prev + '\n' + '<itemref idref="ebook' + index + '" />';
}, '') +
'</spine>' +
'</package>'
);
} else {
oebps.file('content.opf',
'<?xml version="1.0" encoding="UTF-8" ?>' +
'<package xmlns="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/" unique-identifier="db-id" version="3.0">' +
'<metadata>' +
Expand Down Expand Up @@ -166,7 +253,8 @@ function _buildEbook(allPages, fromMenu=false) {
}, '') +
'</spine>' +
'</package>'
);
);
}

///////////////
try {
Expand Down
16 changes: 16 additions & 0 deletions web-extension/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
function setJapaneseStyle(japaneseStyle) {
chrome.runtime.sendMessage({
type: "set japanese style",
japaneseStyle: japaneseStyle
}, function(response) {
});
}

function getJapaneseStyle(callback) {
chrome.runtime.sendMessage({
type: "get japanese style"
}, function(response) {
callback(response.japaneseStyle);
});
}

function setIncludeStyle(includeStyle) {
chrome.runtime.sendMessage({
type: "set include style",
Expand Down