forked from giosilvi/GPT-Prompter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
700 lines (603 loc) · 26.4 KB
/
popup.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
// GENERAL FUNCTIONS
function makePromptList(items) {
// Clear the node 'list-of-prompts'.
var ul = document.getElementById('list-of-prompts');
while (ul.firstChild) {
ul.removeChild(ul.firstChild);
}
var titleExists = false;
for (var i = 0; i < items.customprompt.length; i++) {
var li = document.createElement('li');
li.className = 'list-group-item draggable';
li.setAttribute('draggable', 'true');
li.setAttribute('id', i);
// Create text elements for title, prompt, model, temperature, and max tokens
var titleText = document.createElement('span');
titleText.className = 'feature-text';
// check if title exists
if (items.customprompt[i]['title'] != undefined && items.customprompt[i]['title'] != '') {
titleText.innerText = items.customprompt[i]['title'];
titleText.setAttribute('data-title', 'Title:');
titleExists = true;
} else {
titleExists = false;
}
var promptText = document.createElement('span');
promptText.className = 'prompt-text';
promptText.innerText = items.customprompt[i]['prompt'];
var modelText = document.createElement('span');
modelText.className = 'feature-text';
modelText.innerText = ` ${items.customprompt[i]['model']}`;
modelText.setAttribute('data-title', 'Model:');
var tempText = document.createElement('span');
tempText.className = 'feature-text';
tempText.style.marginLeft = '25px';
tempText.innerText = ` ${items.customprompt[i]['temperature']}`;
tempText.setAttribute('data-title', 'Temp:');
var maxTokensText = document.createElement('span');
maxTokensText.className = 'feature-text';
maxTokensText.style.marginLeft = '25px';
maxTokensText.innerText = ` ${items.customprompt[i]['max_tokens']}`;
maxTokensText.setAttribute('data-title', 'Max tokens:');
// Create Add title , edit and delete buttons
var titleButton = document.createElement('button');
titleButton.className = 'save';
if (titleExists) {
titleButton.innerText = 'Edit Title';
} else {
titleButton.innerText = 'Add Title';
}
titleButton.setAttribute('id', `title${i}`);
var editButton = document.createElement('button');
editButton.className = 'save';
editButton.innerText = 'Edit Prompt';
editButton.setAttribute('id', `edit${i}`);
var deleteButton = document.createElement('button');
deleteButton.className = 'save';
deleteButton.innerText = 'Delete';
deleteButton.setAttribute('id', `del${i}`);
// Add a textare for the title, make it hidden, make it one line, and 500px wide
var titleInsertText = document.createElement('textarea');
titleInsertText.className = 'title-text form-control';
titleInsertText.setAttribute('id', `title-text${i}`);
titleInsertText.style.display = 'none';
titleInsertText.setAttribute('rows', '1');
titleInsertText.setAttribute('cols', '60');
titleInsertText.setAttribute('placeholder', 'Enter title here (click away to save)');
// Append all elements to the list item
if (titleExists) {
li.appendChild(titleText);
li.appendChild(document.createElement('br'));
}
li.appendChild(promptText);
li.appendChild(document.createElement('br'));
li.appendChild(modelText);
li.appendChild(tempText);
li.appendChild(maxTokensText);
li.appendChild(document.createElement('br'));
li.appendChild(titleButton);
li.appendChild(editButton);
li.appendChild(deleteButton);
li.appendChild(document.createElement('br'));
li.appendChild(titleInsertText);
// Append the list item to the 'list-of-prompts' node
ul.appendChild(li);
// Call the addEventsDragAndDrop function with the list item as the parameter
addEventsDragAndDrop(li);
}
updateLowerButtons(items)
}
function updateLowerButtons(items) {
items.customprompt.forEach((prompt, index) => {
const id = index.toString();
const addTitleButton = document.getElementById(`title${id}`);
addTitleButton.addEventListener('click', () => {
addTitle(id);
});
const editButton = document.getElementById(`edit${id}`);
editButton.addEventListener('click', () => {
editPrompt(id);
});
const deleteButton = document.getElementById(`del${id}`);
deleteButton.addEventListener('click', () => {
const element = document.getElementById(id);
element.classList.add('hide');
setTimeout(() => {
erasePrompt(id);
}, 600);
});
});
}
function toggleSaveKeyButton() {
const apiKeyInput = document.getElementById('apikey');
const saveKeyButton = document.getElementById('saveKey');
const deleteKeyButton = document.getElementById('deleteKey');
const linkToAPI = document.getElementById('linktoAPI');
const showKeyButton = document.getElementById('showKey');
if (apiKeyInput.style.display === 'none') {
apiKeyInput.style.display = 'block';
saveKeyButton.style.display = 'block';
deleteKeyButton.style.display = 'block';
linkToAPI.style.display = 'block';
showKeyButton.innerHTML = 'Hide API';
chrome.storage.sync.get('APIKEY', (items) => {
if (typeof items.APIKEY !== 'undefined') {
apiKeyInput.value = items.APIKEY;
}
});
} else {
apiKeyInput.style.display = 'none';
saveKeyButton.style.display = 'none';
deleteKeyButton.style.display = 'none';
linkToAPI.style.display = 'none';
showKeyButton.innerHTML = 'Show API';
}
}
function hideSaveKey() {
//hide the element with id 'apikey' and the 'saveKey' button
document.getElementById('apikey').style.display = 'none';
document.getElementById('saveKey').style.display = 'none';
document.getElementById('deleteKey').style.display = 'none';
document.getElementById('linktoAPI').style.display = 'none';
document.getElementById('showKey').style.display = 'block';
document.getElementById('showKey').innerHTML = 'Show API';
}
//add function to save the the custom prompt in storage
function savePrompt() {
document.getElementById('createPrompt').disabled = true;
// get the text from the prompt
var model = document.getElementById("inputmodel").value;
var temp = parseFloat(document.getElementById("temp").value);
var token = parseInt(document.getElementById("token").value);
var text = document.getElementById("promptinput").value;
var bodyData = { "model": model, "temperature": temp, "max_tokens": token, "prompt": text, "echo": true, "stream": true }
// try to retrive the custom prompt from the storage API
chrome.storage.sync.get('customprompt', function (items) {
// Check that the prompt exists
if (typeof items.customprompt !== 'undefined') {
var prompt_already_present = false;
// check that the prompt is not already present, looping over every prompt in the array and comparing each values in the dictionary
for (var i = 0; i < items.customprompt.length; i++) {
if (items.customprompt[i]['prompt'] == text && items.customprompt[i]['model'] == model && items.customprompt[i]['temperature'] == temp && items.customprompt[i]['max_tokens'] == token) {
prompt_already_present = true;
}
}
var customprompt = document.getElementById('promptinput').value;
if (prompt_already_present == false) {
items.customprompt.push(bodyData);
makePromptList(items) //update the list of prompts
chrome.storage.sync.set({ 'customprompt': items.customprompt }, function () {
// Notify that we saved
console.log('Your custom prompt was saved.');
})
chrome.runtime.sendMessage({ text: "new_prompt_list" });
document.getElementById('promptinput').value = 'Prompt created! Available in context menu (right click).';
document.getElementById("promptinput").style.color = "#10a37f"; //green color for the prompt created
}
else {
console.log('Your custom prompt was already saved.');
var customprompt = document.getElementById('promptinput').value;
document.getElementById('promptinput').value = 'Prompt already present! Available in context menu (right click).';
//yellow color for the prompt created
document.getElementById("promptinput").style.color = "#f7b500";
}
setTimeout(function () {
document.getElementById('promptinput').value = customprompt
document.getElementById("promptinput").style.color = "#495057" //exadecimal standard color
document.getElementById('createPrompt').disabled = false;
}, 2000);
} else {
// if the prompt does not exist, create a new array with the prompt
items.customprompt = [bodyData];
};
});
}
//add a function to erase a custom prompt from the storage API provided the index of the prompt
async function erasePrompt(index) {
try {
const items = await getFromStorage('customprompt');
if (items && items.customprompt && index < items.customprompt.length) {
items.customprompt.splice(index, 1); // splice: remove 1 element at index
await setInStorage({ customprompt: items.customprompt });
makePromptList(items);
console.log('Your custom prompt was erased.');
chrome.runtime.sendMessage({ text: "new_prompt_list" });
}
} catch (error) {
console.error(error);
}
}
async function getFromStorage(key) {
return new Promise((resolve, reject) => {
chrome.storage.sync.get(key, (items) => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve(items);
}
});
});
}
async function setInStorage(items) {
return new Promise((resolve, reject) => {
chrome.storage.sync.set(items, () => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve();
}
});
});
}
function addTitle(index) {
let textTitle = document.getElementById(`title-text${index}`);
textTitle.style.display = 'block';
textTitle.focus();
textTitle.addEventListener('blur', function () {
saveTitle(index);
textTitle.style.display = 'none';
chrome.runtime.sendMessage({ text: "new_prompt_list" });
});
}
function saveTitle(index) {
// get the text from the title
var title = document.getElementById(`title-text${index}`).value;
// try to retrive the custom prompt from the storage API
chrome.storage.sync.get('customprompt', function (items) {
// Check that the prompt exists
if (typeof items.customprompt !== 'undefined') {
// check that the index is valid
if (index <= items.customprompt.length) {
// add the title to the prompt
items.customprompt[index]['title'] = title;
// save the title in the storage
chrome.storage.sync.set({ 'customprompt': items.customprompt }, function () {
// Notify that is saved
console.log('Your custom prompt title was saved.');
})
makePromptList(items); //update the list of prompts
}
}
});
}
function editPrompt(index) {
chrome.storage.sync.get('customprompt', function (items) {
// Check that the prompt exists
if (typeof items.customprompt !== 'undefined') {
// check that the index is valid
if (index <= items.customprompt.length) {
// copy the prompt from the array to the input
document.getElementById('promptinput').value = items.customprompt[index]['prompt'];
document.getElementById('inputmodel').value = items.customprompt[index]['model'];
document.getElementById('temp').value = items.customprompt[index]['temperature'];
document.getElementById('temperature').value = items.customprompt[index]['temperature'];
document.getElementById('token').value = items.customprompt[index]['max_tokens'];
document.getElementById('maxtoken').value = items.customprompt[index]['max_tokens'];
// set the focus on the input
document.getElementById('promptinput').focus();
// document.getElementById('createPrompt').disabled = false;
// document.getElementById('createPrompt').innerHTML = '<b>Edit prompt</b>';
// document.getElementById('createPrompt').onclick = function () { editPrompt2(index) };
}
}
});
}
// function editPrompt2(index) {
// //call savePrompt function
// // erasePrompt(index);
// savePrompt();
// // change the innerHTML of the button
// document.getElementById('createPrompt').innerHTML = '<b>Create prompt</b>';
// // change the onclick function of the button
// document.getElementById('createPrompt').onclick = function () { savePrompt() };
// }
function saveKey() {
// Get a value saved in an input
var apiKey = document.getElementById('apikey').value;
// Save it using the Chrome extension storage API
chrome.storage.sync.set({ 'APIKEY': apiKey }, function () {
// Notify that we saved
console.log('Your API key was saved.');
});
}
//if the user click on the toggle probabilityToggle then save the value in the storage under chrome.storage.sync.set({ 'advancedSettings': { "showProb": true or false} });
// add listener to the probabilityToggle
function addListenerToProbabilityToggle() {
// set the value of the probabilityToggle retrieved from the storage
chrome.storage.sync.get('advancedSettings', function (items) {
// Check that the advanced setting exists
if (typeof items.advancedSettings !== 'undefined') {
// Check that the showProb exists
if (typeof items.advancedSettings.showProb !== 'undefined') {
// set the value of the probabilityToggle
document.getElementById('probabilityToggle').checked = items.advancedSettings.showProb;
}
}
});
// add listener to the probabilityToggle
document.getElementById('probabilityToggle').addEventListener('click', function () {
// get the value of the probabilityToggle
var probabilityToggle = document.getElementById('probabilityToggle').checked;
// retrieve advancedSettings from the storage
chrome.storage.sync.get('advancedSettings', function (items) {
// add ProbabilityToggle to the advancedSettings
items.advancedSettings.showProb = probabilityToggle;
// save the value in the storage
chrome.storage.sync.set({ 'advancedSettings': items.advancedSettings }, function () {
// Notify that we saved
console.log('Your advanced settings were saved.');
}
);
});
});
}
// redo the same for autoAddToggle
function addListenerToAutoAddToggle() {
chrome.storage.sync.get('advancedSettings', function (items) {
// Check that the advanced setting exists
if (typeof items.advancedSettings !== 'undefined') {
// Check that the autoAdd exists
if (typeof items.advancedSettings.autoAdd !== 'undefined') {
// set the value of the autoAddToggle
document.getElementById('autoAddToggle').checked = items.advancedSettings.autoAdd;
}
}
});
document.getElementById('autoAddToggle').addEventListener('click', function () {
var autoAddToggle = document.getElementById('autoAddToggle').checked;
// retrieve advancedSettings from the storage
chrome.storage.sync.get('advancedSettings', function (items) {
// add autoAddToggle to the advancedSettings
items.advancedSettings.autoAdd = autoAddToggle;
// save the value in the storage
chrome.storage.sync.set({ 'advancedSettings': items.advancedSettings }, function () {
// Notify that we saved
console.log('Your advanced settings were saved.');
}
);
});
});
}
function checkInputOfPromptDesigner() {
document.getElementById('promptinput').addEventListener('keyup', onkey, false);
function onkey(e) {
//get the value of the input
var inputtext = document.getElementById('promptinput').value;
//check if "#TEXT#" doesn`t contained in inputtext
if (inputtext.indexOf("#TEXT#") == -1) { // if not found
//check if "#TEXT" is contained in inputtext
if (inputtext.indexOf("#TEXT") != -1) { // if found
//if yes, replace it with "#TEXT#"
inputtext = inputtext.replace("#TEXT", "#TEXT#");
// update the input
document.getElementById('promptinput').value = inputtext;
}
//check if "TEXT#" is contained in inputtext
else if (inputtext.indexOf("TEXT#") != -1) {
//if yes, replace it with "#TEXT#"
inputtext = inputtext.replace("TEXT#", "#TEXT#");
// update the input
document.getElementById('promptinput').value = inputtext;
}
else {
document.getElementById('promptinput').value = "#TEXT#";
}
}
}
}
//make a function that listen for event keydown on the input
document.addEventListener('DOMContentLoaded', function () {
checkInputOfPromptDesigner();
addListenerToProbabilityToggle();
addListenerToAutoAddToggle();
}
);
//LISTENERS FOR THE BUTTONS
//Load History of the custom prompts
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('history').addEventListener('click', function () {
//access local history.html file, and modify the html
chrome.tabs.create({ url: chrome.runtime.getURL('history.html'), active: true });
}
);
}
);
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('saveKey').addEventListener('click', onclick, false)
function onclick() {
//send a message to background.js to check the API key
chrome.runtime.sendMessage({ text: "checkAPIKey", apiKey: document.getElementById('apikey').value });
}
}, false)
//add Listenere to deleteKey button
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('deleteKey').addEventListener('click', onclick, false)
function onclick() {
//send a message to background.js to delete the API key
chrome.storage.sync.remove('APIKEY');
// take the value of the input and erase it
document.getElementById('apikey').value = 'API KEY deleted!';
setTimeout(function () {
document.getElementById('apikey').value = "";
}, 2000);
// reset the icon to the default one
chrome.action.setIcon({ path: "icons/icon16.png" })
}
}, false)
// Attach the click event to the respective elements
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('createPrompt').addEventListener('click', savePrompt);
document.getElementById('showKey').addEventListener('click', toggleSaveKeyButton);
document.getElementById('linktoAPI').addEventListener('click', openLink);
document.getElementById('linktoLogprob').addEventListener('click', openLink);
}, false);
function openLink() {
chrome.tabs.create({ active: true, url: this.href });
}
// Load the list of custom prompts from the storage
document.addEventListener('DOMContentLoaded', function () {
//retrieve from chrome storage the custom prompt
chrome.storage.sync.get('customprompt', function (items) {
//if it exists send an alert
if (typeof items.customprompt !== 'undefined') {
makePromptList(items);
}
})
checkAPIKeyatBeginning();
// add listener to selection on the inputmodel
document.getElementById('inputmodel').addEventListener('change', function () {
//if the user select the model text-davinci-003 or text-davinci-002
console.log(document.getElementById('inputmodel').value);
const model = document.getElementById('inputmodel').value;
if (model == "text-davinci-003" || model == "text-davinci-002") {
// set the max value of element input maxtokens to 4096
document.getElementById('maxtoken').max = 4000;
}
else if (model == "code-davinci-002") {
// set the max value of element input maxtokens to 8000
document.getElementById('maxtoken').max = 8000;
}
else {
// set the max value of element input maxtokens to 2048
document.getElementById('maxtoken').max = 2048;
}
//end
});
}, false);
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.message === "API_key_valid") {
saveKey();
chrome.action.setIcon({ path: "icons/iconA16.png" });
document.getElementById("apikey").value = "The API KEY is valid. Hooray!";
document.getElementById("apikey").style.color = "#10a37f"; //green color
setTimeout(() => {
hideSaveKey();
// set the color back to black
document.getElementById("apikey").style.color = "#495057";
}, 3000);
//
} else if (request.message === "API_key_invalid") {
document.getElementById("apikey").value = "The API KEY is invalid. Try again!";
document.getElementById("apikey").style.color = "#e74c3c"; //red color
setTimeout(() => {
document.getElementById("apikey").value = "";
document.getElementById("apikey").style.color = "#495057";
}, 3000);
}
});
// if the API key is present in memory, hide the button to save it
function checkAPIKeyatBeginning() {
chrome.storage.sync.get('APIKEY', function (items) {
// Check that the API key exists
if (typeof items.APIKEY !== 'undefined') {
hideSaveKey();
}
else {
//hide show key button
document.getElementById('showKey').style.display = 'none';
}
}
);
}
// Update the values of temperature and max token
// To get the value of the temperature and pass it to element with id temp
function Temp() {
document.getElementById("temp").value = document.getElementById("temperature").value;
}
// add listener when the input is changed and activate the function Temp()
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('temperature').addEventListener('mousemove', Temp, false)
}, false)
function Token() {
document.getElementById("token").value = document.getElementById("maxtoken").value;
}
// add listener when the input is changed and activate the function Token()
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('maxtoken').addEventListener('mousemove', Token, false)
}, false)
// DRAGGABLE LIST OF PROMPTS in popup.html
var btn = document.querySelector('.add');
var remove = document.querySelector('.draggable');
function dragStart(e) {
this.style.opacity = '0.4';
dragSrcEl = this;
e.dataTransfer.effectAllowed = 'move';
console.log("Inner html", this.innerHTML)
e.dataTransfer.setData('text/html', this.innerHTML);
// can one transfer also the id of the element? Answer: yes
};
function dragEnter(e) {
this.classList.add('over');
}
function dragLeave(e) {
e.stopPropagation();
this.classList.remove('over');
}
function dragOver(e) {
e.preventDefault();
e.dataTransfer.dropEffect = 'move';
return false;
}
function dragDrop(e) {
if (dragSrcEl != this) {
console.log('dragSrcEl', dragSrcEl)
dragSrcEl.innerHTML = this.innerHTML;
const id_source = dragSrcEl.id;
dragSrcEl.id = this.id;
this.innerHTML = e.dataTransfer.getData('text/html');
this.id = id_source;
// get the button delete of the source and the target
}
return false;
}
function dragEnd(e) {
var listItens = document.querySelectorAll('.draggable');
[].forEach.call(listItens, function (item) {
item.classList.remove('over');
});
this.style.opacity = '1';
// save the new order of the list
// newOrderFromID();
reoderListinMemory();
}
function newOrderFromID() {
var listItens = document.querySelectorAll('.draggable');
var list = [];
[].forEach.call(listItens, function (item) {
list.push(item.id);
});
console.log('list', list)
return list;
}
function reoderListinMemory() {
// get the list of prompts from memory
chrome.storage.sync.get('customprompt', function (items) {
// Check that the API key exists
if (typeof items.customprompt !== 'undefined') {
// alert(items.customprompt);
var list = items.customprompt;
// get the new order of the list
var newOrder = newOrderFromID();
// reoder the list
var newList = [];
for (var i = 0; i < newOrder.length; i++) {
newList.push(list[newOrder[i]]);
}
// save the new list in memory
chrome.storage.sync.set({ 'customprompt': newList }, function () {
items.customprompt = newList;
makePromptList(items);
});
}
chrome.runtime.sendMessage({ text: "new_prompt_list" });
}
);
}
function addEventsDragAndDrop(el) {
el.addEventListener('dragstart', dragStart, false);
el.addEventListener('dragenter', dragEnter, false);
el.addEventListener('dragover', dragOver, false);
el.addEventListener('dragleave', dragLeave, false);
el.addEventListener('drop', dragDrop, false);
el.addEventListener('dragend', dragEnd, false);
}