Page MenuHomePhabricator
Paste P74205

(An Untitled Masterwork)
ActivePublic

Authored by Daimona on Mar 12 2025, 3:34 PM.
Tags
None
Referenced Files
F58808896: raw-paste-data.txt
Mar 12 2025, 5:27 PM
F58808357: raw-paste-data.txt
Mar 12 2025, 3:34 PM
Subscribers
None
// ==UserScript==
// @name Prevent phab content loss for new tasks
// @version 0.1.1
// @description See https://we.phorge.it/T15202
// @author Someone who just lost content, ofc
// @match https://phabricator.wikimedia.org/maniphest/task/edit/*
// @match https://phabricator.wmcloud.org/maniphest/task/edit/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const mainForm = document.querySelector( '.phui-box form' );
function getFormState() {
return new URLSearchParams( new FormData( mainForm ) ).toString();
}
const initialState = getFormState();
/** Adapted from https://we.phorge.it/T15202 */
function onBeforeUnload( e ) {
if ( getFormState() !== initialState ) {
// For security reasons, only a generic string not under the control
// of the webpage is shown instead of this returned string
// so you can put here whatever you want
// https://developer.mozilla.org/en-US/docs/Web/API/BeforeUnloadEvent
var confirmationMessage = "Melanzane ripiene";
// Gecko + IE
(e || window.event).returnValue = confirmationMessage;
// Safari, Chrome, and other WebKit-derived browsers
return confirmationMessage;
}
}
window.addEventListener( 'beforeunload', onBeforeUnload );
mainForm.addEventListener(
'submit',
() => window.removeEventListener( 'beforeunload', onBeforeUnload )
);
})();

Event Timeline

To use this script, you need a Userscript manager like Greasemonkey or tampermonkey. Once you have installed that, follow its instructions for creating a new script and paste the code above.

The script is loaded when creating or editing a task, and it will display a confirmation popup if you try to close the browser tab/window with unsaved changes.