|
1 | | -window.addEventListener('load', function(){ |
2 | | - const prev_buttons = document.getElementsByClassName("fa-cloud-arrow-down"); |
3 | | - if(prev_buttons.length > 0) { |
4 | | - button1 = document.createElement("button"); |
5 | | - button1.classList.add("download-button-1"); |
6 | | - button1.setAttribute("id","download-button-1"); |
7 | | - button1.innerHTML = '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="fa-cloud-arrow-down" class="svg-inline--fa fa-cloud-arrow-down " role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="currentColor" d="M537.6 226.6c4.1-10.7 6.4-22.4 6.4-34.6 0-53-43-96-96-96-19.7 0-38.1 6-53.3 16.2C367 64.2 315.3 32 256 32c-88.4 0-160 71.6-160 160 0 2.7.1 5.4.2 8.1C40.2 219.8 0 273.2 0 336c0 79.5 64.5 144 144 144h368c70.7 0 128-57.3 128-128 0-61.9-44-113.6-102.4-125.4zm-132.9 88.7L299.3 420.7c-6.2 6.2-16.4 6.2-22.6 0L171.3 315.3c-10.1-10.1-2.9-27.3 11.3-27.3H248V176c0-8.8 7.2-16 16-16h48c8.8 0 16 7.2 16 16v112h65.4c14.2 0 21.4 17.2 11.3 27.3z"></path></svg><span style="margin-left: 5px">Download</span>'; |
8 | | - |
9 | | - button2 = document.createElement("button"); |
10 | | - button2.classList.add("download-button-2"); |
11 | | - button2.setAttribute("id","download-button-2"); |
12 | | - button2.innerHTML = '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="fa-cloud-arrow-down" class="svg-inline--fa fa-cloud-arrow-down " role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="currentColor" d="M537.6 226.6c4.1-10.7 6.4-22.4 6.4-34.6 0-53-43-96-96-96-19.7 0-38.1 6-53.3 16.2C367 64.2 315.3 32 256 32c-88.4 0-160 71.6-160 160 0 2.7.1 5.4.2 8.1C40.2 219.8 0 273.2 0 336c0 79.5 64.5 144 144 144h368c70.7 0 128-57.3 128-128 0-61.9-44-113.6-102.4-125.4zm-132.9 88.7L299.3 420.7c-6.2 6.2-16.4 6.2-22.6 0L171.3 315.3c-10.1-10.1-2.9-27.3 11.3-27.3H248V176c0-8.8 7.2-16 16-16h48c8.8 0 16 7.2 16 16v112h65.4c14.2 0 21.4 17.2 11.3 27.3z"></path></svg><span style="margin-left: 5px">Download</span>'; |
13 | | - |
14 | | - try{ |
15 | | - prev_buttons[0].parentNode.parentNode.prepend(button1); |
16 | | - prev_buttons[1].parentNode.parentNode.removeChild(prev_buttons[1].parentNode); |
17 | | - }catch(err){ |
18 | | - console.log(err); |
19 | | - } |
20 | | - try{ |
21 | | - prev_buttons[5].parentNode.parentNode.prepend(button2); |
22 | | - prev_buttons[5].parentNode.parentNode.removeChild(prev_buttons[5].parentNode); |
23 | | - }catch(err){ |
24 | | - console.log(err); |
25 | | - } |
26 | | - |
| 1 | +function downloadDoc(){ |
| 2 | + var head = document.getElementsByTagName("head")[0].innerHTML; |
| 3 | + var tit = document.getElementsByTagName("h1")[0].innerHTML; |
| 4 | + var pages = document.getElementById('page-container').childNodes; |
27 | 5 |
|
28 | | - function downloadDoc(){ |
29 | | - var head = document.getElementsByTagName("head")[0].innerHTML; |
30 | | - var tit = document.getElementsByTagName("h1")[0].innerHTML; |
31 | | - var pages = document.getElementById('page-container').childNodes; |
| 6 | + width = pages[0].offsetWidth; |
| 7 | + height = pages[0].offsetHeight; |
32 | 8 |
|
33 | | - width = pages[0].offsetWidth; |
34 | | - height = pages[0].offsetHeight; |
| 9 | + if (width > height){ |
| 10 | + print_opt = "{@page {size: A5 landscape;} body {zoom: 90%;}"; |
| 11 | + }else{ |
| 12 | + print_opt = "{@page {size: A5 portrait;}"; |
| 13 | + } |
35 | 14 |
|
36 | | - if (width > height){ |
37 | | - print_opt = "{@page {size: A5 landscape;} body {zoom: 90%;}"; |
38 | | - }else{ |
39 | | - print_opt = "{@page {size: A5 portrait;}"; |
40 | | - } |
| 15 | + for(i=0; i<pages.length; i++){ |
| 16 | + pages[i].childNodes[0].style = "display: block;"; |
| 17 | + } |
41 | 18 |
|
42 | | - for(i=0; i<pages.length; i++){ |
43 | | - pages[i].childNodes[0].style = "display: block;"; |
44 | | - } |
| 19 | + var pdf = pages[0].parentNode.parentNode.parentNode.innerHTML; |
45 | 20 |
|
46 | | - var pdf = pages[0].parentNode.parentNode.parentNode.innerHTML; |
| 21 | + newWindow = window.open("", "Document", "height=865,width=625,status=yes,toolbar=no,menubar=no"); |
| 22 | + newWindow.document.getElementsByTagName("head")[0].innerHTML = head + "<style> .nofilter{filter: none !important;} </style>" + "<style> @media print " + print_opt + "</style>"; |
| 23 | + newWindow.document.title = tit; |
| 24 | + newWindow.document.getElementsByTagName("body")[0].innerHTML = pdf; |
| 25 | + newWindow.document.getElementsByTagName("body")[0].childNodes[0].style = ""; |
| 26 | +} |
47 | 27 |
|
48 | | - newWindow = window.open("", "Document", "height=865,width=625,status=yes,toolbar=no,menubar=no"); |
49 | | - newWindow.document.getElementsByTagName("head")[0].innerHTML = head + "<style> .nofilter{filter: none !important;} </style>" + "<style> @media print " + print_opt + "</style>"; |
50 | | - newWindow.document.title = tit; |
51 | | - newWindow.document.getElementsByTagName("body")[0].innerHTML = pdf; |
52 | | - newWindow.document.getElementsByTagName("body")[0].childNodes[0].style = ""; |
53 | | - |
| 28 | +function addButtons(){ |
| 29 | + button1 = document.createElement("button"); |
| 30 | + button1.classList.add("download-button-1"); |
| 31 | + button1.innerHTML = '<svg aria-hidden="true" focusable="false" data-prefix="fas" class="svg-inline--fa" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="currentColor" d="M537.6 226.6c4.1-10.7 6.4-22.4 6.4-34.6 0-53-43-96-96-96-19.7 0-38.1 6-53.3 16.2C367 64.2 315.3 32 256 32c-88.4 0-160 71.6-160 160 0 2.7.1 5.4.2 8.1C40.2 219.8 0 273.2 0 336c0 79.5 64.5 144 144 144h368c70.7 0 128-57.3 128-128 0-61.9-44-113.6-102.4-125.4zm-132.9 88.7L299.3 420.7c-6.2 6.2-16.4 6.2-22.6 0L171.3 315.3c-10.1-10.1-2.9-27.3 11.3-27.3H248V176c0-8.8 7.2-16 16-16h48c8.8 0 16 7.2 16 16v112h65.4c14.2 0 21.4 17.2 11.3 27.3z"></path></svg><span class="download-text">Download</span>'; |
| 32 | + |
| 33 | + let prev_buttons = document.getElementsByClassName("fa-cloud-arrow-down"); |
| 34 | + let i = 0; |
| 35 | + buttons = []; |
| 36 | + while(prev_buttons.length > 0){ |
| 37 | + if(prev_buttons[0].parentNode.parentNode.firstChild.classList.contains("download-button-1")){ |
| 38 | + prev_buttons[0].parentNode.remove(); |
| 39 | + }else{ |
| 40 | + buttons.push(button1.cloneNode(true, true)); |
| 41 | + buttons[i].onclick = function() {downloadDoc()}; |
| 42 | + prev_buttons[0].parentNode.parentNode.prepend(buttons[i]); |
| 43 | + prev_buttons[0].parentNode.remove(); |
| 44 | + i++; |
54 | 45 | } |
| 46 | + prev_buttons = document.getElementsByClassName("fa-cloud-arrow-down"); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +var observer = new MutationObserver(function(mutations) { |
| 51 | + mutations.forEach(function(mutation) { |
| 52 | + addButtons(); |
| 53 | + }); |
| 54 | +}); |
55 | 55 |
|
56 | | - button1.onclick = function() {downloadDoc()}; |
57 | | - button2.onclick = function() {downloadDoc()}; |
| 56 | + |
| 57 | + |
| 58 | +window.addEventListener('load', function(){ |
| 59 | + const prev_buttons = document.getElementsByClassName("fa-cloud-arrow-down"); |
| 60 | + if(prev_buttons.length > 0) { |
| 61 | + try{ |
| 62 | + addButtons(); |
| 63 | + }catch(err){ |
| 64 | + console.log(err); |
| 65 | + }finally{ |
| 66 | + let element = document.getElementById("viewer-wrapper"); |
| 67 | + observer.observe(element, { attributes: true, childList: true, subtree: true}); |
| 68 | + } |
58 | 69 | } |
59 | 70 | }); |
| 71 | + |
0 commit comments