-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
68 lines (60 loc) · 2.21 KB
/
background.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
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.local.set({ hideOpponent: false });
});
chrome.storage.onChanged.addListener((changes, area) => {
if (area === 'local' && changes.hideOpponent) {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs.length > 0) {
const tab = tabs[0];
if (tab.url.includes('lichess.org')) {
chrome.scripting.executeScript({
target: { tabId: tab.id },
func: changes.hideOpponent.newValue ? hideOpponent : showOpponent
});
}
}
});
}
});
function hideOpponent() {
const playerinfo = document.querySelectorAll('.ruser-top');
if (playerinfo.length) {
const userLink = playerinfo[0].querySelector(".user-link");
const rating = playerinfo[0].querySelector("rating");
if (userLink) userLink.style.visibility = "hidden";
if (rating) rating.style.visibility = "hidden";
}
const gameMetaPlayers = document.querySelectorAll('.game__meta__players');
if (gameMetaPlayers.length) {
const players = gameMetaPlayers[0].querySelectorAll(".user-link");
players.forEach(player => {
player.style.visibility = 'hidden';
});
}
const crosstableUsers = document.querySelectorAll('.crosstable__users');
if (crosstableUsers.length) {
const players = crosstableUsers[0].querySelectorAll(".user-link");
players[1].style.visibility = 'hidden';
}
}
function showOpponent() {
const playerinfo = document.querySelectorAll('.ruser-top');
if (playerinfo.length) {
const userLink = playerinfo[0].querySelector(".user-link");
const rating = playerinfo[0].querySelector("rating");
if (userLink) userLink.style.visibility = "";
if (rating) rating.style.visibility = "";
}
const gameMetaPlayers = document.querySelectorAll('.game__meta__players');
if (gameMetaPlayers.length) {
const players = gameMetaPlayers[0].querySelectorAll(".user-link");
players.forEach(player => {
player.style.visibility = '';
});
}
const crosstableUsers = document.querySelectorAll('.crosstable__users');
if (crosstableUsers.length) {
const players = crosstableUsers[0].querySelectorAll(".user-link");
players[1].style.visibility = '';
}
}