-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
85 lines (73 loc) · 2.58 KB
/
content.js
File metadata and controls
85 lines (73 loc) · 2.58 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
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
//after html loads, activates this: so no type error: cannot read property "addeventlistener" of null occurs.
window.onload = function () {
//connect to html button
const specificurl = document.getElementById("wSpecificSubmit");
const domainurl = document.getElementById("wDomainSubmit");
const currenturl = document.getElementById("tabSubmit");
//event listeners
if (currenturl) {
currenturl.addEventListener("click", function () {
console.log("content.js -> CurrentTab Clicked");
getCurrentUrl();
});
}
if (specificurl) {
specificurl.addEventListener("click", function () {
console.log("content.js -> Specific Clicked");
getUrl(true); //true for specific
});
}
if (domainurl) {
domainurl.addEventListener("click", function () {
console.log("content.js -> Domain Clicked");
getUrl(false); //false for domain
});
}
};
function getCurrentUrl() {
}
//fetches url
function getUrl(boolean) {
console.log("fetched url sucessfully");
var urlString = document.getElementById("wSpec").value;
console.log(urlString);
//document.getElementById("desc").innerHTML = "asdf";
if (boolean) {
blacklistSpecific(urlString);
} else {
blacklistDomain(urlString);
}
}
function blacklistSpecific(urlString) {
//arr.push("*://*.facebook.com/*"); won't work
//using regex to check if url is a proper match
//Tried trycatch on chrome's pattern match but it's not possible on asyncronous.
//Tried exception handling via chrome.runtime.lastError but didnt seem to work:
//https://stackoverflow.com/questions/14517184/exception-handling-in-chrome-extensions
// var regExpression =
// "https?://(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)";
// var regex = new RegExp(regExpression);
// if (urlString.match(regex)) {
chrome.runtime.sendMessage({ link1: urlString }, function (response) {
console.log(response.reply);
});
console.log("sent to background.js");
// } else {
// alert("Incorrect URL pattern!");
// }
//document.getElementById("desc").innerHTML = "helllro";
}
function blacklistDomain(urlString) {
// var regExpression =
// "[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)";
// var regex = new RegExp(regExpression);
// if (urlString.match(regex)) {
reformatString = "*://*." + urlString + "/*";
chrome.runtime.sendMessage({ link1: reformatString }, function (response) {
console.log(response.reply);
});
console.log("sent to background.js");
// } else {
// alert("Incorrect URL pattern!");
// }
}