-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathShorten.js
54 lines (52 loc) · 1.35 KB
/
Shorten.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
let content = $context.link || $context.text || $app.env == $env.safari ? $context.safari.items.baseURI : $clipboard.text
ShortenLinks(content)
async function ShortenLinks(str_url) {
let selectedLink = null
let links = $detector.link(str_url)
if (links.length >= 1) {
if (links.length == 1) {
selectedLink = links[0];
} else {
selectedLink = await $ui.menu({ items: links })
selectedLink = selectedLink.title
}
if (selectedLink) {
$http.shorten({
url: selectedLink,
handler: function(url) {
if (url) {
$clipboard.set({
"type": "public.plain-text",
"value": url
})
$ui.toast("Copid Success!", 1)
} else {
$clipboard.set({
"type": "public.plain-text",
"value": "Original Content:" + selectedLink
})
$ui.error("Shorten Failed!", 1)
}
delayClose(0.8)
}
})
} else {
delayClose(0.8)
}
} else {
$ui.error("Please Input Correct URL!", 1)
delayClose(0.8)
}
}
function delayClose(time) {
$thread.main({
delay: time,
handler: function () {
if ($app.env == $env.action || $app.env == $env.safari) {
$context.close()
} else if ($app.env != $env.app) {
$app.close()
}
}
})
}