/* based on chromium plugin code, adapted by Nibble<.gs@gmail.com> */ var hint_num_str = ''; var hint_elems = []; var hint_open_in_new_tab = false; var hint_enabled = false; function hintMode(newtab){ hint_enabled = true; if (newtab) { hint_open_in_new_tab = true; } else { hint_open_in_new_tab = false; } setHints(); document.removeEventListener('keydown', initKeyBind, false); document.addEventListener('keydown', hintHandler, false); hint_num_str = ''; } function hintHandler(e){ e.preventDefault(); //Stop Default Event var pressedKey = get_key(e); if (pressedKey == 'Enter') { if (hint_num_str == '') hint_num_str = '1'; judgeHintNum(Number(hint_num_str)); } else if (/[0-9]/.test(pressedKey) == false) { removeHints(); } else { hint_num_str += pressedKey; var hint_num = Number(hint_num_str); if (hint_num * 10 > hint_elems.length + 1) { judgeHintNum(hint_num); } else { var hint_elem = hint_elems[hint_num - 1]; if (hint_elem != undefined && hint_elem.tagName.toLowerCase() == 'a') { setHighlight(hint_elem, true); } } } } function setHighlight(elem, is_active) { if (is_active) { var active_elem = document.body.querySelector('a[highlight=hint_active]'); if (active_elem != undefined) active_elem.setAttribute('highlight', 'hint_elem'); elem.setAttribute('highlight', 'hint_active'); } else { elem.setAttribute('highlight', 'hint_elem'); } } function setHintRules() { if (document.styleSheets.length < 1) { var style = document.createElement("style"); style.appendChild(document.createTextNode("")); document.head.appendChild(style); } var ss = document.styleSheets[0]; ss.insertRule('a[highlight=hint_elem] {background-color: NULL}', 0); ss.insertRule('a[highlight=hint_active] {background-color: NULL}', 0); } function deleteHintRules() { var ss = document.styleSheets[0]; ss.deleteRule(0); ss.deleteRule(0); } function judgeHintNum(hint_num) { var hint_elem = hint_elems[hint_num - 1]; if (hint_elem != undefined) { execSelect(hint_elem); } else { removeHints(); } } function execSelect(elem) { var tag_name = elem.tagName.toLowerCase(); var type = elem.type ? elem.type.toLowerCase() : ""; if (tag_name == 'a' && elem.href != '') { setHighlight(elem, true); // TODO: ajax,