-
Notifications
You must be signed in to change notification settings - Fork 5
/
wfes-ImageMod.js
146 lines (130 loc) · 4.5 KB
/
wfes-ImageMod.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// @name image Mods
// @version 1.2.0
// @description open fullsize images in "named" tabs
// @author AlterTobi
(function() {
"use strict";
function addFullImageButton(elem, url, target, position = "afterEnd", styleclass = "lupe", elemID=false, spanclass = "") {
const a = document.createElement("a");
const span = document.createElement("span");
span.className = "material-icons material-icons-fontsize " + spanclass;
span.appendChild(document.createTextNode("search"));
a.appendChild(span);
a.target = target;
a.href = url;
if (elemID) {
a.id = elemID;
}
a.className = styleclass;
switch (position) {
case "afterEnd":
case "beforeBegin":
elem.parentNode.style.position = "relative";
break;
case "beforeEnd":
case "afterBegin":
elem.style.position = "relative";
break;
}
elem.insertAdjacentElement(position, a);
}
// setImage URL on existing element
function setImageURL(buttonID, imageUrl) {
const elem = document.getElementById(buttonID);
elem.href = imageUrl;
}
function addFullSizeImageLinksReview() {
const myCssId = "imageModsCSSReview";
const myStyle = `.material-icons-fontsize {
font-size: 48px;
}
.lupe {
position: absolute;
left: 0px;
}
.bottom {
bottom: 0px;
}
`;
let elem, imageUrl;
const myData = window.wfes.g.reviewPageData();
window.wfes.f.addCSS(myCssId, myStyle);
switch (myData.type) {
case "NEW":
elem = document.getElementsByClassName("wf-image-modal flex-grow bg-contain bg-center bg-no-repeat");
imageUrl = myData.imageUrl + "=s0";
addFullImageButton(elem[0], imageUrl, "mainImage");
// Supporting Image
if (myData.supportingImageUrl) {
imageUrl = myData.supportingImageUrl + "=s0";
addFullImageButton(elem[1], imageUrl, "supportingImage");
}
break;
case "EDIT":
elem = document.getElementsByClassName("wf-image-modal");
imageUrl = myData.imageUrl + "=s0";
addFullImageButton(elem[0], imageUrl, "mainImage", "beforeBegin");
break;
case "PHOTO":
elem = document.getElementsByClassName("photo-card__photo");
for (let i=0; i < elem.length; i++) {
imageUrl = myData.newPhotos[i].value + "=s0";
addFullImageButton(elem[i].parentNode.parentNode.parentNode, imageUrl, "additionalImage", "beforeEnd", "lupe bottom");
}
break;
}
}
function addFullSizeImageLinksNomDetail() {
const myCssId = "imageModsCSSNomDetail";
const myStyle = `.material-icons-fontsize {
font-size: 48px;
}
.lupesup {
position: absolute;
left: 0px;
top: 20px;
}
.luperel {
position: relative;
left: 0px;
}
.absolute {
position: absolute;
}
`;
const buttonIDmain = "imageModsBtnMain";
const buttonIDsup = "imageModsBtnSup";
let imageUrl;
const myData = window.wfes.g.nominationDetail();
// only nominations, for edits use Wayfarer Contribution Management Layout
if ("NOMINATION" === myData.type) {
window.wfes.f.addCSS(myCssId, myStyle);
const elem = document.getElementsByClassName("wf-image-modal details-pane__image");
imageUrl = myData.imageUrl + "=s0";
// main Image
if ( null === document.getElementById(buttonIDmain)) {
addFullImageButton(elem[0], imageUrl, "mainImage", "beforeBegin", "luperel", buttonIDmain, "absolute");
} else {
setImageURL(buttonIDmain, imageUrl);
}
// Supporting Image
if (myData.supportingImageUrl) {
imageUrl = myData.supportingImageUrl + "=s0";
if ( null === document.getElementById(buttonIDsup)) {
addFullImageButton(elem[1].parentNode, imageUrl, "supportingImage", "beforeEnd", "lupesup", buttonIDsup);
} else {
setImageURL(buttonIDsup, imageUrl);
}
}
} else {
// remove magnifier
[buttonIDmain, buttonIDsup].forEach(buttonID => {
const element = document.getElementById(buttonID);
if (element) {element.remove();}
});
}
}
window.addEventListener("WFESNominationDetailLoaded", () => {setTimeout(addFullSizeImageLinksNomDetail, 100);});
window.addEventListener("WFESReviewPageLoaded", () => {setTimeout(addFullSizeImageLinksReview, 100);});
console.log("Script loaded:", GM_info.script.name, "v" + GM_info.script.version);
})();