Skip to content

Commit 2de9330

Browse files
authored
Create index.js
1 parent 4df6189 commit 2de9330

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

location/index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* 自动定位脚本
3+
* @author: Peng-YM
4+
* 更新地址:https://raw.githubusercontent.com/Peng-YM/QuanX/master/Tools/Location/locate.js
5+
* 配置方法:
6+
* 根据平台添加如下配置
7+
* 1. Quantumult X
8+
* [MITM]
9+
* hostname=weather-data.apple.com
10+
* [Rewrite]
11+
* https://weather-data.apple.com url script-request-header https://raw.githubusercontent.com/Peng-YM/QuanX/master/Tools/Location/locate.js
12+
*
13+
* 2. Loon
14+
* [MITM]
15+
* hostname=weather-data.apple.com
16+
* [Script]
17+
* http-request https://weather-data.apple.com, script-path=https://raw.githubusercontent.com/Peng-YM/QuanX/master/Tools/Location/locate.js, require-body=false
18+
*
19+
* 3. Surge
20+
* [MITM]
21+
* hostname=weather-data.apple.com
22+
* [Script]
23+
* type=http-request, pattern=https://weather-data.apple.com, script-path=https://raw.githubusercontent.com/Peng-YM/QuanX/master/Tools/Location/locate.js, require-body=false
24+
*
25+
* 即可定时获取当前位置,注意需要安装自带的天气应用。此重写不要禁用。
26+
* 在脚本中即可通过 "latitude" 和 ”longitude" 这两个字段引用当前的经纬度了。
27+
*/
28+
29+
const url = $request.url;
30+
const res = url.match(/CN\/(.*)\/(.*)\?/);
31+
const latitude = res[1];
32+
const longitude = res[2];
33+
console.log(`当前位置:经度${latitude},纬度${longitude}`);
34+
35+
// write data
36+
if (typeof $prefs !== 'undefined'){
37+
// QX
38+
$prefs.setValueForKey(latitude, "latitude");
39+
$prefs.setValueForKey(longitude, "longitude");
40+
}else{
41+
// Loon & Surge
42+
$persistentStore.write(latitude, "latitude");
43+
$persistentStore.write(longitude, "longitude");
44+
}

0 commit comments

Comments
 (0)