-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent_script.js
More file actions
26 lines (21 loc) · 1.24 KB
/
content_script.js
File metadata and controls
26 lines (21 loc) · 1.24 KB
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
var title = document.title;//title of the website
var hostname = window.location.hostname;//hostname of the website
var url = window.location.href;//url of the website
function setCharAt(str, index, chr) {//replace char of string at the index argument value with char from the argument
if (index > str.length - 1) return str;
return str.substr(0, index) + chr + str.substr(index + 1);
}
function checkUrl() {//check if the url has changed
if(url != window.location.href && title != document.title){
url = window.location.href;
title = document.title;
browser.runtime.sendMessage({"msg": "screenshot", "url": url, "title": title, "hostname": hostname}); //send message to take a screenshot to the background_script
}
}
if (hostname.charAt(0) == "w" && hostname.charAt(1) == "w" && hostname.charAt(2) == "w" && hostname.charAt(3) == ".") {//remove "www." from hostnames
for (i = 0; i < 4; i++) {//iterate the first four digits -> "www."
hostname = setCharAt(hostname, 0, "");
}
}
browser.runtime.sendMessage({"msg": "screenshot", "url": url, "title": title, "hostname": hostname}); //send message to take a screenshot to the background_script
setInterval(checkUrl, 1000);//check every second if the url has changed