Skip to content

Commit ed50b76

Browse files
committed
auto reload
1 parent 6568042 commit ed50b76

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

scripts/backup/ext/pinterest-auto-save/content.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
console.log("pinterest-auto-save loaded");
22

33
const cached = getCache();
4+
const reloadIfNotClickIn = 30000;
45
let allBoardBtn,
5-
isAutoClick = false;
6+
isAutoClick = false,
7+
lastClickTime = 0,
8+
intervalCheckClickTime = null;
69

710
const saveAllBtn = document.createElement("button");
811
saveAllBtn.innerText = "Save to All boards";
@@ -12,6 +15,15 @@ saveAllBtn.onclick = async () => {
1215
setCache("lastSaveIndex", parseInt(fromIndex) || 0);
1316
}
1417

18+
lastClickTime = Date.now();
19+
if (intervalCheckClickTime) clearInterval(intervalCheckClickTime);
20+
intervalCheckClickTime = setInterval(() => {
21+
if (Date.now() - lastClickTime > reloadIfNotClickIn) {
22+
// alert("reload");
23+
location.reload();
24+
}
25+
}, 1000);
26+
1527
savingText.innerText =
1628
"Auto Saving to board " + ((cached?.lastSaveIndex || 0) + 1) + " ...";
1729
document.body.appendChild(overlay);
@@ -64,6 +76,7 @@ saveAllBtn.onclick = async () => {
6476
// if save button appear -> click it
6577
const saveBtn = cur.querySelector('button[aria-label="save button"]');
6678
if (saveBtn) {
79+
lastClickTime = Date.now();
6780
clickSave(saveBtn, targetIndex);
6881
}
6982
// else -> click row
@@ -89,6 +102,7 @@ saveAllBtn.onclick = async () => {
89102
await sleep(1000);
90103
const saveBtn = target.querySelector('button[aria-label="save button"]');
91104
if (saveBtn) {
105+
lastClickTime = Date.now();
92106
clickSave(saveBtn, targetIndex);
93107
done = true;
94108
}
@@ -122,7 +136,7 @@ window.onload = async () => {
122136
};
123137

124138
onElementsAdded(
125-
'[data-test-id="closeup-body"] button[aria-label="Select a board you want to save to"]',
139+
'[data-test-id*="closeup-body"] button[aria-label="Select a board you want to save to"]',
126140
(nodes) => {
127141
if (nodes[0]) {
128142
console.log("add save all btn", nodes[0]);

0 commit comments

Comments
 (0)