-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
51 lines (45 loc) · 1.76 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
/**
* ClipCopy function.
* @textVal : str
* @return : (true|false)
*/
function copyTextToClipboard(textVal){
var copyFrom = document.createElement('textarea');
copyFrom.textContent = textVal;
var bodyElm = document.getElementsByTagName('body')[0];
bodyElm.appendChild(copyFrom);
copyFrom.select();
var returnVal = document.execCommand('copy');
bodyElm.removeChild(copyFrom);
return returnVal;
}
chrome.tabs.getSelected(null, function(tab){
document.querySelector('body').style.width = (tab.width*0.45) + 'px';
document.querySelector('body').style.minHeight = (tab.height*0.2) + 'px';
});
chrome.tabs.getSelected(null, function(tab){
chrome.tabs.sendMessage(tab.id, {title:''}, function(response) {
const url = tab.url;
const text = response.text;
const count = response.count;
document.querySelector('#inputBefore').innerHTML = text;
document.querySelector('.input-before-count').innerHTML = count;
document.querySelector('form').inputAfter.value = encodeURI(text);
});
});
let elemBtnEncode = document.querySelector('.btn-encode');
elemBtnEncode.addEventListener('click', (e) => {
let text = document.querySelector('form').inputBefore.value;
let count = document.querySelector('form').inputBefore.value.length;
if(count == 0){
alert(' Text has not been entered. ');
}
document.querySelector('form').inputBefore.value = text;
document.querySelector('.input-before-count').innerHTML = count;
document.querySelector('form').inputAfter.value = encodeURI(text);
});
const elemBtnCopy = document.querySelector('.btn-copy');
elemBtnCopy.addEventListener('click', (e) => {
copyTextToClipboard(document.querySelector('form').inputAfter.value);
alert(' Copy completion. ');
});