-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathWeiboImgUploader.js
79 lines (71 loc) · 1.84 KB
/
WeiboImgUploader.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
72
73
74
75
76
77
78
79
/*
Weibo Img Uploader
通过微博图片链接查找发图人微博
by Neurogram
*/
var url = $context.safari ? $context.safari.items.location.href : $context.link || $clipboard.text
var urlTest = /sinaimg.cn/.test(url)
if (urlTest == false) {
$ui.alert("微博图片地址错误")
$app.close()
}
function decodeBase62(number) {
var alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
var out = 0
var len = number.length - 1
for (var t = 0; t <= len; t++) {
out = out + alphabet.indexOf(number.substr(t, 1)) * Math.pow(62, len - t)
}
return out
}
function decode16Unit(number) {
return parseInt(number, 16)
}
function decode(number) {
if (number.startsWith('00')) {
return decodeBase62(number)
} else {
return decode16Unit(number)
}
}
function findNumber(url) {
var lastIndexOfSlash = url.lastIndexOf('/')
var number = url.substr(lastIndexOfSlash + 1, 8)
return number
}
function findUid(url) {
var number = findNumber(url)
var uid = decode(number)
return uid
}
function constructHomePageUrl(uid) {
var prefixUrl = 'http://weibo.com/u/'
return prefixUrl + uid
}
function main(url) {
var uid = findUid(url)
var homePageUrl = constructHomePageUrl(uid)
console.log(homePageUrl)
return homePageUrl
}
$ui.alert({
title: "此图片指向的实际微博地址为",
message: main(url),
actions: [{
title: "复制",
handler: function() {
$clipboard.text = main(url)
$app.close()
}
},
{
title: "预览",
handler: function() {
$ui.preview({
title: "微博",
url: main(url)
})
}
}
]
})