-
Notifications
You must be signed in to change notification settings - Fork 4
/
Disgallery.plugin.js
131 lines (110 loc) · 3.08 KB
/
Disgallery.plugin.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//META{"name":"Disgallery"}*//
Element.prototype.remove = function() {
this.parentElement.removeChild(this);
}
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
for(var i = this.length - 1; i >= 0; i--) {
if(this[i] && this[i].parentElement) {
this[i].parentElement.removeChild(this[i]);
}
}
}
var allimgsN;
var allImgs;
var allImgslinks;
var currentImgN = 0;
var startImgLink;
var presentationON = false;
var galerySpace;
//var Counter;
var Disgallery = function(){}
Disgallery.prototype.start = function () {
document.onkeydown = checkKey;
document.addEventListener('mouseup', logMouseButton);
};
function RunDisgallery(init = 0){
//GET IMAGES
allImgs = document.getElementsByClassName("da-imageWrapper da-imageZoom da-clickable da-embedWrapper");
allimgsN = allImgs.length;
allImgslinks = [allImgs.length];
for (var i=0; i < allImgs.length; i++) {
allImgslinks[i] = allImgs[i].href;
}
//start GALERY
galerySpace = document.getElementsByClassName("da-modal");
galerySpace[0].innerHTML = '<div style="z-index: 10000; -webkit-flex: 1 0 auto;\
flex: 1 0 auto;\
display: -webkit-flex;\
display: flex;\
-webkit-align-items: flex-start;\
align-items: flex-start;\
-webkit-justify-content: space-around;\
justify-content: space-around;\
overflow: hidden;\
width: auto;" class="a-gal inner-1_1f7b"><img style="max-height: 100vh; max-width: 100%;" class="imageWrapper-38T7d9" id="cimg" src=""><a id="ilink" href=""></img></div>';
document.getElementById("cimg").src = allImgslinks[currentImgN];
}
function scrollImg(n){
currentImgN += n;
if(currentImgN >= allimgsN){
currentImgN = 0;
}else if(currentImgN < 0){
currentImgN = allimgsN-1;
}
var i = allImgslinks[currentImgN];
document.getElementById("cimg").src = i;
RunDisgallery();
console.log("Disgallery Image Number : " + (currentImgN+1) + "/" + (allimgsN));
}
function checkKey(event) {
var x = event.which || event.keyCode;
var left = 37;
var up = 38;
var right = 39;
var down = 40;
var F12 = 123;
var F11 = 122;
if(x == left || x == up){
scrollImg(1);
}
if(x == right || x == down){
scrollImg(-1);
}
if(x == F12){
presentationON = true;
RunDisgallery(1);
}
if(x == F11){ //DOWNLOAD IMAGE
if(!presentationON)return;
var a = $("<a>")
.attr("href", allImgslinks[currentImgN])
.attr("download", "img.png")
.appendTo("body");
a[0].click();
a.remove();
}
if(event.key == "Escape"){
presentationON = false;
}
}
function logMouseButton(e) {
if(e.button == 0){
//console.log("!")
presentationON = false;
}
}
Disgallery.prototype.getSettingsPanel = function () {
return "<h3>Settings Panel</h3>";
};
Disgallery.prototype.getName = function () {
return "Disgallery";
};
Disgallery.prototype.getDescription = function () {
return "Disgallery";
};
Disgallery.prototype.getVersion = function () {
return "0.1.1";
};
Disgallery.prototype.getAuthor = function () {
return "906Eventyon";
};