Skip to content

Instantly share code, notes, and snippets.

@shu8
Created November 23, 2014 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shu8/2a25e8b8d17caa60c78a to your computer and use it in GitHub Desktop.
Save shu8/2a25e8b8d17caa60c78a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Input Disabler
// @namespace http://stackexchange.com/users/4337810/%E1%B9%A7%D0%BD%CA%8A%C3%9F
// @version 0.1
// @description This script allows you to disable any HTML inputs you find across the web!
// @author ṧнʊß (shub)
// @match http://*/*
// @match https://*/*
// ==/UserScript==
function addButtonBefore(inputItem) {
var button = document.createElement("button");
var text = document.createTextNode("eliminate");
button.appendChild(text);
cssString = "font-size: 9px; border: 0; border-radius: 10px; outline: none;"
button.style.cssText = cssString;
button.setAttribute("title", "disable / enable this element")
button.addEventListener('click', function(e) {
var state = inputItem.disabled;
inputItem.disabled = !state;
e.preventDefault();
e.stopPropagation();
e.cancelBubble = true;
e.returnValue = false;
return false;
});
inputItem.parentNode.insertBefore(button, inputItem.nextSibling.nextSibling); //Doubled .nextSibling because some elements have text after them. Difference is unnoticeable for elements without text.
}
Array.prototype.forEach.call(document.getElementsByName('answer'), function(inputItem) {
addButtonBefore(inputItem);
});
@shu8
Copy link
Author

shu8 commented Nov 23, 2014

This was specifically designed as an answer to this (on Software Recommendations Beta SE). It will work with radio buttons in a group called 'answer'. You can easily change this by changing line 31 answer to the radio button group name.

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