Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 6ec7890

Browse files
committed
Update v0.5.0 - Implemented support for all resolutions and devices
1 parent 2d74181 commit 6ec7890

File tree

4 files changed

+76
-52
lines changed

4 files changed

+76
-52
lines changed

doc-viewer.js

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,71 @@
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;
275

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;
328

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+
}
3514

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+
}
4118

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;
4520

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+
}
4727

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++;
5445
}
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+
});
5555

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+
}
5869
}
5970
});
71+

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 3,
33

44
"name": "StuHack",
5-
"version": "0.4.9",
5+
"version": "0.5.0",
66
"description": "Banner remover, filter pass & document downloader",
77
"icons": {
88
"16": "img/icon16.png",

remove-banner.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ window.addEventListener('load', function(){
1111

1212
/* Mobile */
1313
if (window.innerWidth <= 990){
14-
var pages = document.getElementById('page-container').childNodes;
15-
if(pages != null){
14+
var container = document.getElementById('page-container');
15+
if(container != null){
16+
var pages = container.childNodes;
1617
for(i=0; i<pages.length; i++) {
1718
if(pages[i].id == ''){
1819
pages[i].parentNode.removeChild(pages[i]);

style.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@
8282
opacity: 1;
8383
}
8484

85+
.download-text{
86+
margin-left: 5px;
87+
}
88+
89+
@media screen and (max-width: 600px) {
90+
.download-text{
91+
margin-left: 5px;
92+
display: none;
93+
}
94+
}
95+
8596

8697
@media print {
8798
.p2hv .stopoverlappingourstyleplease {

0 commit comments

Comments
 (0)