-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
148 lines (123 loc) · 5.53 KB
/
popup.js
File metadata and controls
148 lines (123 loc) · 5.53 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
let unfollowersList = [];
document.addEventListener('DOMContentLoaded', function() {
const scanBtn = document.getElementById('scanBtn');
const exportBtn = document.getElementById('exportBtn');
const status = document.getElementById('status');
const progress = document.getElementById('progress');
const progressBar = document.getElementById('progressBar');
const results = document.getElementById('results');
const stats = document.getElementById('stats');
// Load saved data
chrome.storage.local.get(['unfollowers', 'scanDate'], function(data) {
if (data.unfollowers && data.scanDate) {
const scanDate = new Date(data.scanDate);
const now = new Date();
const hoursDiff = (now - scanDate) / (1000 * 60 * 60);
if (hoursDiff < 24) {
displayResults(data.unfollowers);
updateStatus(`Last scan: ${scanDate.toLocaleTimeString()}`, 'success');
}
}
});
scanBtn.addEventListener('click', function() {
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
const tab = tabs[0];
if (!tab.url.includes('instagram.com')) {
updateStatus('Please navigate to Instagram first', 'error');
return;
}
startScan();
});
});
exportBtn.addEventListener('click', function() {
exportToCSV();
});
function startScan() {
scanBtn.disabled = true;
progress.style.display = 'block';
updateStatus('Starting scan...', 'info');
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { action: 'startScan' }, function(response) {
if (chrome.runtime.lastError) {
updateStatus('Error: Please refresh Instagram and try again', 'error');
scanBtn.disabled = false;
progress.style.display = 'none';
return;
}
});
});
}
function updateStatus(message, type) {
status.textContent = message;
status.className = `status ${type}`;
}
function updateProgress(percent, message) {
progressBar.style.width = percent + '%';
if (message) {
updateStatus(message, 'info');
}
}
function displayResults(data) {
unfollowersList = data.unfollowers;
// Update stats
document.getElementById('followingCount').textContent = data.following.length;
document.getElementById('followersCount').textContent = data.followers.length;
document.getElementById('unfollowersCount').textContent = unfollowersList.length;
stats.style.display = 'flex';
// Display unfollowers list
results.innerHTML = '';
if (unfollowersList.length === 0) {
results.innerHTML = '<div style="text-align: center; color: #8e8e8e; padding: 20px;">Everyone you follow follows you back! 🎉</div>';
} else {
unfollowersList.forEach(user => {
const userDiv = document.createElement('div');
userDiv.className = 'user-item';
userDiv.innerHTML = `
<img class="user-avatar" src="${user.profile_pic_url || ''}" alt="${user.username}" onerror="this.style.display='none'">
<div class="user-info">
<div class="username">@${user.username}</div>
<div class="fullname">${user.full_name || ''}</div>
</div>
`;
userDiv.addEventListener('click', function() {
chrome.tabs.create({ url: `https://instagram.com/${user.username}` });
});
results.appendChild(userDiv);
});
}
exportBtn.style.display = unfollowersList.length > 0 ? 'block' : 'none';
}
function exportToCSV() {
if (unfollowersList.length === 0) return;
let csv = 'Username,Full Name,Profile URL\n';
unfollowersList.forEach(user => {
csv += `${user.username},"${user.full_name || ''}",https://instagram.com/${user.username}\n`;
});
const blob = new Blob([csv], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
chrome.downloads.download({
url: url,
filename: `instagram_unfollowers_${new Date().toISOString().split('T')[0]}.csv`
});
}
// Listen for messages from content script
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message.type === 'progress') {
updateProgress(message.percent, message.message);
} else if (message.type === 'complete') {
scanBtn.disabled = false;
progress.style.display = 'none';
if (message.error) {
updateStatus(message.error, 'error');
} else {
displayResults(message.data);
updateStatus(`Scan complete! Found ${message.data.unfollowers.length} non-followers`, 'success');
// Save data
chrome.storage.local.set({
unfollowers: message.data,
scanDate: new Date().toISOString()
});
}
}
});
});