mirror of
https://github.com/alexadam/save-as-ebook.git
synced 2025-09-14 03:09:46 +00:00
misc style fixes - WIP
This commit is contained in:
parent
1d6905332b
commit
475ea4c158
2 changed files with 53 additions and 9 deletions
|
@ -26,16 +26,27 @@ var tmpIdsToNewCss = {};
|
||||||
// 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'page-break-after', 'page-break-before', 'page-break-inside', 'position', 'quotes', 'table-layout',
|
// 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'page-break-after', 'page-break-before', 'page-break-inside', 'position', 'quotes', 'table-layout',
|
||||||
// 'text-align', 'text-decoration', 'text-indent', 'text-transform', 'vertical-align', 'visibility', 'white-space', 'width', 'word-spacing', 'z-index'
|
// 'text-align', 'text-decoration', 'text-indent', 'text-transform', 'vertical-align', 'visibility', 'white-space', 'width', 'word-spacing', 'z-index'
|
||||||
// ];
|
// ];
|
||||||
|
// var supportedCss = [
|
||||||
|
// 'background-color', 'border', 'border-top', 'border-right',
|
||||||
|
// 'border-bottom', 'border-left', 'border-collapse', 'border-color', 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', 'border-spacing',
|
||||||
|
// 'border-style', 'border-top-style', 'border-right-style', 'border-bottom-style', 'border-left-style', 'border-width', 'border-top-width', 'border-right-width',
|
||||||
|
// 'border-bottom-width', 'border-left-width', 'bottom', 'left', 'right', 'top', 'caption-side', 'clear', 'color', 'content',
|
||||||
|
// 'display', 'float', 'font', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'height',
|
||||||
|
// 'letter-spacing', 'line-height', 'list-style', 'list-style-image', 'list-style-position', 'list-style-type', 'margin', 'margin-top', 'margin-right', 'margin-bottom',
|
||||||
|
// 'margin-left', 'max-height', 'max-width', 'min-height', 'min-width', 'overflow', 'padding',
|
||||||
|
// 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'position', 'quotes', 'table-layout',
|
||||||
|
// 'text-align', 'text-decoration', 'text-indent', 'text-transform', 'vertical-align', 'visibility', 'white-space', 'width', 'word-spacing', 'z-index'
|
||||||
|
// ];
|
||||||
var supportedCss = [
|
var supportedCss = [
|
||||||
'background-color', 'border', 'border-top', 'border-right',
|
'background-color', 'border', 'border-top', 'border-right',
|
||||||
'border-bottom', 'border-left', 'border-collapse', 'border-color', 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', 'border-spacing',
|
'border-bottom', 'border-left', 'border-color', 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color', 'border-spacing',
|
||||||
'border-style', 'border-top-style', 'border-right-style', 'border-bottom-style', 'border-left-style', 'border-width', 'border-top-width', 'border-right-width',
|
'border-style', 'border-top-style', 'border-right-style', 'border-bottom-style', 'border-left-style', 'border-width', 'border-top-width', 'border-right-width',
|
||||||
'border-bottom-width', 'border-left-width', 'bottom', 'left', 'right', 'top', 'caption-side', 'clear', 'color', 'content',
|
'border-bottom-width', 'border-left-width', 'color',
|
||||||
'display', 'float', 'font', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'height',
|
'font', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'height',
|
||||||
'letter-spacing', 'line-height', 'list-style', 'list-style-image', 'list-style-position', 'list-style-type', 'margin', 'margin-top', 'margin-right', 'margin-bottom',
|
'letter-spacing', 'line-height', 'list-style', 'list-style-image', 'list-style-position', 'list-style-type', 'margin', 'margin-top', 'margin-right', 'margin-bottom',
|
||||||
'margin-left', 'max-height', 'max-width', 'min-height', 'min-width', 'overflow', 'padding',
|
'margin-left', 'max-height', 'max-width', 'min-height', 'min-width', 'padding',
|
||||||
'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'position', 'quotes', 'table-layout',
|
'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'quotes',
|
||||||
'text-align', 'text-decoration', 'text-indent', 'text-transform', 'vertical-align', 'visibility', 'white-space', 'width', 'word-spacing', 'z-index'
|
'text-align', 'text-decoration', 'text-indent', 'text-transform', 'vertical-align', 'visibility', 'white-space', 'width', 'word-spacing',
|
||||||
];
|
];
|
||||||
//////
|
//////
|
||||||
|
|
||||||
|
@ -215,7 +226,7 @@ function sanitize(rawContentString) {
|
||||||
tmpAttrsTxt += ' class="' + attrs[i].value + '"';
|
tmpAttrsTxt += ' class="' + attrs[i].value + '"';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastFragment = tmpAttrsTxt.length === 0 ? '<a>' : '<a href="' + tmpAttrsTxt + '">';
|
lastFragment = tmpAttrsTxt.length === 0 ? '<a>' : '<a ' + tmpAttrsTxt + '>';
|
||||||
} else {
|
} else {
|
||||||
var tmpAttrsTxt = '';
|
var tmpAttrsTxt = '';
|
||||||
for (var i = 0; i < attrs.length; i++) {
|
for (var i = 0; i < attrs.length; i++) {
|
||||||
|
@ -314,17 +325,50 @@ function jsonToCss(jsonObj) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractCss(callback) {
|
function extractCss(callback) {
|
||||||
|
// getIncludeStyle(function (result) {
|
||||||
|
// if (result) {
|
||||||
|
// $('body').find('*').each(function (i, pre) {
|
||||||
|
// if (!$(pre).is(':visible')) {
|
||||||
|
// $(pre).replaceWith('');
|
||||||
|
// } else {
|
||||||
|
// var classNames = pre.getAttribute('class');
|
||||||
|
// var tmpName = cssClassesToTmpIds[classNames];
|
||||||
|
// var tmpNewCss = tmpIdsToNewCss[tmpName];
|
||||||
|
// if (!tmpName) {
|
||||||
|
// tmpName = 'class-' + Math.floor(Math.random()*100000);
|
||||||
|
// cssClassesToTmpIds[classNames] = tmpName;
|
||||||
|
// tmpIdsToNewCss[tmpName] = {};
|
||||||
|
// }
|
||||||
|
// if (!tmpNewCss) {
|
||||||
|
// var style = window.getComputedStyle(pre);
|
||||||
|
// tmpNewCss = {};
|
||||||
|
// for (var cssTagName of supportedCss) {
|
||||||
|
// tmpNewCss[cssTagName] = style.getPropertyValue(cssTagName);
|
||||||
|
// }
|
||||||
|
// tmpIdsToNewCss[tmpName] = tmpNewCss;
|
||||||
|
// }
|
||||||
|
// pre.setAttribute('data-class', tmpName);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// callback(jsonToCss(tmpIdsToNewCss));
|
||||||
|
// } else {
|
||||||
|
// callback();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
$('body').find('*').each(function (i, pre) {
|
$('body').find('*').each(function (i, pre) {
|
||||||
if (!$(pre).is(':visible')) {
|
if (!$(pre).is(':visible')) {
|
||||||
$(pre).replaceWith('');
|
$(pre).replaceWith('');
|
||||||
} else {
|
} else {
|
||||||
var classNames = pre.getAttribute('class');
|
var classNames = pre.getAttribute('class');
|
||||||
|
if (!classNames) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var tmpName = cssClassesToTmpIds[classNames];
|
var tmpName = cssClassesToTmpIds[classNames];
|
||||||
var tmpNewCss = tmpIdsToNewCss[tmpName];
|
var tmpNewCss = tmpIdsToNewCss[tmpName];
|
||||||
if (!tmpName) {
|
if (!tmpName) {
|
||||||
tmpName = 'class-' + Math.floor(Math.random()*100000);
|
tmpName = 'class-' + Math.floor(Math.random()*100000);
|
||||||
cssClassesToTmpIds[classNames] = tmpName;
|
cssClassesToTmpIds[classNames] = tmpName;
|
||||||
tmpIdsToNewCss[tmpName] = {};
|
|
||||||
}
|
}
|
||||||
if (!tmpNewCss) {
|
if (!tmpNewCss) {
|
||||||
var style = window.getComputedStyle(pre);
|
var style = window.getComputedStyle(pre);
|
||||||
|
|
|
@ -149,7 +149,7 @@ function dispatch(action, justAddToBuffer) {
|
||||||
chrome.tabs.executeScript(tab[0].id, {file: '/pure-parser.js'});
|
chrome.tabs.executeScript(tab[0].id, {file: '/pure-parser.js'});
|
||||||
chrome.tabs.executeScript(tab[0].id, {file: '/cssjson.js'});
|
chrome.tabs.executeScript(tab[0].id, {file: '/cssjson.js'});
|
||||||
|
|
||||||
chrome.tabs.insertCSS(tab[0].id, {code: currentStyle.style}); // TODO remove from here --- see if it still works
|
// chrome.tabs.insertCSS(tab[0].id, {code: currentStyle.style}); // TODO remove from here --- see if it still works
|
||||||
|
|
||||||
chrome.tabs.executeScript(tab[0].id, {
|
chrome.tabs.executeScript(tab[0].id, {
|
||||||
file: 'extractHtml.js'
|
file: 'extractHtml.js'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue