-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
101 lines (86 loc) · 3.39 KB
/
Copy pathpopup.js
File metadata and controls
101 lines (86 loc) · 3.39 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
// Threshold values corresponding to slider positions
const thresholdValues = [100, 1000, 10000, 100000, 1000000, 10000000];
document.addEventListener('DOMContentLoaded', function() {
const thresholdSlider = document.getElementById('threshold');
const thresholdValueDisplay = document.getElementById('threshold-value');
const removedCountDisplay = document.getElementById('removed-count');
const applyButton = document.getElementById('apply');
const presetButtons = document.querySelectorAll('.preset-buttons button');
let currentThreshold = 1000; // Default
// Format number with commas
function formatNumber(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
// Load saved threshold and update UI
chrome.storage.local.get(['viewThreshold', 'removedCount'], function(result) {
if (result.viewThreshold) {
currentThreshold = result.viewThreshold;
// Find closest slider position
let closestIndex = 0;
let minDiff = Math.abs(thresholdValues[0] - currentThreshold);
for (let i = 1; i < thresholdValues.length; i++) {
const diff = Math.abs(thresholdValues[i] - currentThreshold);
if (diff < minDiff) {
minDiff = diff;
closestIndex = i;
}
}
thresholdSlider.value = closestIndex;
thresholdValueDisplay.textContent = formatNumber(currentThreshold);
}
if (result.removedCount) {
removedCountDisplay.textContent = formatNumber(result.removedCount);
}
});
// Get current count from active tab
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
if (tabs[0] && tabs[0].url.includes('youtube.com')) {
chrome.tabs.sendMessage(tabs[0].id, {action: "getCount"}, function(response) {
if (response && response.count !== undefined) {
removedCountDisplay.textContent = formatNumber(response.count);
}
});
}
});
// Update threshold display when slider changes
thresholdSlider.addEventListener('input', function() {
const value = thresholdValues[this.value];
thresholdValueDisplay.textContent = formatNumber(value);
currentThreshold = value;
});
// Handle preset buttons
presetButtons.forEach(button => {
button.addEventListener('click', function() {
const value = parseInt(this.dataset.value);
currentThreshold = value;
thresholdValueDisplay.textContent = formatNumber(value);
// Find closest slider position
let closestIndex = 0;
let minDiff = Math.abs(thresholdValues[0] - value);
for (let i = 1; i < thresholdValues.length; i++) {
const diff = Math.abs(thresholdValues[i] - value);
if (diff < minDiff) {
minDiff = diff;
closestIndex = i;
}
}
thresholdSlider.value = closestIndex;
});
});
// Apply button handler
applyButton.addEventListener('click', function() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
if (tabs[0] && tabs[0].url.includes('youtube.com')) {
chrome.tabs.sendMessage(
tabs[0].id,
{action: "updateThreshold", threshold: currentThreshold},
function(response) {
if (response && response.count !== undefined) {
removedCountDisplay.textContent = formatNumber(response.count);
}
}
);
}
});
});
});