Skip to content

Instantly share code, notes, and snippets.

@malcolmocean
Created April 18, 2020 23:05
Show Gist options
  • Save malcolmocean/7ba2e561abfc6882a09522ff4887e057 to your computer and use it in GitHub Desktop.
Save malcolmocean/7ba2e561abfc6882a09522ff4887e057 to your computer and use it in GitHub Desktop.
Twitter UserScript - prevent accidentally closing tweetstorm drafts
// ==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