-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
63 lines (52 loc) · 2.23 KB
/
main.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
//Etsy BLM Integration
function post(url, data) {
return fetch(url, {method: "POST",headers: {'Content-Type': 'application/json'}, body: JSON.stringify(data)});
}
function addBadges(x, type, floatRight=true){
text= $(x).text();
$(x).addClass("stay-local-badged");
if(type=="BLM")
post("https://us-central1-local-businesss.cloudfunctions.net/checkBusiness",{url: text}).then((o) => o.json()).then(function(list){
if (list.exists){
if (list.categories.includes("BLM")){
$(x).after('<img src="'+chrome.runtime.getURL("0.png")+'" style="width:2em;height:2em;vertical-align:middle;'+(floatRight ? "float:right" : '')+'">');
}
}
});
else if (type=="local"){
post("https://us-central1-local-businesss.cloudfunctions.net/checkLocalBusiness",{name: text}).then(bad => bad.json()).then(function(bad){
if (bad){
$(x).after('<img src="'+chrome.runtime.getURL("1.png")+'" style="width:2em;height:2em;vertical-align:middle;'+(floatRight ? "float:right" : '')+'">');
}
});
}
}
url = window.location.href;
if (url.match(/https\:\/\/www\.etsy\.com\/.*/)){
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
$( "p:not(.stay-local-badged).text-gray-lighter.text-body-smaller.display-inline-block").each(function(index){addBadges(this,"BLM")});
$(".shop-name-and-title-container>h1:not(.stay-local-badged), div.show-xs.show-sm.show-md.col-xs-12.mt-xs-1>h1:not(.stay-local-badged),text-center.mb-xs-1").each(function(index,){addBadges(this,"BLM",floatRight=false)});
}
)});
var observerConfig = {
attributes: true,
childList: true,
characterData: true
};
var targetNode = document.body;
observer.observe(targetNode, observerConfig);
}else if (url.match(/https\:\/\/www\.google\.com\/search.*/)){
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
$(".dbg0pd>div:not(.stay-local-badged),.dbg0pd>span:not(.stay-local-badged)").each(function(index){addBadges(this,"local")});
}
)});
var observerConfig = {
attributes: true,
childList: true,
characterData: true
};
var targetNode = document.body;
observer.observe(targetNode, observerConfig);
}