-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
48 lines (45 loc) · 1.54 KB
/
script.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
let Data = {"Title": "", "URL": ""}
chrome.tabs.query({
active: true,
currentWindow: true,
},tabs=>{
const tab = tabs[0]
Data.Title = tab.title;
Data.URL = tab.url;
console.log(`Title: ${Data.Title}`);
console.log(`URL: ${Data.URL}`);
});
window.addEventListener('load',()=>{
const txtBox = document.querySelector('input');
document.querySelector('button.ttl').addEventListener('click',()=>{
txtBox.value = Data.Title;
});
document.querySelector('button.url').addEventListener('click',()=>{
txtBox.value = Data.URL;
});
document.querySelector('button.bmark').addEventListener('click',()=>{
txtBox.value = `[${Data.Title}](${Data.URL})`;
});
const cb = new ClipboardJS('button.copy');
const msgContainer = document.querySelector('div.msg');
const msgSuccess = document.querySelector('p.copied');
const msgFailed = document.querySelector('p.failed');
cb.on("success", function(e){
console.log('Copied Successfully.', e);
msgContainer.style.display = "block";
msgSuccess.style.display = "block";
setTimeout(()=>{
msgSuccess.style.display = "none";
msgContainer.style.display = "none";
},3000);
});
cb.on("error", function(e) {
console.error('Failed to Copy.', e);
msgContainer.style.display = "block";
msgFailed.style.display = "block";
setTimeout(()=>{
msgFailed.style.display = "none";
msgContainer.style.display = "none";
},3000);
});
})