From d25a47814c6920efcca10150e41ecde91213f6cb Mon Sep 17 00:00:00 2001 From: wareya Date: Wed, 11 Sep 2019 19:51:15 -0400 Subject: [PATCH] add options that make it possible to make nazeka look more like yomichan --- options.js | 82 +++++++++++++++++++++++++++++++++++++++++++++++++---- texthook.js | 64 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 136 insertions(+), 10 deletions(-) diff --git a/options.js b/options.js index f98eb5e..1eb831a 100644 --- a/options.js +++ b/options.js @@ -144,12 +144,6 @@ function defaults() default: "一,二,三,四,五,六,七,八,九,〇", label: "Ignore json dictionary entries with these spellings" }); - settings.push({ - id: "highlight_dict_headers", - kind: "checkbox", - default: false, - label: "Highlight dictionary headers" - }); settings.push({ id: "popup_requires_key", kind: "combobox", @@ -262,6 +256,18 @@ function defaults() default: false, label: "Fixed width" }); + settings.push({ + id: "novalign", + kind: "checkbox", + default: false, + label: "Disable use of `vertical-align: middle;` for reading/etc info" + }); + settings.push({ + id: "inserthr", + kind: "checkbox", + default: false, + label: "Insert horizontal bar between entries" + }); /* // currently broken settings.push({ @@ -310,6 +316,12 @@ function defaults() default: false, label: "Disable border" }); + settings.push({ + id: "dropshadow", + kind: "checkbox", + default: false, + label: "Enable dropshadow" + }); settings.push({ id: "bgcolor", kind: "color", @@ -340,6 +352,26 @@ function defaults() default: "#D8A888", label: "Dictionary title color (for when using json dictionaries)" }); + settings.push({ + id: "highlight_dict_headers", + kind: "checkbox", + default: false, + label: "Highlight dictionary headers" + }); + settings.push({ + id: "dropshadowcolor", + kind: "color", + default: "#000000", + label: "Dropshadow color" + }); + settings.push({ + id: "dropshadowradius", + kind: "number", + min: 1, + max: 50, + default: 10, + label: "Dropshadow radius" + }); settings.push({ id: "font", kind: "text", @@ -382,6 +414,44 @@ function defaults() default: false, label: "Sticky mode" }); + settings.push({ + id: "padding", + kind: "number", + min: 0, + max: 10, + default: 2, + label: "Padding" + }); + settings.push({ + id: "info_styling", + kind: "checkbox", + default: false, + label: "Yomichan-like definition info tag styling" + }); + settings.push({ + id: "info_fgcolor", + kind: "color", + default: "#CCCCCC", + label: "Yomichan-like info tag text color" + }); + settings.push({ + id: "info_bgcolor_pos", + kind: "color", + default: "#284880", + label: "Yomichan-like info tag background for part-of-speech tags" + }); + settings.push({ + id: "info_bgcolor_num", + kind: "color", + default: "#484848", + label: "Yomichan-like info tag background color for sense numbers" + }); + settings.push({ + id: "info_bgcolor_etc", + kind: "color", + default: "#305028", + label: "Yomichan-like info tag background color for etc tags" + }); // reader settings.push({ diff --git a/texthook.js b/texthook.js index 47bfd24..1024d7c 100644 --- a/texthook.js +++ b/texthook.js @@ -67,7 +67,18 @@ live_mining: false, use_selection: false, only_selection: false, audio_force_https: false, -highlight_dict_headers: false +highlight_dict_headers: false, +dropshadow: false, +dropshadowradius: 10, +dropshadowcolor: "#000000", +padding: 2, +novalign: 2, +inserthr: false, +info_styling: false, +info_fgcolor: "#CCCCCC", +info_bgcolor_pos: "#606060", +info_bgcolor_num: "#406080", +info_bgcolor_etc: "#608040" }; let platform = "win"; @@ -208,7 +219,7 @@ function display_div(middle, x, y) font += ","; middle.style = `background-color: ${settings.bgcolor}; border-radius: 2.5px; border: 1px solid ${settings.bgcolor};`; let border_text = (settings.disableborder)?("border: 0px solid transparent;"):(`border: 1px solid ${settings.fgcolor}`); - middle.firstChild.style = `${border_text}; border-radius: 2px; padding: 2px; background-color: ${settings.bgcolor}; color: ${settings.fgcolor}; font-family: ${font} Arial, sans-serif; text-align: left; font-size: ${settings.definition_fontsize}px;`; + middle.firstChild.style = `${border_text}; border-radius: 2px; padding: ${settings.padding}px; background-color: ${settings.bgcolor}; color: ${settings.fgcolor}; font-family: ${font} Arial, sans-serif; text-align: left; font-size: ${settings.definition_fontsize}px;`; let find_root = document.defaultView; let newx = x; @@ -272,6 +283,15 @@ function display_div(middle, x, y) styletext += `border-radius: 3px; background-color: ${settings.bgcolor}; z-index: 1000000000000000000000;`; styletext += "writing-mode: horizontal-tb; line-height: initial; white-space: initial;"; + if(settings.dropshadow) + { + let v = parseInt(settings.dropshadowcolor.substring(1), 16); + let r = Math.floor(v / 256 / 256); + let g = Math.floor(v / 256) % 256; + let b = Math.floor(v) % 256; + let rgba = "rgba(" + r + "," + g + "," + b + ",0.5)"; + styletext += `box-shadow: 0 0 ${settings.dropshadowradius}px ${rgba};` + } let other = mydoc.body.getElementsByClassName(div_class); let outer = undefined; @@ -426,7 +446,7 @@ function elementize_jmdict_defs(goodsenses) { let sense = goodsenses[j]; - if(sense.pos == lastpos) + if(sense.pos + "" == lastpos) // removing this + "" breaks repetitive sense hiding in chrome sense.pos = undefined; else lastpos = sense.pos; @@ -581,10 +601,25 @@ function get_style() font += ","; if(morefont != "") font += morefont + ","; + let valign = ".nazeka_word * {vertical-align: middle}"; + if(settings.novalign) + valign = ""; + let infostyle = ""; + if(settings.info_styling) + { + infostyle = +`.nazeka_pos, .nazeka_num, .nazeka_misc {font-size:80%; border-radius:3px; padding: 1px 3px 2px; color:${settings.info_fgcolor}; display:inline-block; position: relative; bottom: 1px; margin-bottom: -5px;} +.nazeka_pos {background-color:${settings.info_bgcolor_pos};} +.nazeka_num {background-color:${settings.info_bgcolor_num};} +.nazeka_misc {background-color:${settings.info_bgcolor_etc};} +`; + } style.textContent = `.nazeka_main_keb{font-size:${settings.dict_item_fontsize}px;white-space:nowrap;font-family: ${font}IPAGothic,TakaoGothic,Noto Sans CJK JP Regular,Meiryo,sans-serif;color:${settings.hlcolor}} .nazeka_main_reb{font-size:${settings.dict_item_fontsize}px;white-space:nowrap;font-family: ${font}IPAGothic,TakaoGothic,Noto Sans CJK JP Regular,Meiryo,sans-serif;color:${settings.hlcolor}} -.nazeka_word * {vertical-align: middle} +${valign} +${infostyle} +.${div_class} hr{margin: 0.5em; padding: 0; border: none; border-top: 1px solid ${settings.fgcolor}; opacity: 0.25} .nazeka_sub_keb{font-size:${settings.reading_fontsize}px;white-space:nowrap;font-family: ${font}IPAGothic,TakaoGothic,Noto Sans CJK JP Regular,Meiryo,sans-serif} .nazeka_sub_reb{font-size:${settings.reading_fontsize}px;white-space:nowrap;color:${settings.hlcolor2}} .nazeka_original{float: right; margin-right: 2px; margin-left:4px; opacity:0.7;} @@ -1126,9 +1161,17 @@ function build_div_compound (results, moreText, index) for(let lookup of results) { if(settings.corner == 2 || settings.corner == 3) + { + if(!first && settings.inserthr) + middle.firstChild.insertBefore(document.createElement("hr"), middle.firstChild.children[0]); middle.firstChild.insertBefore(build_div_inner(lookup.text, lookup.result, moreText, index, first), middle.firstChild.children[0]); + } else + { + if(!first && settings.inserthr) + middle.firstChild.appendChild(document.createElement("hr")); middle.firstChild.appendChild(build_div_inner(lookup.text, lookup.result, moreText, index, first)); + } first = false; } return middle; @@ -1341,6 +1384,19 @@ async function settings_init() getvar("audio_force_https"); getvar("highlight_dict_headers"); + getvar("dropshadow"); + getvar("dropshadowradius"); + getvar("dropshadowcolor"); + getvar("padding"); + getvar("novalign"); + getvar("inserthr"); + + getvar("info_styling"); + getvar("info_fgcolor"); + getvar("info_bgcolor_pos"); + getvar("info_bgcolor_num"); + getvar("info_bgcolor_etc"); + if(!settings.enabled && exists_div()) delete_div(); if(!settings.enabled)