Created
September 25, 2008 00:52
-
-
Save liquidz/12719 to your computer and use it in GitHub Desktop.
opera user js for searching gist
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== | |
| // @include http://gist.github.com/* | |
| // ==/UserScript== | |
| (function(){ | |
| var $ = function(id){ | |
| return document.getElementById(id); | |
| }; | |
| var classLoop = function(tag_name, class_name, func){ | |
| var tags = document.getElementsByTagName(tag_name); | |
| if(tags){ | |
| for(var i = 0; i < tags.length; ++i){ | |
| if(tags[i].className == class_name) func(tags[i]); | |
| } | |
| } | |
| }; | |
| var settings = { | |
| label_text: " find: ", | |
| label_color: "#888", | |
| form_id: "search_form" | |
| }; | |
| var check_key_up = function(e){ | |
| var obj = $(settings.form_id); | |
| if(obj){ | |
| var value = obj.value; | |
| if(value.length < 2){ | |
| classLoop("div", "file", function(elem){ | |
| elem.style.display = "block"; | |
| }); | |
| } else { | |
| classLoop("div", "file", function(elem){ | |
| if(elem.innerHTML.match(obj.value)){ | |
| elem.style.display = "block"; | |
| } else { | |
| elem.style.display = "none"; | |
| } | |
| }); | |
| } | |
| } | |
| }; | |
| var select_form = function(e){ | |
| var obj = $(settings.form_id); | |
| if(obj) obj.select(); | |
| }; | |
| window.onload = function(){ | |
| var label = document.createElement("span"); | |
| var search_form = document.createElement("input"); | |
| search_form.type = "text"; | |
| search_form.id = settings.form_id; | |
| label.innerHTML = settings.label_text; | |
| label.style.color = settings.label_color; | |
| var h2 = document.getElementsByTagName("h2")[0]; | |
| h2.appendChild(label); | |
| h2.appendChild(search_form); | |
| search_form.addEventListener("keyup", check_key_up, true); | |
| search_form.addEventListener("click", select_form, false); | |
| search_form.focus(); | |
| }; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment