-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
executable file
·170 lines (152 loc) · 5.32 KB
/
test.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
HTMLCollection.prototype.forEach = Array.prototype.forEach;
NodeList.prototype.forEach = Array.prototype.forEach;
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]);
}
}
}
function imgpicShowSave() {
var buttons = document.getElementsByClassName("imgpic_save_btn_container");
buttons.remove();
var images = document.images;
images.forEach(function(element, i){
showImgPicSaveBtn(element);
});
}
function showImgPicSaveBtn(ele) {
var container = document.createElement("span");
container.id = "imgpic_save_btn_container";
container.classList.add("imgpic_save_btn_container");
var btn = document.createElement("button");
btn.id="imgpic_save_btn";
btn.class = "imgpic_save_btn";
btn.innerHTML = "Save";
btn.onclick = function() { showImgpicExtModal(event,ele); };
container.appendChild(btn);
ele.parentNode.insertBefore(container, ele.nextSibling);
if(typeof ele.parentNode.href !="undefined") {
//ele.parentNode.href="javascript:";
//ele.parentNode.removeAttribute("jsaction");
}
ele.removeAttribute("jsaction");
}
function resizeDcsModal(id) {
var modalele = document.getElementById(id);
var windowwidth = window.innerWidth;
var modalwidth = windowwidth*0.6;
var left = (windowwidth / 2) - (modalwidth / 2);
modalele.style.left = left+"px";
}
function imgpicAddClass(id,className) {
element = document.getElementById(id);
element.classList.add(className);
}
function imgpicRemoveClass(id,className) {
element = document.getElementById(id);
element.classList.remove(className);
}
function initDcsModal(id) {
resizeDcsModal(id);
imgpicRemoveClass(id,"hide");
}
var imgpicExtBoards = '';
function imgpicGenerateFormData(object) {
object.imgpic_user_name = imgpic_ext_username;
object.imgpic_password = imgpic_ext_password;
data = new FormData();
for (var property in object) {
if (object.hasOwnProperty(property)) {
// do stuff
data.append( property, object[property] );
}
}
return data;
}
var imgpicExtBoardList ='';
function showImgpicExtModal(e,ele) {
e.preventDefault();
src = ele.src;
var website = document.URL;
var parentNode = ele.parentNode;
href = parentNode.href;
if(typeof href !='undefined') {
var strArray = href.split("imgurl=");
src = ele.src;
if(strArray.length>=1) {
var str = strArray[1];
if(typeof str!="undefined") {
strArray = str.split("&imgrefurl=");
if(strArray.length >=1) {
src = strArray[0];
src = unescape(src);
str = strArray[1];
strArray = str.split("&docid");
if(strArray.length>=1) {
website = strArray[0];
website = unescape(website);
}
}
}
}
}
document.getElementById("imgpicExtWebsite").value=website;
document.getElementById("imgpicExtModalImage").src=src;
var url = imgpicExtBaseUrl+"chrome/getUserBoards";
var data = imgpicGenerateFormData({imgpic_session_id:imgpic_session_id});
if(imgpicExtBoardList!="") {
initDcsModal('imgpicExtSaveModal');
return;
}
imgpicAjaxCall(url,data,function(res){
var result = JSON.parse(res);
if(result.status=="fail") {
imgpicExtReload();
} else {
imgpicExtBoardList =result.html;
document.getElementById("imgpicExtBoards").innerHTML= result.html;
initDcsModal('imgpicExtSaveModal');
}
});
}
function imgpicExtReload() {
var x = confirm("ImgPic Session Expired. Do you want to reload the page?");
if(x) {
window.location.reload();
return false;
}
}
function imgpicAjaxCall(url,data,callback) {
//document.cookie = "PHPSESSID="+imgpic_session_id;
var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
callback(this.responseText);
}
};
xmlhttp.open("POST", url);
xmlhttp.send(data);
}
function imgpicExtSaveBoard(btn,bid) {
btn.disabled=true;
var url = imgpicExtBaseUrl+"chrome/saveImageToBoard";
var data = {};
data.imgsrc = document.getElementById("imgpicExtModalImage").src;
data.website = document.getElementById("imgpicExtWebsite").value;
data.boardid = bid;
data.description = document.getElementById("imgpicExtModalDesc").value;
var formdata = imgpicGenerateFormData(data);
imgpicAjaxCall(url,formdata,function(res){
var result = JSON.parse(res);
if(status=='fail') {
imgpicExtReload();
} else {
imgpicAddClass("imgpicExtSaveModal","hide");
btn.disabled=false;
}
});
}