-
Notifications
You must be signed in to change notification settings - Fork 3
/
add.js
89 lines (77 loc) · 2.87 KB
/
add.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
document.addEventListener('DOMContentLoaded', function() {
const actionButton = document.getElementById('actionStartButton');
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
const currentTab = tabs[0];
var statusElement = document.getElementById('status');
var baseUrl = currentTab.url;
if (baseUrl.includes('https://rephonic.com/search')) {
statusElement.textContent = "You found a list!";
statusElement.style.fontSize = "20px";
actionButton.disabled = false;
actionButton.classList.add("activeButton");
actionButton.style.backgroundColor = "#007BFF";
actionButton.style.color = "white";
actionButton.style.cursor = "pointer";
actionButton.addEventListener('mouseenter', function() {
this.style.backgroundColor = "#0056b3";
});
actionButton.addEventListener('mouseleave', function() {
this.style.backgroundColor = "#007BFF";
});
} else {
statusElement.textContent = "Please go to Rephonic List URL";
statusElement.style.fontSize = "20px";
actionButton.disabled = true;
actionButton.classList.remove("activeButton");
actionButton.style.backgroundColor = "grey";
actionButton.style.color = "white";
actionButton.style.cursor = "not-allowed";
}
});
});
function setRunningState(isRunning) {
chrome.storage.local.set({ isRunning: isRunning });
}
document.getElementById('actionStartButton').addEventListener('click', function() {
chrome.storage.local.get('isRunning', (result) => {
const isRunning = result.isRunning;
if (isRunning) {
setRunningState(false);
this.textContent = "Start";
} else {
setRunningState(true);
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
function: automateClicks,
});
});
this.textContent = "Stop";
}
});
});
function automateClicks() {
chrome.storage.local.get('isRunning', function(result) {
if (!result.isRunning) return;
var addButtons = document.querySelector('.ant-table-tbody').getElementsByTagName('button');
for (let i = 0; i < addButtons.length; i++) {
setTimeout(() => {
chrome.storage.local.get('isRunning', function(result) {
if (!result.isRunning) return;
addButtons[i].click();
console.log(`Button ${i + 1} -----> Clicked`);
});
}, 1000 * i)
}
const nextPageButton = document.querySelector(".ant-pagination-next .ant-pagination-item-link");
if (nextPageButton) {
setTimeout(() => {
chrome.storage.local.get('isRunning', function(result) {
if (!result.isRunning) return;
nextPageButton.click();
setTimeout(automateClicks, 5000);
});
}, addButtons.length * 1000 + 1000);
}
});
}