-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontentScriptGoogle.js
89 lines (77 loc) · 2.64 KB
/
contentScriptGoogle.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
let isEnabled;
chrome.storage.local.get("enabled", (result) => {
isEnabled = result.enabled !== undefined ? result.enabled : true;
runScripts(isEnabled);
});
chrome.storage.onChanged.addListener((changes) => {
changes.enabled
? runScripts(changes.enabled.newValue)
: runScripts(isEnabled);
});
function runScripts(extensionEnabled) {
const dataAttributesToRemove = {
books: ['[data-attrid="kc:/book/book:reviews"]'],
games: ['[data-attrid="kc:/cvg/computer_videogame:reviews"]'],
google_users: [
'[data-attrid="kc:/ugc:top_thumbs_up"]',
'[data-attrid="kc:/ugc:thumbs_up"]',
'[data-attrid="kc:/ugc:user_reviews"]',
'[data-starbar-class="rating-list"]',
],
movies: [
'[data-attrid="kc:/film/film:reviews"]',
'[data-attrid="kc:/film/film:critic_reviews"]',
'[itemprop="starRating"]',
'[itemprop="tomatoMeter"]',
'[data-g-id="reviews"]',
'[data-sncf="3"]',
'[data-md="17"]'
],
tv: ['[data-attrid="kc:/tv/tv_program:reviews"]'],
aria: [
'[aria-label^="Rated"]',
'[aria-label^="Scored"]'
]
};
_removeItemsFromPage(
dataAttributesToRemove,
extensionEnabled
);
if (window.location.host === "www.google.com") {
// Get the star ratings for the individual search results.
const titleStars = document.getElementsByTagName("g-review-stars");
// Hide the star ratings.
for (let title of titleStars) {
title.parentElement.style.display = extensionEnabled
? "none"
: "block";
}
}
}
_removeItemsFromPage = (
dataAttributesToRemove,
extensionEnabled
) => {
Object.keys(dataAttributesToRemove).forEach((mediaCategory) => {
dataAttributesToRemove[mediaCategory].forEach((domId) => {
let elems = document.querySelectorAll(domId);
if (elems.length) {
elems.forEach((elem) => {
if (mediaCategory == 'aria') {
elem = elem.closest('div');
}
elem.style.display = extensionEnabled ? 'none' : 'block';
})
}
});
});
_manageReviewResults(extensionEnabled);
};
_manageReviewResults = (extensionEnabled) => {
let cites = document.getElementsByTagName("cite");
for (let item of cites) {
if (item.innerHTML.toLowerCase().match(/(review)/g)) {
item.closest(".g").style.display = extensionEnabled ? "none" : "block";
}
}
};