Radio button disabler (answer to http://softwarerecs.stackexchange.com/questions/13490/chrome-extension-to-eliminate-choices-on-multiple-choice-questions)
This file contains 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 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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.