forked from doankhoi/easybook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
67 lines (58 loc) · 1.63 KB
/
Copy pathcontent.js
File metadata and controls
67 lines (58 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function getElement(selector) {
var element = $("#" + selector);
if (element.length == 0) {
element = $("." + selector);
if (element.length == 0) {
element = $(selector);
if (element.length == 0) {
console.error("Not found element: " + selector);
return null
}
}
element = $(element[0]);
}
return element;
}
function keepOnly(keepSelector, parentSelector) {
var remainEl = getElement(keepSelector);
var parrentEl = getElement(parentSelector);
if (!remainEl || !parrentEl) {
console.error("Not found element: " + keepSelector + " or " + parentSelector);
return;
}
var remainEl = remainEl.detach();
console.log(parrentEl);
parrentEl.empty().append(remainEl);
}
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.message === "print_page") {
keepOnly('container', 'body');
keepOnly('js-toc', 'container');
keepOnly('section[role="document"]', 'js-toc');
keepOnly('sbo-rt-content', 'section[role="document"]');
console.log('Change CSS');
var body = $('body');
body.css({
"padding": "0px"
});
var div = $('#sbo-rt-content');
div.css({
"maxWidth": "100%",
"margin": "0px",
"padding": "0px"
});
var p = $('.scalefonts #sbo-rt-content div p');
p.css({
"textAlign": "justify"
});
var img = $('#sbo-rt-content .image');
img.css({
"textAlign": "center"
});
var h = $('#sbo-rt-content h2');
h.attr('style', 'margin-top: 0px !important');
window.print();
}
}
);