-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
49 lines (49 loc) · 1.86 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
49
browser.tabs.query({"active":true}, (tabs) => {
const url = tabs[0].url
document.getElementById('link').innerText = url
new QRCode(document.getElementById("qrcode"), {
text: url,
width: 250,
height: 250,
colorDark : "#1d4999",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
})
document.getElementById('short').addEventListener('click', () => {
const btn = document.getElementById('short')
btn.innerText = `Loading...`
btn.disabled = true
fetch(`https://tinyurl-rest-wrapper.herokuapp.com/shorten?url=${encodeURIComponent(url)}`)
.then(res => res.json())
.then(json => {
document.getElementById('link').innerText = json.tinyurl
document.getElementById('qrcode').innerHTML = ''
new QRCode(document.getElementById("qrcode"), {
text: json.tinyurl,
width: 250,
height: 250,
colorDark : "#1d4999",
colorLight : "#ffffff",
correctLevel : QRCode.CorrectLevel.H
})
btn.innerText = `Shorten Link`
btn.disabled = false
})
.catch(() => {
btn.innerText = `Error. Retry?`
btn.disabled = false
})
})
document.getElementById('expand').addEventListener('click', () => {
const new_url = document.getElementById('link').innerText
window.linkshare = new_url
let win = window.open('index.html', '_blank')
win.focus()
})
document.getElementById('link-box').addEventListener('click', () => {
const url_copy = document.getElementById('link').innerText
navigator.clipboard.writeText(url_copy)
.then()
.catch()
})
})