From a74f17a6b9ae820de398fd4de3eaffa52ba2bcff Mon Sep 17 00:00:00 2001 From: sakfa <640527+sakfa@users.noreply.github.com> Date: Fri, 29 May 2026 14:15:21 -0700 Subject: [PATCH] Replace confirm dialogs on edit/delete failures with exponential backoff On 429 rate-limit responses, automatically retry after 1s doubling each failure up to 1024s. Resets to 1s on any successful request or new run. --- powerdeletesuite.js | 53 +++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/powerdeletesuite.js b/powerdeletesuite.js index bfca90d..275bbe3 100644 --- a/powerdeletesuite.js +++ b/powerdeletesuite.js @@ -408,6 +408,7 @@ var pd = { }); }, createProcessStream: function () { + pd.backoff.reset(); window.pd_processing = true; pd.exportItems = []; pd.exportIds = []; @@ -548,6 +549,22 @@ var pd = { }); }, }, + backoff: { + delay: 1000, + maxDelay: 1024000, + schedule: function (fn) { + console.log( + "[PowerDeleteSuite] Rate limited (429). Backing off for " + + pd.backoff.delay / 1000 + + "s before retrying..." + ); + setTimeout(fn, pd.backoff.delay); + pd.backoff.delay = Math.min(pd.backoff.delay * 2, pd.backoff.maxDelay); + }, + reset: function () { + pd.backoff.delay = 1000; + }, + }, helpers: { validate: function () { if (pd.task.config.isEditing && pd.task.config.editText === "") { @@ -885,22 +902,18 @@ var pd = { }, }).then( function () { + pd.backoff.reset(); pd.task.items[0].pdDeleted = true; pd.actions.children.handleSingle(); }, - function () { + function (jqXHR) { pd.task.info.errors++; - if ( - confirm( - "Error deleting " + - (item.kind == "t3" ? "post" : "comment") + - ", would you like to retry?" - ) - ) { - pd.actions.children.handleSingle(); + if (jqXHR.status === 429) { + pd.backoff.schedule(function () { + pd.actions.children.handleSingle(); + }); } else { - pd.actions.children.finishItem(); - pd.actions.children.handleGroup(); + pd.actions.children.handleSingle(); } } ); @@ -929,21 +942,19 @@ var pd = { }, }).then( function () { + pd.backoff.reset(); pd.task.items[0].pdEdited = true; pd.actions.children.handleSingle(); }, - function () { + function (jqXHR) { pd.task.info.errors++; - if ( - !confirm( - "Error editing " + - (item.kind == "t3" ? "post" : "comment") + - ", would you like to retry?" - ) - ) { - item.pdEdited = true; + if (jqXHR.status === 429) { + pd.backoff.schedule(function () { + pd.actions.children.handleSingle(); + }); + } else { + pd.actions.children.handleSingle(); } - pd.actions.children.handleSingle(); } ); } else {