Created
April 18, 2020 23:05
-
-
Save malcolmocean/7ba2e561abfc6882a09522ff4887e057 to your computer and use it in GitHub Desktop.
Twitter UserScript - prevent accidentally closing tweetstorm drafts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Twitter - onbeforeunload for compose | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Have you ever lost a tweetstorm because you accidentally hit a hotkey to close a tab/window? | |
// This script adds the familiar "Leave site? Changes that you've made may not be saved." pop-up | |
// The text of that dialog is controlled by the browser, so it may vary, but the important part is a chance to confirm what you're doing. | |
// @author @Malcolm_Ocean | |
// @match https://twitter.com/* | |
// @grant none | |
// ==/UserScript== | |
(() => { | |
'use strict' | |
window.onbeforeunload = () => { | |
if (/compose\/tweet/.test(location.href)) { | |
return "Discard this tweet/thread?" | |
} | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment