Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions bookmarklet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ javascript: (function () {
var isOverview = document.location.href.match(/\/overview\b/);
if (isReddit && isOverview) {
var cachBustUrl = `?${new Date().getDate()}`;
var cachBustUrl = 'https://raw.githubusercontent.com/j0be/PowerDeleteSuite/master/powerdeletesuite.js?' + (new Date().getDate());
// var cachBustUrl = "https://raw.githubusercontent.com/saandman/PowerDeleteSuite/master/powerdeletesuite.js?" + (new Date().getDate());
var cachBustUrl = 'https://raw.githubusercontent.com/jfl88/PowerDeleteSuite/master/powerdeletesuite.js?' + (new Date().getDate());
fetch(cachBustUrl)
.then(function (response) {
return response.text();
Expand Down
202 changes: 115 additions & 87 deletions powerdeletesuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,21 @@ var pd = {
csvCell: function (str) {
return '"' + str + '",';
},
getRateLimitTimeout: function(xhr) {
// Read headers
const rateLimitRemaining = parseInt(xhr.getResponseHeader('x-ratelimit-remaining'), 10);
const rateLimitReset = parseInt(xhr.getResponseHeader('x-ratelimit-reset'), 10);
// Determine timeout
let timeout;
// if ratelimit low, set the timeout to wait based on the reset time
if (rateLimitRemaining <= 5) {
timeout = (rateLimitReset + 1) * 1000;
} else {
// Randomize timeout between 1.5 to 3 seconds
timeout = Math.floor(Math.random() * 1500) + 1500;
}
return timeout;
},
getSettings: function () {
return localStorage.getItem("pd_storage")
? JSON.parse(localStorage.getItem("pd_storage"))
Expand Down Expand Up @@ -714,21 +729,27 @@ var pd = {
sort: pd.task.paths.sorts[0],
t: pd.task.paths.timeframes[0],
},
}).then(
function (resp) {
}).complete(
function (xhr) {
resp = xhr.responseJSON;
if (resp.data) {
var children = resp.data.children;
pd.task.info.donePages++;
if (children.length > 0) {
pd.task.info.doneItems = 0;
pd.task.info.numItems = children.length;
pd.task.items = children;
pd.actions.children.handleGroup();
} else {
pd.task.after = "";
pd.actions.page.shift();
pd.actions.page.next();
}
const timeout = pd.helpers.getRateLimitTimeout(xhr);
console.log(new Date().toLocaleDateString()+ 'timeout: ' + timeout);
// Set the next action with the calculated timeout
setTimeout(() => {
var children = resp.data.children;
pd.task.info.donePages++;
if (children.length > 0) {
pd.task.info.doneItems = 0;
pd.task.info.numItems = children.length;
pd.task.items = children;
pd.actions.children.handleGroup();
} else {
pd.task.after = "";
pd.actions.page.shift();
pd.actions.page.next();
}
}, timeout);
} else {
pd.task.info.errors++;
if (
Expand All @@ -742,7 +763,7 @@ var pd = {
pd.ui.done();
}
}
},
}).fail(
function () {
pd.task.info.errors++;
if (
Expand Down Expand Up @@ -872,85 +893,92 @@ var pd = {
},
},
delete: function (item) {
setTimeout(() => {
if (pd.performActions) {
$.ajax({
url: "/api/del",
method: "post",
data: {
id: item.data.name,
executed: "deleted",
uh: pd.config.uh,
renderstyle: "html",
},
}).then(
function () {
if (pd.performActions) {
$.ajax({
url: "/api/del",
method: "post",
data: {
id: item.data.name,
executed: "deleted",
uh: pd.config.uh,
renderstyle: "html",
},
}).complete(
function (xhr) {
const timeout = pd.helpers.getRateLimitTimeout(xhr);
console.log(new Date().toLocaleDateString()+ 'timeout: ' + timeout);
// Set the next action with the calculated timeout
setTimeout(() => {
pd.task.items[0].pdDeleted = true;
pd.actions.children.handleSingle();
},
function () {
pd.task.info.errors++;
if (
confirm(
"Error deleting " +
(item.kind == "t3" ? "post" : "comment") +
", would you like to retry?"
)
) {
pd.actions.children.handleSingle();
} else {
pd.actions.children.finishItem();
pd.actions.children.handleGroup();
}
}
);
} else {
pd.task.items[0].pdDeleted = true;
pd.task.after = pd.task.items[0].data.name;
pd.actions.children.handleSingle();
}
}, 5000);
}, timeout);
}
).fail(
function () {
pd.task.info.errors++;
if (
confirm(
"Error deleting " +
(item.kind == "t3" ? "post" : "comment") +
", would you like to retry?"
)
) {
pd.actions.children.handleSingle();
} else {
pd.actions.children.finishItem();
pd.actions.children.handleGroup();
}
});
} else {
pd.task.items[0].pdDeleted = true;
pd.task.after = pd.task.items[0].data.name;
pd.actions.children.handleSingle();
}
},
edit: function (item) {
setTimeout(() => {
if (pd.performActions) {
var editString = pd.task.config.editText ||
pd.editStrings[Math.floor(Math.random() * pd.editStrings.length)];
$.ajax({
url: "/api/editusertext",
method: "post",
data: {
thing_id: item.data.name,
text: editString,
id: "#form-" + item.data.name,
r: item.data.subreddit,
uh: pd.config.uh,
renderstyle: "html",
},
}).then(
function () {
if (pd.performActions) {
var editString = pd.task.config.editText ||
pd.editStrings[Math.floor(Math.random() * pd.editStrings.length)];
$.ajax({
url: "/api/editusertext",
method: "post",
data: {
thing_id: item.data.name,
text: editString,
id: "#form-" + item.data.name,
r: item.data.subreddit,
uh: pd.config.uh,
renderstyle: "html",
},
}).complete(
function (xhr) {
const timeout = pd.helpers.getRateLimitTimeout(xhr);
console.log(new Date().toLocaleDateString()+ 'timeout: ' + timeout);
// Set the next action with the calculated timeout
setTimeout(() => {
pd.task.items[0].pdEdited = true;
pd.actions.children.handleSingle();
},
function () {
pd.task.info.errors++;
if (
!confirm(
"Error editing " +
(item.kind == "t3" ? "post" : "comment") +
", would you like to retry?"
)
) {
item.pdEdited = true;
}
pd.actions.children.handleSingle();
}, timeout);
}
).fail(
function () {
pd.task.info.errors++;
if (
!confirm(
"Error editing " +
(item.kind == "t3" ? "post" : "comment") +
", would you like to retry?"
)
) {
item.pdEdited = true;
}
);
} else {
pd.task.items[0].pdEdited = true;
pd.actions.children.handleSingle();
}
}, 5000);
pd.actions.children.handleSingle();
}
);
} else {
pd.task.items[0].pdEdited = true;
pd.actions.children.handleSingle();
}
},
},
ui: {
Expand Down
4 changes: 2 additions & 2 deletions powerdeletesuite.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
(function() {
'use strict';

fetch("https://raw.githubusercontent.com/j0be/PowerDeleteSuite/master/bookmarklet.js").then(response => response.text()).then(response => {
fetch("https://raw.githubusercontent.com/jfl88/PowerDeleteSuite/master/bookmarklet.js").then(response => response.text()).then(response => {
var scr = response;
document.querySelector("#header-bottom-right > ul.flat-list").outerHTML += document.querySelector("#header-bottom-right > ul.flat-list").nextSibling.outerHTML; // dupe the separator
document.querySelector("#header-bottom-right > ul.flat-list").nextSibling.outerHTML += '<a id="pd-delete" href="' + scr + '">PDS</a>' // yoink a button between the separators
})
})();
})();