Skip to content

Instantly share code, notes, and snippets.

@shu8
Created November 23, 2014 13:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
// ==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