From 973e1fed14595b80e9aabcf36527ef79110c7fd5 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Fri, 11 Jun 2021 00:30:11 -0400 Subject: [PATCH] hints: clang-format --- user-scripts/hints.js | 147 +++++++++++++----------------------------- 1 file changed, 46 insertions(+), 101 deletions(-) diff --git a/user-scripts/hints.js b/user-scripts/hints.js index 01fc640..c1854c3 100644 --- a/user-scripts/hints.js +++ b/user-scripts/hints.js @@ -26,39 +26,31 @@ var charset = "sdfghjklertzuivbn".split(""); var key_follow = "f"; var key_follow_new_win = "F"; -function update_highlights_or_abort() -{ +function update_highlights_or_abort() { var submatch; var col_sel, col_unsel; var longest_id = 0; - if (document.chorizo_hints.state === "follow_new") - { + if (document.chorizo_hints.state === "follow_new") { col_unsel = "#DAFFAD"; col_sel = "#FF5D00"; - } - else - { + } else { col_unsel = "#A7FFF5"; col_sel = "#33FF00"; } - for (var id in document.chorizo_hints.labels) - { + for (var id in document.chorizo_hints.labels) { var label = document.chorizo_hints.labels[id]; var bgcol = col_unsel; longest_id = Math.max(longest_id, id.length); - if (document.chorizo_hints.box.value !== "") - { + if (document.chorizo_hints.box.value !== "") { submatch = id.match("^" + document.chorizo_hints.box.value); - if (submatch !== null) - { + if (submatch !== null) { var href_suffix = ""; var box_shadow_inner = "#B00000"; - if (id === document.chorizo_hints.box.value) - { + if (id === document.chorizo_hints.box.value) { bgcol = col_sel; box_shadow_inner = "red"; if (label.elem.tagName.toLowerCase() === "a") @@ -75,15 +67,11 @@ function update_highlights_or_abort() save_parent_style(label); label.elem.style.boxShadow = "0 0 5pt 2pt black, 0 0 0 2pt " + box_shadow_inner + " inset"; - } - else - { + } else { label.span.style.visibility = "hidden"; reset_parent_style(label); } - } - else - { + } else { label.span.style.visibility = "visible"; label.span.innerHTML = id; reset_parent_style(label); @@ -95,16 +83,14 @@ function update_highlights_or_abort() set_state("inactive"); } -function open_match() -{ +function open_match() { var choice = document.chorizo_hints.box.value; var was_state = document.chorizo_hints.state; var elem = document.chorizo_hints.labels[choice].elem; - set_state("inactive"); /* Nukes labels. */ + set_state("inactive"); /* Nukes labels. */ - if (elem) - { + if (elem) { var tag_name = elem.tagName.toLowerCase(); var type = elem.type ? elem.type.toLowerCase() : ""; @@ -113,59 +99,42 @@ function open_match() if (was_state === "follow_new" && tag_name === "a") window.open(elem.href); - else if ( - ( - tag_name === "input" && - type !== "button" && - type !== "color" && - type !== "checkbox" && - type !== "file" && - type !== "radio" && - type !== "reset" && - type !== "submit" - ) || - tag_name === "textarea" || - tag_name === "select" - ) + else if ((tag_name === "input" && type !== "button" && + type !== "color" && type !== "checkbox" && type !== "file" && + type !== "radio" && type !== "reset" && type !== "submit") || + tag_name === "textarea" || tag_name === "select") elem.focus(); else elem.click(); } } -function reset_parent_style(label) -{ +function reset_parent_style(label) { if (label.parent_style !== null) label.elem.style.boxShadow = label.parent_style.boxShadow; } -function save_parent_style(label) -{ - if (label.parent_style === null) - { +function save_parent_style(label) { + if (label.parent_style === null) { var style = window.getComputedStyle(label.elem); label.parent_style = new Object(); label.parent_style.boxShadow = style.getPropertyValue("boxShadow"); } } -function set_state(new_state) -{ +function set_state(new_state) { console.log("[hints] New state: " + new_state); document.chorizo_hints.state = new_state; - if (document.chorizo_hints.state === "inactive") - { + if (document.chorizo_hints.state === "inactive") { nuke_labels(); // Removing our box causes unwanted scrolling. Just hide it. document.chorizo_hints.box.blur(); document.chorizo_hints.box.value = ""; document.chorizo_hints.box.style.visibility = "hidden"; - } - else - { + } else { if (document.chorizo_hints.labels === null) create_labels(); @@ -177,8 +146,7 @@ function set_state(new_state) // invisible text box (opacity 0) and focus it while follow mode // is active. var box = document.chorizo_hints.box; - if (box === null) - { + if (box === null) { document.chorizo_hints.box = document.createElement("input"); box = document.chorizo_hints.box; @@ -202,27 +170,23 @@ function set_state(new_state) } } -function create_labels() -{ +function create_labels() { document.chorizo_hints.labels = new Object(); var selector = "a[href]:not([href=''])"; - if (document.chorizo_hints.state !== "follow_new") - { + if (document.chorizo_hints.state !== "follow_new") { selector += ", input:not([type=hidden]):not([chorizo_input_box=yes])"; selector += ", textarea, select, button"; } var elements = document.body.querySelectorAll(selector); - for (var i = 0; i < elements.length; i++) - { + for (var i = 0; i < elements.length; i++) { var elem = elements[i]; var label_id = ""; var n = i; - do - { + do { // Appending the next "digit" (instead of prepending it as // you would do it in a base conversion) scatters the labels // better. @@ -240,40 +204,35 @@ function create_labels() span.style.position = "absolute"; span.style.textTransform = "lowercase"; span.style.visibility = "hidden"; - span.style.zIndex = "2147483647"; // Max for WebKit according to luakit + span.style.zIndex = "2147483647"; // Max for WebKit according to luakit document.chorizo_hints.labels[label_id] = { - "elem": elem, - "span": span, - "parent_style": null, + "elem" : elem, + "span" : span, + "parent_style" : null, }; // Appending the spans as children to anchors gives better // placement results, but we can *only* do this for ... var tag_name = elem.tagName.toLowerCase(); - if (tag_name === "a") - { + if (tag_name === "a") { span.style.borderTopLeftRadius = "10pt"; span.style.borderBottomLeftRadius = "10pt"; span.style.padding = "0px 2pt 0px 5pt"; elem.appendChild(span); - } - else - { + } else { span.style.borderRadius = "10pt"; span.style.padding = "0px 5pt"; elem.parentNode.insertBefore(span, elem); } - console.log("[hints] Label ID " + label_id + ", " + i + - " for elem [" + elem + "]"); + console.log("[hints] Label ID " + label_id + ", " + i + " for elem [" + + elem + "]"); } } -function nuke_labels() -{ - for (var id in document.chorizo_hints.labels) - { +function nuke_labels() { + for (var id in document.chorizo_hints.labels) { var label = document.chorizo_hints.labels[id]; reset_parent_style(label); @@ -288,39 +247,28 @@ function nuke_labels() document.chorizo_hints.labels = null; } -function on_box_input(e) -{ - update_highlights_or_abort(); -} +function on_box_input(e) { update_highlights_or_abort(); } -function on_box_key(e) -{ - if (e.key === "Escape") - { +function on_box_key(e) { + if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); set_state("inactive"); - } - else if (e.key === "Enter") - { + } else if (e.key === "Enter") { e.preventDefault(); e.stopPropagation(); open_match(); } } -function on_window_key(e) -{ +function on_window_key(e) { if (e.target.nodeName.toLowerCase() === "textarea" || e.target.nodeName.toLowerCase() === "input" || - document.designMode === "on" || - e.target.contentEditable === "true") - { + document.designMode === "on" || e.target.contentEditable === "true") { return; } - if (document.chorizo_hints.state === "inactive") - { + if (document.chorizo_hints.state === "inactive") { if (e.key === key_follow) set_state("follow"); else if (e.key === key_follow_new_win) @@ -328,8 +276,7 @@ function on_window_key(e) } } -if (document.chorizo_hints === undefined) -{ +if (document.chorizo_hints === undefined) { document.chorizo_hints = new Object(); document.chorizo_hints.box = null; document.chorizo_hints.labels = null; @@ -338,8 +285,6 @@ if (document.chorizo_hints === undefined) document.addEventListener("keyup", on_window_key); console.log("[hints] Initialized."); -} -else +} else console.log("[hints] ALREADY INSTALLED"); - }()); -- 2.39.2