Skip to content

A free, self-hostable news aggregator…

Disallow user page navigation while refreshing feeds (#9446)

Inverle74556f806fad
diff --git a/p/scripts/extra.js b/p/scripts/extra.js
index 6bb0c679e..fe63eef7e 100644
--- a/p/scripts/extra.js
+++ b/p/scripts/extra.js
@@ -518,17 +518,18 @@ function init_2stateButton() {
}
function init_configuration_alert() {
- window.onsubmit = function (e) {
+ window.addEventListener('submit', function (e) {
window.hasSubmit = data_leave_validation(document.body, e.target);
- };
- window.onbeforeunload = function (e) {
+ });
+ window.addEventListener('beforeunload', function (e) {
if (window.hasSubmit) {
- return;
+ return true;
}
if (!data_leave_validation(document.body)) {
+ e.preventDefault();
return false;
}
- };
+ });
}
function init_details_attributes() {
diff --git a/p/scripts/main.js b/p/scripts/main.js
index 04d8a8018..5e8de3025 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -1863,7 +1863,10 @@ function refreshFeed(feeds, feeds_count) {
const req2 = new XMLHttpRequest();
req2.open('POST', './?c=feed&a=actualize&id=-1&ajax=1', true);
req2.onloadend = function (e) {
- delayedFunction(function () { location.reload(); });
+ delayedFunction(function () {
+ feeds_processed = 0; // New articles were committed, allow exiting the page without confirmation.
+ location.reload();
+ });
};
req2.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
req2.send(JSON.stringify({
@@ -2465,8 +2468,17 @@ function init_normal() {
});
}
- document.addEventListener("visibilitychange", () => {
- if (document.visibilityState === "hidden") {
+ window.addEventListener('beforeunload', (e) => {
+ const feeds_updating = feeds_processed > 0;
+ if (feeds_updating) {
+ // Prevent the user from closing the tab without confirmation.
+ e.preventDefault();
+ return false;
+ }
+ });
+
+ document.addEventListener('visibilitychange', () => {
+ if (document.visibilityState === 'hidden') {
if (mark_read_queue && mark_read_queue.length > 0) {
clearTimeout(send_mark_read_queue_timeout);
send_mark_queue_tick(null);