-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
153 lines (134 loc) · 4.94 KB
/
Copy pathpopup.js
File metadata and controls
153 lines (134 loc) · 4.94 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Common chips that programmers/students might want to hide
const commonChips = [
"Music", "Gaming", "Live", "Recently uploaded", "Watched",
"New to you", "Comedy", "Entertainment", "Sports", "Fashion",
"Beauty", "Travel", "Food", "Pranks", "Vlogs"
];
let filterMode = 'hide'; // 'hide' or 'showOnly'
let hiddenChips = [];
let blockedKeywords = [];
let whitelistKeywords = [];
document.addEventListener('DOMContentLoaded', () => {
const presetChipsContainer = document.getElementById('presetChips');
const customChipInput = document.getElementById('customChipInput');
const customChipsList = document.getElementById('customChipsList');
const blockKeywordsInput = document.getElementById('blockKeywords');
const whitelistKeywordsInput = document.getElementById('whitelistKeywords');
const saveBtn = document.getElementById('saveBtn');
const statusDiv = document.getElementById('status');
const modeHideBtn = document.getElementById('modeHide');
const modeShowBtn = document.getElementById('modeShow');
const modeHint = document.getElementById('modeHint');
// Create preset chip buttons
commonChips.forEach(chip => {
const chipBtn = document.createElement('div');
chipBtn.className = 'preset-chip';
chipBtn.textContent = chip;
chipBtn.dataset.chip = chip;
chipBtn.addEventListener('click', () => togglePresetChip(chip, chipBtn));
presetChipsContainer.appendChild(chipBtn);
});
// Mode selector
modeHideBtn.addEventListener('click', () => {
filterMode = 'hide';
modeHideBtn.classList.add('active');
modeShowBtn.classList.remove('active');
modeHint.textContent = 'Hide the chips you select below';
});
modeShowBtn.addEventListener('click', () => {
filterMode = 'showOnly';
modeShowBtn.classList.add('active');
modeHideBtn.classList.remove('active');
modeHint.textContent = 'Show ONLY the chips you select below (hide everything else)';
});
// Add custom chip on Enter key
customChipInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter' && customChipInput.value.trim()) {
addCustomChip(customChipInput.value.trim());
customChipInput.value = '';
}
});
// Load saved settings
chrome.storage.sync.get(['filterMode', 'hiddenChips', 'blockedKeywords', 'whitelistKeywords'], (result) => {
filterMode = result.filterMode || 'hide';
hiddenChips = result.hiddenChips || [];
blockedKeywords = result.blockedKeywords || [];
whitelistKeywords = result.whitelistKeywords || [];
// Set mode
if (filterMode === 'showOnly') {
modeShowBtn.classList.add('active');
modeHideBtn.classList.remove('active');
modeHint.textContent = 'Show ONLY the chips you select below (hide everything else)';
}
// Update preset chips UI
hiddenChips.forEach(chip => {
const presetBtn = document.querySelector(`.preset-chip[data-chip="${chip}"]`);
if (presetBtn) {
presetBtn.classList.add('added');
}
});
// Render custom chips
renderCustomChips();
// Fill inputs
blockKeywordsInput.value = blockedKeywords.join(', ');
whitelistKeywordsInput.value = whitelistKeywords.join(', ');
});
// Save button
saveBtn.addEventListener('click', () => {
chrome.storage.sync.set({
filterMode: filterMode,
hiddenChips: hiddenChips,
blockedKeywords: blockedKeywords,
whitelistKeywords: whitelistKeywords
}, () => {
statusDiv.style.display = 'block';
setTimeout(() => statusDiv.style.display = 'none', 3000);
// Notify content script
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
if (tabs[0]) {
chrome.tabs.sendMessage(tabs[0].id, {action: "refreshFilters"});
}
});
});
});
function togglePresetChip(chip, btnElement) {
if (hiddenChips.includes(chip)) {
hiddenChips = hiddenChips.filter(c => c !== chip);
btnElement.classList.remove('added');
} else {
hiddenChips.push(chip);
btnElement.classList.add('added');
}
}
function addCustomChip(chipName) {
if (!hiddenChips.includes(chipName)) {
hiddenChips.push(chipName);
renderCustomChips();
}
}
function removeCustomChip(chipName) {
hiddenChips = hiddenChips.filter(c => c !== chipName);
renderCustomChips();
// Also remove from preset if exists
const presetBtn = document.querySelector(`.preset-chip[data-chip="${chipName}"]`);
if (presetBtn) {
presetBtn.classList.remove('added');
}
}
function renderCustomChips() {
customChipsList.innerHTML = '';
hiddenChips.forEach(chip => {
if (!commonChips.includes(chip)) {
const tag = document.createElement('div');
tag.className = 'tag';
tag.innerHTML = `
${chip}
<button onclick="removeChip('${chip}')">×</button>
`;
customChipsList.appendChild(tag);
}
});
}
// Make removeChip available globally
window.removeChip = removeCustomChip;
});