Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created January 10, 2010 12:47
Show Gist options
  • Save hitode909/273482 to your computer and use it in GitHub Desktop.
Save hitode909/273482 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name label
// @namespace http://www.hatena.ne.jp/hitode909
// @description label
// @include *
// ==/UserScript==
var inputs = document.getElementsByTagName("input");
for(var i=0; i<inputs.length; i++){
var input = inputs[i];
if(input.getAttribute("type") == "radio") {
var cur = input;
var found = false;
while(cur) {
if(cur.tagName == "LABEL") {
found = true;
break;
}
cur = cur.parentNode;
}
if (!found && input.nextSibling) {
var df = document.createDocumentFragment();
df.appendChild(input.cloneNode(false));
df.appendChild(input.nextSibling);
var label = document.createElement('label');
label.appendChild(df);
input.parentNode.replaceChild(label, input);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment