-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhostname.js
32 lines (27 loc) · 1012 Bytes
/
hostname.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
const title = document.querySelector('title');
let observer = new MutationObserver(function(mutations) {
changeTitle();
});
const config = { subtree: true, characterData: true, childList: true };
let protocolEnabled, pathEnabled, protocol, path;
let getting = browser.storage.local.get();
getting.then(setExtraOptions, e => console.error(error));
observer.observe(title, config);
window.addEventListener ("load", changeTitle, false);
function setExtraOptions(item) {
protocolEnabled = item.protocol;
pathEnabled = item.path;
}
function prepHostname() {
protocol = (protocolEnabled ? `${window.location.protocol}//` : "");
path = (pathEnabled ? window.location.pathname : "");
return ` - ${protocol}${window.location.hostname}${path}`;
}
function changeTitle() {
let hostname = prepHostname();
if (!document.title.includes(hostname)) {
observer.disconnect();
document.title = document.title + hostname;
observer.observe(title, config);
}
}