-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_script.js
102 lines (83 loc) · 2.63 KB
/
content_script.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
function content_helper() {
var lat, lon, zoom;
var parseLink = function (linkParent) {
var fChild = linkParent.firstElementChild;
if(!fChild) {
return;
}
var olLink = fChild.href;
var q_str = olLink.split('?')[1];
q_str.split('&').forEach(function (value) {
var pair = value.split('=');
if(pair[0] === 'zoom') {
zoom = pair[1];
}
else if(pair[0] === 'lat') {
lat = pair[1];
}
else if(pair[0] === 'lon') {
lon = pair[1];
}
});
};
/*
* Loadmap: getting coords from GoogleAPI logo
*/
var gmEl = document.getElementsByClassName("gm-style");
var waze = document.getElementsByClassName("wm-permalink-control");
var openLayersEl = document.getElementsByClassName("olControlPermalink");
var navitelPermalink = document.getElementById("permalink");
if(gmEl.length && gmEl[0].children.length > 1 && gmEl[0].children[2].children.length > 0) {
var gmLink = gmEl[0].children[2].children[0];
var gmUrl = gmLink.href;
var q_str = gmUrl.split('?')[1];
q_str.split('&').forEach(function (value) {
var pair = value.split('=');
if(pair[0] === 'z') {
zoom = pair[1];
}
else if(pair[0] === 'll') {
var gcoord = pair[1].split(',');
lat = gcoord[0];
lon = gcoord[1];
}
});
}
// Chepetsk OpenLayers permalink
else if(openLayersEl.length) {
parseLink(openLayersEl[0]);
}
// Navitel
else if(navitelPermalink) {
parseLink(navitelPermalink);
}
// waze
else if(waze.length) {
parseLink(waze[0]);
}
// Bing: getting coords from LocalStorage
else {
lat = localStorage.getItem("centerLatitude");
lon = localStorage.getItem("centerLongitude");
zoom = localStorage.getItem("zoom");
}
return {
lat: lat,
lon: lon,
zoom: zoom
};
}
chrome.runtime.sendMessage({
action: "coords",
coords: content_helper()
});
// добавляем перекрестие на openstreetmap.org
// setTimeout(function(){
// var div=document.createElement("div");
// div.classList.add('icross');
// div.classList.add('icross_osm');
// div.innerHTML += '<img src="chrome-extension://plagppklljkoeblkoknfpmljklplpdol/img/cross.svg" />';
// // OSM
// document.getElementById('content').appendChild(div);
// // div.innerText="test123";
// }, 1000);