-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinjection.js
87 lines (70 loc) · 3.04 KB
/
injection.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
originalUrl = window.location.href;
var index = window.location.href.indexOf("?url=");
url = window.location.href.substring(index+5, window.location.href.length-14);
history.replaceState({}, "NativeDoc", "/nativeDoc");
$(document).keydown(function(event) {
// If Control or Command key is pressed and the R key is pressed
// run refresh function. 82 is the key code for R.
if((event.ctrlKey || event.metaKey) && event.which == 82) {
// Refresh Function
console.log(originalUrl);
window.location.href = originalUrl;
event.preventDefault();
};
});
$(".ndfHFb-c4YZDc-aSZUA-Wrql6b").remove();
dl_url = chrome.extension.getURL('dl.jpg');
print_url = chrome.extension.getURL('printer.png')
// <div id='save' style='float:left' class='btn-l'><img class='icon' src='"+save_url+"'></div>
$("body").append("<div class='toolbar'><div id='print' style='float:left' class='btn-l'><img class='icon2' src='"
+print_url+"'></div><div id='download' style='float:right' class='btn-r'><img class='icon' src='"
+dl_url+"'></div></div>")
$(document).ready(function() {
$("body").wrap("<div class='invisible'></div>");
$('.invisible').after("<div class='visible'></div>");
//Extract total page numbers from the alt of the first page
var firstBLOBAlt = $('h2.ndfHFb-c4YZDc-cYSp0e-DARUcf-Df1ZY-tJHJj').first().text();
var numberIndex = firstBLOBAlt.indexOf("of ");
var numPages = parseInt(firstBLOBAlt.substr(numberIndex + 3, firstBLOBAlt.length-numberIndex-3));
var pages = [];
var count = 0;
for(var i = 0; i < numPages; i++) {
//Asynchronous, so page order is arbitrary... need to sort it after all have loaded
//At the same time, we can't block on the function because user needs to be able to move around
$('<img class="blob" src="'+ nativeDoc_blob + (''+i) +'" page='+i+'>').load(function() {
pages.push($(this));
count++;
if(count >= numPages) {
pages.sort(function(a,b) {
return a.attr("page") - b.attr("page");
});
pages.forEach(function(page) {
$('.visible').append(page);
});
}
});
}
$('#download').click(function(){
window.location.href = url;
})
$('#print').click(function(){
window.print();
})
$(document).keydown(function(event) {
// If Control or Command key is pressed and the S key is pressed
// run save function. 83 is the key code for S.
if((event.ctrlKey || event.metaKey) && event.which == 83) {
// Save Function
$('#download').click();
event.preventDefault();
};
});
$(document).keydown(function(event) {
// If Control or Command key is pressed and the P key is pressed
// run print function. 80 is the key code for P.
if((event.ctrlKey || event.metaKey) && event.which == 80) {
window.print();
event.preventDefault();
};
});
});