Skip to content

Commit ceaf8a0

Browse files
committed
initial commit
0 parents  commit ceaf8a0

File tree

16 files changed

+779
-0
lines changed

16 files changed

+779
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.zip
2+
*.pem
3+
*.crx

LICENSE

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright 2017 Stephen Zhang <zsrkmyn at gmail dot com>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7+
the Software, and to permit persons to whom the Software is furnished to do so,
8+
subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PROJECT_NAME=ingress-opr-helper
2+
3+
distribute:
4+
zip -r ${PROJECT_NAME}.zip ${PROJECT_NAME}

ingress-opr-helper/css/map.css

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#opr-helper-map-container,
2+
#opr-helepr-config-position-config-helper-and-css-sucks {
3+
position: relative;
4+
}
5+
6+
#opr-helper-map {
7+
height: 300px;
8+
}
9+
10+
#opr-helper-panorama {
11+
height: 300px;
12+
}
13+
14+
#opr-helper-config {
15+
position: absolute;
16+
padding: 3px 5px 3px 5px;
17+
top: 3px;
18+
left: 3px;
19+
background: #ffffff;
20+
opacity: 0.8;
21+
color: #000;
22+
font-size: 12px;
23+
font-family: sans-serif;
24+
font-weight: normal;
25+
}
26+
27+
#opr-helper-config label {
28+
margin: 0;
29+
}
30+
31+
#opr-helper-config select {
32+
display: inline;
33+
}
34+
35+
#opr-helper-config input[type="checkbox"] {
36+
margin: 0 2px 0 2px;
37+
vertical-align: middle;
38+
}
39+

ingress-opr-helper/css/popup.css

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
body {
2+
min-width: 200px;
3+
}
4+
5+
h1 {
6+
font-family: sans-serif;
7+
font-size: 20px;
8+
font-weight: bold;
9+
text-align: center;
10+
}
11+
12+
h2 {
13+
font-family: sans-serif;
14+
font-size: 15px;
15+
font-weight: bold;
16+
}
17+
18+
.menu {
19+
margin: 5px;
20+
}
21+
22+
.group {
23+
margin: 5px;
24+
}
25+
26+
.group > section {
27+
font-family: sans-serif;
28+
font-size: 13px;
29+
margin: 10px 7px 10px 7px;
30+
}
31+
32+
.group > section > input[type="checkbox"] {
33+
margin: 0 5px 0 0;
34+
vertical-align: middle;
35+
}
36+
37+
.separator {
38+
margin: 5px;
39+
border-style: solid;
40+
border-width: 1px;
41+
}

ingress-opr-helper/images/icon128.png

19.6 KB
Loading

ingress-opr-helper/manifest.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Ingress OPR Helper",
4+
"version": "0.1",
5+
"description": "A helper for ingress portal recon system",
6+
"icons": {"128": "images/icon128.png"},
7+
"permissions": ["storage"],
8+
"background": {
9+
"scripts": ["scripts/bg.js"]
10+
},
11+
"content_security_policy": "script-src 'self' https://webapi.amap.com; object-src 'self'",
12+
"web_accessible_resources": [
13+
"scripts/map.js",
14+
"scripts/utils.js",
15+
"scripts/amap.js",
16+
"scripts/baidu.js"
17+
],
18+
"browser_action": {
19+
"default_title": "",
20+
"default_icon": "images/icon128.png",
21+
"default_popup": "popup.html"
22+
},
23+
"content_scripts": [
24+
{
25+
"matches": ["https://opr.ingress.com/recon"],
26+
"js": [
27+
"scripts/main.js",
28+
"scripts/provider.js"
29+
],
30+
"css": ["css/map.css"]
31+
}
32+
]
33+
}

ingress-opr-helper/popup.html

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<html>
2+
<head>
3+
<link href="css/popup.css" rel="stylesheet">
4+
<script type="text/javascript" src="scripts/provider.js"></script>
5+
<script type="text/javascript" src="scripts/popup.js"></script>
6+
</head>
7+
<body>
8+
<header>
9+
<h1>Ingress OPR Helper</h1>
10+
</header>
11+
<div class="menu">
12+
<div class="separator"></div>
13+
<div class="group">
14+
<h2>Layers</h2>
15+
<section><input type="checkbox" id="satellite"><label>Show satellite map</label></section>
16+
<section><input type="checkbox" id="road"><label>Show road map</label></section>
17+
</div>
18+
<div class="separator"></div>
19+
<div class="group">
20+
<h2>Misc</h2>
21+
<section><input type="checkbox" id="fixchina"><label>Fix offset in China</label></section>
22+
</div>
23+
<div class="separator"></div>
24+
<div class="group">
25+
<h2>Provider</h2>
26+
<section>
27+
<label>Choose provider:</label>
28+
<select id="provider">
29+
</select>
30+
</section>
31+
</div>
32+
<div class="separator"></div>
33+
</div>
34+
<footer>
35+
<center>
36+
<a href="https://github.com/zsrkmyn/ingress-opr-helper" target="_blank">About</a>
37+
</center>
38+
</footer>
39+
</body>
40+
</html>

ingress-opr-helper/scripts/amap.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
let AMAP_URL = "https://webapi.amap.com/maps?v=1.3&key=bf3417f86991b12f5b64466f7e0498a0";
3+
let OPRHelperAMap = class extends OPRHelperMap {
4+
constructor(mapid, settings) {
5+
super(mapid);
6+
window.map = this.map = new AMap.Map(
7+
settings.mcontainer,
8+
{showIndoorMap: false}
9+
);
10+
AMap.plugin(['AMap.ToolBar', 'AMap.Scale'], () => {
11+
this.map.addControl(new AMap.ToolBar({
12+
position: 'RB',
13+
liteStyle: true,
14+
direction: false,
15+
}));
16+
this.map.addControl(new AMap.Scale());
17+
})
18+
this.ready();
19+
}
20+
21+
setZoom(z) {
22+
this.map.setZoom(z);
23+
}
24+
25+
setCenter(lng, lat) {
26+
this.map.setCenter([lng, lat]);
27+
}
28+
29+
addMarker(lng, lat, icon, offset) {
30+
var opt = {
31+
map: this.map,
32+
position: [lng, lat],
33+
}
34+
if (icon) {
35+
opt.icon = icon;
36+
if (offset)
37+
opt.offset = new AMap.Pixel(offset[0], offset[1]);
38+
}
39+
var marker = new AMap.Marker(opt);
40+
marker.show();
41+
}
42+
43+
showSatellite(flag) {
44+
if (!this.satellite)
45+
this.satellite = new AMap.TileLayer.Satellite(
46+
{map: this.map, opacity: 1});
47+
if (flag == undefined || flag)
48+
this.satellite.show();
49+
else
50+
this.satellite.hide();
51+
}
52+
53+
showRoad(flag) {
54+
if (!this.road)
55+
this.road = new AMap.TileLayer.RoadNet(
56+
{map: this.map, opacity: 1});
57+
if (flag == undefined || flag)
58+
this.road.show();
59+
else
60+
this.road.hide();
61+
}
62+
}
63+
64+
OPRHelperMapFactory.register('amap', OPRHelperAMap, () => loadScript(AMAP_URL));
65+
}

ingress-opr-helper/scripts/baidu.js

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
let BMAP_URL = "https://api.map.baidu.com/api?v=2.0&ak=gfXoaMam8YmLlPZ05kKUw7C7CLykEn3T&s=1";
3+
let OPRHelperBaiduMap = class extends OPRHelperMap {
4+
constructor(mapid, settings) {
5+
super(mapid);
6+
this.road = false;
7+
this.satellite = false;
8+
this.pcontainer = settings.pcontainer;
9+
this.map = new BMap.Map(settings.mcontainer);
10+
this.map.centerAndZoom(new BMap.Point(116, 39), 15); // fuck baidu! map won't work if centerAndZoom isn't called
11+
this.map.enableScrollWheelZoom();
12+
this.map.enableContinuousZoom();
13+
this.map.addControl(new BMap.NavigationControl({
14+
anchor: BMAP_ANCHOR_BOTTOM_RIGHT,
15+
type: BMAP_NAVIGATION_CONTROL_ZOOM,
16+
}));
17+
this.map.addControl(new BMap.ScaleControl({
18+
anchor: BMAP_ANCHOR_BOTTOM_LEFT,
19+
}));
20+
this.ready()
21+
}
22+
23+
setZoom(z) {
24+
this.map.setZoom(z);
25+
}
26+
27+
setCenter(lng, lat) {
28+
[lng, lat] = OPRHelperBaiduMap.mars2baidu(lng, lat);
29+
this.map.setCenter(new BMap.Point(lng, lat));
30+
}
31+
32+
addMarker(lng, lat, icon, offset) {
33+
[lng, lat] = OPRHelperBaiduMap.mars2baidu(lng, lat);
34+
var pos = new BMap.Point(lng, lat);
35+
var opt = {}
36+
if (icon) {
37+
opt.icon = new BMap.Icon(icon);
38+
}
39+
var marker = new BMap.Marker(pos, opt);
40+
this.map.addOverlay(marker);
41+
}
42+
43+
showSatellite(flag) {
44+
var mapType;
45+
if (flag === undefined || flag) {
46+
this.satellite = true;
47+
if (this.road)
48+
mapType = BMAP_HYBRID_MAP;
49+
else
50+
mapType = BMAP_SATELLITE_MAP;
51+
} else {
52+
this.satellite = false;
53+
mapType = BMAP_NORMAL_MAP;
54+
}
55+
this.map.setMapType(mapType);
56+
}
57+
58+
showRoad(flag) {
59+
var mapType = BMAP_NORMAL_MAP;
60+
if (flag === undefined || flag) {
61+
this.road = true;
62+
if (this.satellite)
63+
mapType = BMAP_HYBRID_MAP;
64+
} else {
65+
this.road= false;
66+
if (this.satellite)
67+
mapType = BMAP_SATELLITE_MAP;
68+
}
69+
this.map.setMapType(mapType);
70+
}
71+
72+
showPanorama(lng, lat) {
73+
[lng, lat] = OPRHelperBaiduMap.mars2baidu(lng, lat);
74+
OPRHelperBaiduMap.getPanoramaInfo(lng, lat)
75+
.then((data) => {
76+
if (!this.panorama) {
77+
this.panorama =
78+
new BMap.Panorama(this.pcontainer, {
79+
navigationControl: true,
80+
linksControl: true,
81+
});
82+
}
83+
var pos = new BMap.Point(lng, lat);
84+
this.panorama.setPosition(pos);
85+
this.panorama.addOverlay(
86+
new BMap.PanoramaLabel(
87+
'Portal Here',
88+
{position: pos}
89+
)
90+
);
91+
this.panorama.show();
92+
});
93+
}
94+
95+
static getPanoramaInfo(lng, lat) {
96+
return new Promise((resolve, reject) => {
97+
var service = new BMap.PanoramaService();
98+
service.getPanoramaByLocation(new BMap.Point(lng, lat),
99+
(data) => {
100+
if (data == null)
101+
reject();
102+
else
103+
resolve(data);
104+
});
105+
});
106+
}
107+
108+
// stolen from http://blog.csdn.net/coolypf/article/details/8569813
109+
static mars2baidu(lng, lat) {
110+
const xpi = 3.14159265358979324 * 3000.0 / 180.0;
111+
var z = Math.sqrt(lng * lng + lat * lat) + 2e-5 * Math.sin(lat * xpi);
112+
var theta = Math.atan2(lat, lng) + 3e-6 * Math.cos(lng * xpi);
113+
return [
114+
z * Math.cos(theta) + 0.0065, // lng
115+
z * Math.sin(theta) + 0.006 // lat
116+
];
117+
}
118+
}
119+
120+
OPRHelperMapFactory.register('baidu', OPRHelperBaiduMap, () => {
121+
return new Promise((resolve, reject) => {
122+
BMAP_URL += '&callback=window.onbmapload_';
123+
window.onbmapload_ = () => {
124+
delete window.onbmapload_;
125+
setTimeout(resolve, 2000);
126+
}
127+
loadScript(BMAP_URL);
128+
});
129+
});
130+
}

0 commit comments

Comments
 (0)