Created
April 28, 2020 15:51
-
-
Save fortserious/2c43d239c3d7eda33e6e7a7ce0d3fcae to your computer and use it in GitHub Desktop.
nytimes spelling bee allow backspace
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 nytimes spelling bee fixer | |
// @namespace www.rossdoran.com | |
// @version 0.1 | |
// @description wait for key elements | |
// @match https://www.nytimes.com/puzzles/spelling-bee | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js | |
// @run-at document-start | |
// ==/UserScript== | |
// Prevents the backspace key from navigating back, and remaps to delete key. | |
// Note: This may disable backspace function for password entry boxes on the page. | |
$(document).unbind('keydown').bind('keydown', function (event) { | |
if (event.keyCode === 8) { | |
var doPrevent = true; | |
var types = ["text", "password", "file", "search", "email", "number", "date", "color", "datetime", "datetime-local", "month", "range", "search", "tel", "time", "url", "week"]; | |
var d = $(event.srcElement || event.target); | |
var disabled = d.prop("readonly") || d.prop("disabled"); | |
if (!disabled) { | |
if (d[0].isContentEditable) { | |
doPrevent = false; | |
} else if (d.is("input")) { | |
var type = d.attr("type"); | |
if (type) { | |
type = type.toLowerCase(); | |
} | |
if (types.indexOf(type) > -1) { | |
doPrevent = false; | |
} | |
} else if (d.is("textarea")) { | |
doPrevent = false; | |
} | |
} | |
if (doPrevent) { | |
event.preventDefault(); | |
$(e.target).trigger({ | |
type: "keypress", | |
which: 13 | |
}); | |
return false; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment