Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bryan-lunt/b7ec6abe922605f3f82ead1fc99dd3eb to your computer and use it in GitHub Desktop.
Save bryan-lunt/b7ec6abe922605f3f82ead1fc99dd3eb to your computer and use it in GitHub Desktop.
Prevent Lost work on DataAnnotation.tech
// ==UserScript==
// @name Disable Back Button
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Disables the back button for specified URLs
// @author You
// @match https://app.dataannotation.tech/workers/tasks/*
// @grant none
// ==/UserScript==
// Replace "your-target-website-url-here" with the actual URLs you want to target
//
// Copied from StackOverflow https://stackoverflow.com/a/12381873
//
(function (global) {
if(typeof (global) === "undefined") {
throw new Error("window is undefined");
}
var _hash = "!";
var noBackPlease = function () {
global.location.href += "#";
// Making sure we have the fruit available for juice (^__^)
global.setTimeout(function () {
global.location.href += "!";
}, 50);
};
global.onhashchange = function () {
if (global.location.hash !== _hash) {
global.location.hash = _hash;
}
};
global.onload = function () {
noBackPlease();
// Disables backspace on page except on input fields and textarea..
document.body.onkeydown = function (e) {
var elm = e.target.nodeName.toLowerCase();
if (e.which === 8 && (elm !== 'input' && elm !== 'textarea')) {
e.preventDefault();
}
// Stopping the event bubbling up the DOM tree...
e.stopPropagation();
};
}
})(window);
@bryan-lunt
Copy link
Author

Prevents losing work on DataAnnotation dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment