-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathXQRcode.js
163 lines (153 loc) · 5.26 KB
/
XQRcode.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
解析二维码,自动打开到相应的 App 并保存到剪贴板
1.通过 share extension 运行,避免保存图片 或 直接相册运行
2.主程序内直接运行,自动解析剪贴板图片 或 开启扫描
3.无法识别时点击取消打开微信扫描
支持的 App:
支付宝、淘宝、口碑、京东、Safari、迅雷、磁力、OFO扫车码
微博、微信;需要跳转到 App 内再次扫描
可添加至 Launch Center Pro 等应用快速启动:jsbox://run?name=XQRcode
欢迎提供更多相关 url scheme
问题:QQ 扫一扫 url scheme 未知,因此 QQ 登录或支付只能打开 QQ 而无法自动打开扫一扫
作者联系:https://t.me/axel_burks
*/
var version = 0.8
var autoUpdate = $context.image ? false : true
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
if (autoUpdate == true && Object.size($context.query) > 0) {
autoUpdate = false
}
var qr = $context.image || ($clipboard.image ? $clipboard.image.image : null)
if (qr == null) {
$qrcode.scan({
handler(string) {
showResult(string, false)
},
cancelled() {
$app.openURL("weixin://scanqrcode")
}
})
} else {
var text = $qrcode.decode(qr)
if (text) {
showResult(text, true)
} else {
showWarning("run through Share Extension", true)
}
}
if (autoUpdate == true) {
$thread.background({
handler: function() {
checkVersion()
}
})
}
function isContains(str, regxstr) {
return new RegExp(regxstr).test(str)
}
function showResult(text, runningExt) {
//$clipboard.text = text
//$clipboard.save(text)
$clipboard.set({
"type": "public.plain-text",
"value": text
})
var scheme = text.match(/^(?!ssr?:\/\/)\w+:\/\/[^\s]*/i)
if (scheme) {
var url = text.match(/^(https?|weixin|wxp):\/\/[^\s]+/i)[0]
if (url) {
if (isContains(url,/weibo\.cn/i)) {
scheme = "weibo://qrcode"
} else if (isContains(url,/(weixin|wxp):\/\/|weixin\.qq|tenpay\.com/i)) {
scheme = "weixin://scanqrcode"
} else if (isContains(url,/(wsk|txz)\.qq\.com/i)) {
scheme = "mqq://"
} else if (isContains(url,/zhihu\.com.*question/i)) {
scheme = url.toString().replace(/https?/i,"zhihu")
} else if (isContains(url,/ofo\.so\/plate/i)) {
scheme = "ofoapp://useBike?carno=" + url
} else if (isContains(url,/taobao\.com|tb\.cn|tmall\.com|qazdsa\.com/i)) {
scheme = url.toString().replace(/https?/i,"taobao")
} else if (isContains(url,/qr\.shouqianba\.com|qr\.alipay\.com.*PAI_LOGIN/i)) {
scheme = "alipays://platformapi/startapp?saId=10000007"
} else if (isContains(url,/(qr|d)\.alipay\.com\/(kox|sux)/i)) {
scheme = "koubei://platformapi/startapp?saId=10000007&qrcode=" + url
} else if (isContains(url,/(qr|d)\.alipay\.com|spay3\.swiftpass\.cn|tlt\.allinpay\.com|v\.ubox\.cn\/qr|i\.55tuan\.com\/rq/i)) {
scheme = "alipays://platformapi/startapp?saId=10000007&qrcode=" + url
} else if (isContains(url,/item\.(m\.)?jd\.com/i)) {
var skuId = url.toString().match(/item.*?jd\.com\/.*?(\d+)(?=\.html)/i)[1]
scheme = "openapp.jdmobile://virtual?params=" + encodeURIComponent("{\"sourceValue\":\"0_productDetail_97\",\"des\":\"productDetail\",\"skuId\":\"" + skuId + "\",\"category\":\"jump\",\"sourceType\":\"PCUBE_CHANNEL\"}")
} else if (isContains(url,/qr\.m\.jd\.com/i)) {
var key = url.toString().match(/qr\.m\.jd\.com\/p\?k=([^\s]+)/i)[1]
scheme = "openApp.jdMobile://virtual?params=" + encodeURIComponent("{\"category\":\"jump\",\"des\":\"ScanLogin\",\"key\":\"" + key + "\"}")
}
}
$app.openURL(scheme)
if (runningExt)
$context.close()
} else if (text.match(/^magnet:[^\s]+/i)) {
var magnet_link = text.match(/^magnet:[^\s]+/i)[0]
$app.openURL("thunder://" + $text.base64Encode(magnet_link))
if (runningExt)
$context.close()
} else {
$ui.alert({
title: "Clipboard Saved",
message: text,
actions: [{
title: "OK",
style: "Cancel",
handler: function() {
if (runningExt)
$context.close()
$system.home()
}
}]
})
}
}
function showWarning(text, runningExt) {
$ui.alert({
title: "QR Code Error",
message: "The image you " + text + " should be a QR Code.\n\nPlease try again.",
actions: [{
title: "OK",
style: "Cancel",
handler: function() {
if (runningExt)
$context.close()
}
}]
})
}
function checkVersion() {
$http.get({
url: "https://raw.githubusercontent.com/axelburks/JSBox/master/updateInfo",
handler: function(resp) {
var afterVersion = resp.data["XQRcode"]["version"];
var msg = resp.data["XQRcode"]["msg"];
if (afterVersion > version) {
$ui.alert({
title: "检测到新的版本!V" + afterVersion,
message: "更新说明:\n" + msg,
actions: [{
title: "更新",
handler: function() {
var url = "jsbox://install?url=https://raw.githubusercontent.com/axelburks/JSBox/master/XQRcode.js&name=XQRcode&icon=icon_102.png";
$app.openURL(encodeURI(url));
$app.close()
}
}, {
title: "取消"
}]
})
}
}
})
}