Skip to content

Instantly share code, notes, and snippets.

@lolicsystem
Created January 7, 2010 16:05
Show Gist options
  • Save lolicsystem/271329 to your computer and use it in GitHub Desktop.
Save lolicsystem/271329 to your computer and use it in GitHub Desktop.
tr タグと li タグを grep するグリモン。grepの元ネタは http://0xcc.net/blog/archives/000008.html (グリモンの皮を被せただけ)
// ==UserScript==
// @name table_grep
// @namespace http://github.com/lolicsystem
// @description table grep
// @include *
// @author lolicsystem
// @version 0.1
// ==/UserScript==
(function () {
var target = document.getElementsByTagName('html');
target[0].appendChild(keywordInput());
function keywordInput() {
var e = document.createElement('input');
e.type = 'text';
e.size = '20';
e.style.position = 'fixed';
e.style.top = '3px';
e.style.left = '3px';
e.style.zIndex = '65535';
e.addEventListener('keyup',
function () {
grep('tr', e.value);
grep('li', e.value);
}, true);
return e;
}
var displaystyle;
function grep (tag, pattern) {
try {
regex = new RegExp(pattern, "i");
var row = document.getElementsByTagName(tag);
for (i = 0; i < row.length; i++) {
e = row[i];
if(displaystyle == null){
displaystyle = e.style.display;
}
var str = e.innerText || e.innerHTML;
if (str.match(regex)) {
e.style.display = displaystyle;
} else {
e.style.display = "none";
}
}
} catch (e) {
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment