-
Notifications
You must be signed in to change notification settings - Fork 1
/
content2.js
42 lines (39 loc) · 968 Bytes
/
content2.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
// Runs on google maps
var port = chrome.runtime.connect({
name: "gmaps"
});
var prevUrl = document.location.href;
var prevTitle = document.title.toString();
var title = document.querySelector("title");
var observer = new MutationObserver(function(e) {
e.some(function(e) {
var t = e.target.textContent.toString();
t = t.replace(/^\([0-9]{0,}\)\s/, "").replace(/ +/g, " ");
if (t != prevTitle) {
prevTitle = t;
fetchURL();
return true;
}
})
});
function sendData(e) {
if (e != prevUrl) {
prevUrl = document.location.href;
port.postMessage({
action: "MapsURL",
url: e
});
}
}
async function fetchURL() {
await sleep(2000);
sendData(document.location.href);
}
function sleep(e) {
return new Promise(t => setTimeout(t, e))
}
observer.observe(title, {
subtree: false,
characterData: true,
childList: true
});