This repository has been archived by the owner on Feb 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathemojis.js
71 lines (61 loc) · 1.87 KB
/
emojis.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
var forEach = Array.prototype.forEach;
var $status;
var counter = 0;
function handleClick(event) {
var more = false;
if(event.shiftKey) {
more = true;
}
if(counter > 0) {
$status.innerHTML += '<img src="' + event.target.src + '" style="background-color: transparent"/>'
} else {
$status.innerHTML = '<img src="' + event.target.src + '" style="background-color: transparent"/>'
}
counter++;
if(!more) {
copyStatus();
} else {
showButtons();
}
}
function copyStatus() {
var range = document.createRange();
range.selectNodeContents($status);
window.getSelection().addRange(range);
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
} catch(err) {
}
if(window.removeRange) {
window.getSelection().removeRange(range);
} else {
window.getSelection().removeAllRanges();
}
window.setTimeout(function(){
window.close();
}, 500);
}
function showButtons() {
document.querySelector('div.buttons').classList.add('visible');
}
function hideButtons() {
document.querySelector('div.buttons').classList.remove('visible');
}
function clear() {
$status.removeChild($status.childNodes[$status.childNodes.length-1]);
if(!$status.hasChildNodes()) {
$status.innerHTML = 'Clik an icon to copy it.';
hideButtons();
counter = 0;
}
}
document.addEventListener('DOMContentLoaded', function(){
$status = document.getElementById('status');
var images = document.getElementsByTagName('img');
forEach.call(images, function( image ){
image.addEventListener('click', handleClick);
});
document.getElementById('clear').addEventListener('click', clear);
document.getElementById('copy').addEventListener('click', copyStatus);
});