-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighlight_selection_bookmark_min.js
More file actions
1 lines (1 loc) · 20.9 KB
/
highlight_selection_bookmark_min.js
File metadata and controls
1 lines (1 loc) · 20.9 KB
1
javascript:(()=>{let e=0;const t=(()=>{const e=[],t=[],n={},o={},i={};function r(e){return"string"==typeof e?new RegExp(`^${e}$`,"iu"):e}function l(e,t){return e===t?t:e===e.toLowerCase()?t.toLowerCase():e===e.toUpperCase()?t.toUpperCase():e[0]===e[0].toUpperCase()?t.charAt(0).toUpperCase()+t.substr(1).toLowerCase():t.toLowerCase()}function s(e,t){return e.replace(t[0],(function(n,o){const i=(r=t[1],s=arguments,r.replace(/\$(\d{1,2})/gu,(function(e,t){return s[t]||""})));var r,s;return l(""===n?e[o-1]:n,i)}))}function c(e,t,o){if(!e.length||Object.prototype.hasOwnProperty.call(n,e))return t;let i=o.length;for(;i--;){const e=o[i];if(e[0].test(t))return s(t,e)}return t}function a(e,t,n){return function(o){const i=o.toLowerCase();return Object.prototype.hasOwnProperty.call(t,i)?l(o,i):Object.prototype.hasOwnProperty.call(e,i)?l(o,e[i]):c(i,o,n)}}function h(e,t,n){return function(o){const i=o.toLowerCase();return!!Object.prototype.hasOwnProperty.call(t,i)||!Object.prototype.hasOwnProperty.call(e,i)&&c(i,i,n)===i}}function u(e,t,n){return(n?`${t} `:"")+(1===t?u.singular(e):u.plural(e))}return u.plural=a(i,o,e),u.isPlural=h(i,o,e),u.singular=a(o,i,t),u.isSingular=h(o,i,t),u.addPluralRule=function(t,n){e.push([r(t),n])},u.addSingularRule=function(e,n){t.push([r(e),n])},u.addUncountableRule=function(e){"string"!=typeof e?(u.addPluralRule(e,"$0"),u.addSingularRule(e,"$0")):n[e.toLowerCase()]=!0},u.addIrregularRule=function(e,t){t=t.toLowerCase(),e=e.toLowerCase(),i[e]=t,o[t]=e},[["them","them"],["myself","ourselves"],["yourself","yourselves"],["itself","themselves"],["herself","themselves"],["himself","themselves"],["themself","themselves"],["is","are"],["was","were"],["has","have"],["this","these"],["that","those"],["echo","echoes"],["dingo","dingoes"],["volcano","volcanoes"],["tornado","tornadoes"],["torpedo","torpedoes"],["genus","genera"],["viscus","viscera"],["stigma","stigmata"],["stoma","stomata"],["dogma","dogmata"],["lemma","lemmata"],["schema","schemata"],["anathema","anathemata"],["ox","oxen"],["axe","axes"],["die","dice"],["yes","yeses"],["foot","feet"],["eave","eaves"],["goose","geese"],["tooth","teeth"],["quiz","quizzes"],["human","humans"],["proof","proofs"],["carve","carves"],["valve","valves"],["looey","looies"],["thief","thieves"],["groove","grooves"],["pickaxe","pickaxes"],["passerby","passersby"]].forEach((function(e){return u.addIrregularRule(e[0],e[1])})),[[/s?$/iu,"s"],[/[^\u0000-\u007F]$/iu,"$0"],[/([^aeiou]ese)$/iu,"$1"],[/(ax|test)is$/iu,"$1es"],[/(alias|[^aou]us|t[lm]as|gas|ris)$/iu,"$1es"],[/(e[mn]u)s?$/iu,"$1s"],[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/iu,"$1"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/iu,"$1i"],[/(alumn|alg|vertebr)(?:a|ae)$/iu,"$1ae"],[/(seraph|cherub)(?:im)?$/iu,"$1im"],[/(her|at|gr)o$/iu,"$1oes"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/iu,"$1a"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/iu,"$1a"],[/sis$/iu,"ses"],[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/iu,"$1$2ves"],[/([^aeiouy]|qu)y$/iu,"$1ies"],[/([^ch][ieo][ln])ey$/iu,"$1ies"],[/(x|ch|ss|sh|zz)$/iu,"$1es"],[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/iu,"$1ices"],[/\b((?:tit)?m|l)(?:ice|ouse)$/iu,"$1ice"],[/(pe)(?:rson|ople)$/iu,"$1ople"],[/(child)(?:ren)?$/iu,"$1ren"],[/eaux$/iu,"$0"],[/m[ae]n$/iu,"men"],["thou","you"]].forEach((function(e){return u.addPluralRule(e[0],e[1])})),[[/(ss)$/iu,"$1"],[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/iu,"$1fe"],[/(ar|(?:wo|[ae])l|[eo][ao])ves$/iu,"$1f"],[/ies$/iu,"y"],[/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/iu,"$1ie"],[/\b(mon|smil)ies$/iu,"$1ey"],[/\b((?:tit)?m|l)ice$/iu,"$1ouse"],[/(seraph|cherub)im$/iu,"$1"],[/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/iu,"$1"],[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/iu,"$1sis"],[/(movie|twelve|abuse|e[mn]u)s$/iu,"$1"],[/(test)(?:is|es)$/iu,"$1is"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/iu,"$1us"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/iu,"$1um"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/iu,"$1on"],[/(alumn|alg|vertebr)ae$/iu,"$1a"],[/(cod|mur|sil|vert|ind)ices$/iu,"$1ex"],[/(matr|append)ices$/iu,"$1ix"],[/(pe)(rson|ople)$/iu,"$1rson"],[/(child)ren$/iu,"$1"],[/(eau)x?$/iu,"$1"],[/men$/iu,"man"]].forEach((function(e){return u.addSingularRule(e[0],e[1])})),["as","adulthood","advice","agenda","aid","aircraft","alcohol","ammo","analytics","anime","athletics","audio","bison","blood","bream","buffalo","butter","carp","cash","chassis","chess","clothing","cod","commerce","cooperation","corps","debris","diabetes","digestion","elk","energy","equipment","excretion","expertise","firmware","flounder","fun","gallows","garbage","graffiti","hardware","headquarters","health","herpes","highjinks","homework","housework","information","jeans","justice","kudos","labour","literature","machinery","mackerel","mail","media","mews","moose","music","mud","manga","news","only","personnel","pike","plankton","pliers","police","pollution","premises","rain","research","rice","salmon","scissors","series","sewage","shambles","shrimp","software","species","staff","swine","tennis","traffic","transportation","trout","tuna","wealth","welfare","whiting","wildebeest","wildlife","you",/pok[eé]mon$/iu,/[^aeiou]ese$/iu,/deer$/iu,/fish$/iu,/measles$/iu,/o[iu]s$/iu,/pox$/iu,/sheep$/iu].forEach(u.addUncountableRule),u})(),n=e=>{if(!e)return!1;const t=e.getBoundingClientRect();return 0!==t.height&&0!==t.width},o=(e,t)=>{const n=e.previousSibling,o=e.parentElement;e.remove(),n?n.after(...t):o?.prepend(...t)},i=e=>e.replaceAll(/[a-zA-Z]+/gu,(e=>t.singular(e))),r={一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},l=e=>(e=>e.replace(/[一二三四五六七八九]/gu,(e=>r[e])))((e=>e.replace(/[ァ-ン]/gu,(e=>String.fromCharCode(e.charCodeAt(0)-96))).replaceAll("ゐ","い").replaceAll("ゑ","え"))((e=>e.replace(/[!-~]/gu,(e=>String.fromCharCode(e.charCodeAt(0)-65248))))(i(e).replaceAll(/\s+/gu,"")))).toLowerCase(),s=(e,t,{f_include_end_spaces:n=!1}={})=>{const o=t.split(/([^a-zA-Z]+)/u).map((e=>[e.length,i(e).length])),r=i(t);let l,s=r.substring(0,e).match(/\s/gu)?.length??0,c=e;for(;s;)l=r[c],/^\s$/u.test(l)||(s-=1),c+=1;if(n)for(l=r[c];/^\s$/u.test(l);)c+=1,l=r[c];let a=c,h=0;for(let e=0;e<o.length;e++){const t=o[e];if(h+=t[1],h>c)break;a+=t[0]-t[1]}return a},c=(e,t,o)=>{switch(e.nodeType){case Node.ELEMENT_NODE:{if(["SCRIPT","STYLE"].includes(e.nodeName.toLocaleUpperCase()))return;const n=e.childNodes;for(let e=0;e<n.length;e++){const i=n[e];c(i,t,o)}break}case Node.TEXT_NODE:{if(!n(e.parentElement))return;const i=e.textContent;if(!i)return;let r=!1,l=0,s=i.length;if(e===o.startContainer&&(l=o.startOffset,r=!0),e===o.endContainer&&(s=o.endOffset,r=!0),r)t.push(i.substring(l,s));else{if(!o.isPointInRange(e,0))return;t.push(i)}break}}},a=(e,t)=>{switch(e.nodeType){case Node.ELEMENT_NODE:{if(["SCRIPT","STYLE"].includes(e.nodeName.toLocaleUpperCase()))return;const n=e.contentDocument?.body?.childNodes;if(n)for(let e=0;e<n.length;e++){const o=n[e];a(o,t)}const o=e.childNodes;for(let e=0;e<o.length;e++){const n=o[e];a(n,t)}break}case Node.TEXT_NODE:{if(!n(e.parentElement))return;const o=l(e.textContent);if(""===o)return;t.push({s_text:o,node:e});break}}},h=(e,t,{f_return_object:n=!1,f_is_end:o=!1}={})=>{for(let i=0;i<t.length;i++){const r=t[i];if(o?r.index_to>=e:r.index_to>e)return n?r:i}throw new Error(`not found at get_text_object(${e}) `)},u=(e,t)=>1===e?"1":`${e} (↑${t}↓${e-t-1})`,g=(e,t,n,o,i)=>{const{n_counter2:r}=i,l=t%n,s=document.createElement("mark");return s.classList.add("highlight_selection",`highlight_selection_${l}`,`highlight_selection_serial_${t}`),s.textContent=e,s.dataset.s_count_highlights=u(o,r),s},d=(e,t,n,o)=>{const i=[],{node:r}=e,{textContent:l}=r,c=e.custom_ranges.sort(((e,t)=>e.start>t.start?1:-1));let a,h,u=0;for(let e=0;e<c.length;e++){a=c[e],h=l.substring(u,s(a.start,l,{f_include_end_spaces:!0})),""!==h&&i.push(document.createTextNode(h));const r=s(a.end,l);h=l.substring(s(a.start,l,{f_include_end_spaces:!0}),r),i.push(g(h,t,n,o,a)),u=r}return h=l.substring(s(a.end,l)),""!==h&&i.push(document.createTextNode(h)),i},_=e=>1===e.custom_ranges.length&&e.custom_ranges[0].f_is_highlighted&&e.custom_ranges[0].f_is_equal_text,m=(e,t,n)=>{const{n_counter2:o}=n.custom_ranges[0];e.dataset.s_count_highlights=u(t,o)},p=(e,t)=>{const n=[];a(document.body,n),(e=>{let t=0;for(let n=0;n<e.length;n++){const o=e[n];o.index_from=t;const{s_text:i}=o,r=i.length;o.index_to=t+r,t+=r}})(n);const i=((e,t)=>{const n=new RegExp(e.replace(/[()[\]{}*+.$^\\|?]/gu,"\\$&"),"gui");return[...t.matchAll(n)].map((e=>e.index))})(e,n.map((e=>e.s_text)).join("")),r=((e,t,n)=>{const o=[];for(let i=0;i<e.length;i++){const r=e[i],l=h(r,t),s=h(r+n,t,{f_is_end:!0}),c={start:{index:l,pos:r-t[l].index_from},end:{index:s,pos:r+n-t[s].index_from},n_counter:i};o.push(c)}return o})(i,n,e.length),s=((e,t,n,o,i)=>{const r=new Map;for(let s=0;s<e.length;s++){const c=e[s],a=c.start.index,h=c.end.index;for(let e=a;e<=h;e++){const s=t[e],{node:u}=s;let g;const d=Boolean(u.parentElement.closest(".highlight_selection")),_=l(u.textContent)===o,m=u.parentElement.classList?.contains(`highlight_selection_serial_${i}`);if(!d||_||m)switch(r.has(u)?g=r.get(u):(g={node:u,custom_ranges:[]},r.set(u,g)),e){case a:g.custom_ranges.push({start:c.start.pos,end:Math.min(s.s_text.length,c.start.pos+n),n_counter:c.n_counter,f_is_highlighted:d,f_is_equal_text:_});break;case h:g.custom_ranges.push({start:0,end:c.end.pos,n_counter:c.n_counter,f_is_highlighted:d,f_is_equal_text:_});break;default:g.custom_ranges.push({start:0,end:s.s_text.length,n_counter:c.n_counter,f_is_highlighted:d,f_is_equal_text:_})}}}return r})(r,n,e.length,e,t),c=[...s.values()],u=document.querySelector("#highlight_selection_style").textContent.match(/highlight_selection_\d+/gu).length,g=(e=>{let t=-1,n=-1;for(let o=0;o<e.length;o++){const i=e[o].custom_ranges;for(let e=0;e<i.length;e++){const o=i[e];o.n_counter>t?(t=o.n_counter,n++,o.n_counter2=n):o.n_counter2=n}}return n+1})(c);for(let e=0;e<c.length;e++){const n=c[e];if(_(n)){const e=n.node.parentElement.closest(".highlight_selection");m(e,g,n);continue}const i=d(n,t,u,g);i.length&&o(n.node,i)}},f=e=>{const t=`.highlight_selection_serial_${e}`,n=document.querySelector(t);if(!n)return;const o=l(n.textContent);p(o,e)},b=()=>{if(Object.hasOwn(window,"M_highlight_selection_observer_controller")&&window.M_highlight_selection_observer_controller.disconnect(),void 0===document.documentElement.dataset.n_highlight_selection_serial_color_current)return;const e=Number(document.documentElement.dataset.n_highlight_selection_serial_color_current);for(let t=0;t<=e;t++)f(t);Object.hasOwn(window,"M_highlight_selection_observer_controller")&&window.M_highlight_selection_observer_controller.reconnect()},$=()=>{console.log("highlight_selection_bookmark.js: v1.4.0"),e=0,Object.hasOwn(window,"M_highlight_selection_observer_controller")&&window.M_highlight_selection_observer_controller.disconnect(),(()=>{let e=document.querySelector("iframe");if(!e){if(e=document.createElement("iframe"),!e)return;e.style.display="none",document.body.append(e)}try{console.log=e.contentWindow?.console.log}catch(t){e=document.createElement("iframe"),e.style.display="none",document.body.append(e);try{console.log=e.contentWindow?.console.log}catch(e){}}})(),document.querySelector("#highlight_selection_style")||document.head.insertAdjacentHTML("beforeend",'\n<style id="highlight_selection_style">\n.highlight_selection:not(#a) {\n\tposition: relative;\n\tpadding: 2px 0;\n\tfont-style: normal;\n\tline-height: inherit;\n\tbackground: revert;\n\ttext-shadow: initial;\n\tfont-size: inherit;\n}\n\n.highlight_selection[data-s_count_highlights="1"] {\n\topacity: 0.8;\n outline: 4px dashed pink!important;\n}\n\n/* .highlight_selection[data-s_count_highlights="1"]のopacityがStacking contextを作ってz-indexに影響するため。 */\n.highlight_selection:hover {\n\tz-index: 1000000000;\n}\n\n.highlight_selection:hover:before {\n position: absolute;\n\ttop: 100%;\n left: 50%;\n transform: translate(-50%);\n color: white;\n font-size: .8rem;\n background-color: #645b5b;\n padding: .3rem .6rem;\n border-radius: 3px;\n margin-top: 3px;\n\tz-index: 1000000000;\n\tcontent: attr(data-s_count_highlights);\n letter-spacing: 0;\n text-indent: 0;\n line-height: initial;\n\twidth: max-content;\n}\n\n.highlight_selection_close:not(#a) {\n\tposition: absolute;\n\tleft: -5px;\n\ttop: -5px;\n\tbackground-color: white;\n\tcolor: black;\n\tborder: 1px solid;\n\tuser-select: none;\n\tline-height: 0;\n\ttext-indent: 0;\n\tpadding: 0;\n margin: 0;\n width: auto;\n}\n\n.highlight_selection_close:hover:not(#a) {\n\tcolor: white;\n\tbackground-color: hotpink;\n\tcursor: pointer;\n}\n\n.highlight_selection_close_svg:not(#a) {\n\twidth: 10px;\n\theight: 10px;\n\tfill: currentColor;\n\tmax-width: unset;\n\tmargin: 0;\n\tpadding: 0;\n}\n\n.highlight_selection_0 {\n\tcolor: yellow !important;\n\tbackground-color: red !important;\n}\n\n.highlight_selection_1 {\n\tcolor: #ffff91 !important;\n\tbackground-color: #2091eb !important;\n}\n\n.highlight_selection_2 {\n\tcolor: #b3fcff !important;\n\tbackground-color: #085230 !important;\n}\n\n.highlight_selection_3 {\n\tcolor: blue !important;\n\tbackground-color: orange !important;\n}\n\n.highlight_selection_4 {\n\tcolor: #eee113 !important;\n\tbackground-color: #6c0570 !important;\n}\n\n.highlight_selection_5 {\n\tcolor: #fdcfe7 !important;\n\tbackground-color: #006899 !important;\n}\n\n.highlight_selection_6 {\n\tcolor: lightpink !important;\n\tbackground-color: blue !important;\n}\n\n.highlight_selection_7 {\n\tcolor: #c2ffd9 !important;\n\tbackground-color: #e00079 !important;\n}\n\n.highlight_selection_8 {\n\tcolor: #e1ff92 !important;\n\tbackground-color: #1bbb04 !important;\n}\n\n.highlight_selection_9 {\n\tcolor: #10a235 !important;\n\tbackground-color: #e9df27 !important;\n}\n\n.highlight_selection_10 {\n\tcolor: #f4d83f !important;\n\tbackground-color: #904f40 !important;\n}\n\n.highlight_selection_11 {\n\tcolor: #cefff6 !important;\n\tbackground-color: #1a4db6 !important;\n}\n\n.highlight_selection_12 {\n\tcolor: #321a93 !important;\n\tbackground-color: #f78be0 !important;\n}\n\n.highlight_selection_13 {\n\tcolor: #dfffad !important;\n\tbackground-color: #8338ec !important;\n}\n\n.highlight_selection_14 {\n\tcolor: #e4ffde !important;\n\tbackground-color: #cf5a3e !important;\n}\n\n.highlight_selection_15 {\n\tcolor: #f2e038 !important;\n\tbackground-color: #0086a4 !important;\n}\n\n.highlight_selection_16 {\n\tcolor: #e8fff8 !important;\n\tbackground-color: #f75454 !important;\n}\n\n.highlight_selection_17 {\n\tcolor: #69370b !important;\n\tbackground-color: #f4dc02 !important;\n}\n\n.highlight_selection_18 {\n\tcolor: #ddf1ff !important;\n\tbackground-color: #87322a !important;\n}\n\n.highlight_selection_19 {\n\tcolor: #f3f3ff !important;\n\tbackground-color: #5b8db5 !important;\n}\n\n.highlight_selection_20 {\n\tcolor: #4c02f9 !important;\n\tbackground-color: #8ffca0 !important;\n}\n\n.highlight_selection_21 {\n\tcolor: cyan !important;\n\tbackground-color: red !important;\n}\n\n.highlight_selection_22 {\n\tcolor: #f0ffed !important;\n\tbackground-color: #744e67 !important;\n}\n\n.highlight_selection_23 {\n\tcolor: #ffeeee !important;\n\tbackground-color: #18b7cf !important;\n}\n\n.highlight_selection_24 {\n\tcolor: #03ac6b !important;\n\tbackground-color: #f7f5e1 !important;\n}\n\n.highlight_selection_25 {\n\tcolor: #e5f7ff !important;\n\tbackground-color: #f29f18 !important;\n}\n\n.highlight_selection_26 {\n\tcolor: #3789f1 !important;\n\tbackground-color: #f7f701 !important;\n}\n\n.highlight_selection_27 {\n\tcolor: #fff2d6 !important;\n\tbackground-color: #ed5b9d !important;\n}\n\n.highlight_selection_28 {\n\tcolor: #7f82c5 !important;\n\tbackground-color: #e2e3f7 !important;\n}\n\n.highlight_selection_29 {\n\tcolor: #007a65 !important;\n\tbackground-color: #f7bf61 !important;\n}\n\n.highlight_selection_30 {\n\tcolor: #ed0597 !important;\n\tbackground-color: #d0f5f7 !important;\n}\n\n.highlight_selection_31 {\n\tcolor: #2884b3 !important;\n\tbackground-color: #f7c8ca !important;\n}\n\n.highlight_selection_32 {\n\tcolor: #000091 !important;\n\tbackground-color: #f3dfe9 !important;\n}\n\n.highlight_selection_33 {\n\tcolor: #73fa79 !important;\n\tbackground-color: black !important;\n}\n\n.highlight_selection_34 {\n\tcolor: #fffb00 !important;\n\tbackground-color: #8881f0 !important;\n}\n\n.highlight_selection_35 {\n\tcolor: #f7b0b0 !important;\n\tbackground-color: #053530 !important;\n}\n</style>'),document.querySelector("#highlight_selection_svg_template")||document.body.insertAdjacentHTML("afterbegin",'<svg xmlns="http://www.w3.org/2000/svg" style="display:none;" id="highlight_selection_svg_template">\n<symbol viewBox="0 0 32 32" id="highlight_selection_close_xlink">\n<path d="m32 4-4-4-12 12L4 0 0 4l12 12L0 28l4 4 12-12 12 12 4-4-12-12z"/>\n</symbol>\n</svg>');const t=(()=>{const e=getSelection();if(!e||!e.rangeCount)return;const t=(e=>{const t=[];return c(e.commonAncestorContainer,t,e),l(t.join(""))})(e.getRangeAt(0));return""!==t?t:void 0})();if(!t)return;const n=(()=>{const e=document.documentElement.dataset.n_highlight_selection_serial_color_current;return void 0!==e?Number(e)+1:0})();p(t,n),(()=>{let e;document.documentElement.dataset.n_highlight_selection_serial_color_current||(document.addEventListener("mouseover",(t=>{const n=t.target;if(!n)throw new Error("!e_target at c_mouseover");if(n.classList.contains("highlight_selection")){if(t.stopPropagation(),t.stopImmediatePropagation(),clearTimeout(e),(e=>e.lastElementChild?.classList.contains("highlight_selection_close"))(n))return;document.querySelectorAll(".highlight_selection_close").forEach((e=>e.remove())),n.insertAdjacentHTML("beforeend",'<span class="highlight_selection_close"><svg class="highlight_selection_close_svg"><use xlink:href="#highlight_selection_close_xlink"/></svg></span>');const i=n.querySelector(".highlight_selection_close");if(!i)throw new Error("Unexpected e_close. Never here.");const r=e=>{if(0!==e.button)return;e.stopPropagation(),e.stopImmediatePropagation();const t=i.closest(".highlight_selection");if(!t)throw new Error("Unexpected e_highlight_selection. Never here.");Object.hasOwn(window,"M_highlight_selection_observer_controller")&&window.M_highlight_selection_observer_controller.disconnect(),i.remove(),(e=>{const t=e.className.match(/\bhighlight_selection_serial_(\d+)\b/u)[1],n=document.querySelectorAll(`.highlight_selection_serial_${t}`);for(let e=0;e<n.length;e++){const i=n[e];if(!i.isConnected)continue;if(!i.parentElement)return void console.log("e_item.parentElement not found",i.parentElement);let r=null;const l=[...i.parentElement.childNodes];for(let e=0;e<l.length;e++){const n=l[e];n.classList?.contains(`highlight_selection_serial_${t}`)?1===n.childNodes.length&&n.firstChild.nodeType===Node.TEXT_NODE?(r?r.textContent+=n.textContent:(r=n.lastChild,o(n,n.childNodes),r.nodeType!==Node.TEXT_NODE&&(r=null)),n.remove()):(o(n,n.childNodes),r=null):n.nodeType===Node.TEXT_NODE?r?(r.textContent+=n.textContent,n.remove()):r=n:r=null}}if(document.documentElement.dataset.n_highlight_selection_serial_color_current===t){const e=Number(t);document.documentElement.dataset.n_highlight_selection_serial_color_current=String(e-1)}})(t),b(),Object.hasOwn(window,"M_highlight_selection_observer_controller")&&window.M_highlight_selection_observer_controller.reconnect()};i.addEventListener("mousedown",r,{capture:!0});const l=e=>{n.removeEventListener("mouseleave",e),i.removeEventListener("mousedown",r,{capture:!0}),i.remove()},s=()=>{e=setTimeout((()=>l(s)),500)};n.addEventListener("mouseleave",s)}}),{capture:!0}),document.addEventListener("dblclick",(e=>{const t=e.target?.closest(".highlight_selection");if(!t)return;e.preventDefault();const n=getSelection();n?.selectAllChildren(t)}),{capture:!0}))})(),(t=>{document.documentElement.dataset.n_highlight_selection_serial_color_current=String(t),getSelection()?.empty(),Object.hasOwn(window,"M_highlight_selection_observer_controller")&&window.M_highlight_selection_observer_controller.reconnect(),Object.hasOwn(window,"M_highlight_selection_observer_controller")||(window.M_highlight_selection_observer_controller=((t,n=2e3,o=document)=>{let i=null;const r={attributes:!1,characterData:!1,childList:!0,subtree:!0},l=new MutationObserver((o=>{o.every((e=>0===e.addedNodes.length))||o.some((e=>e.addedNodes[0]?.className?.toLowerCase().includes("highlight_selection")))||"fixed"!==o[0]?.addedNodes[0]?.style?.position&&(clearTimeout(i),e<10&&(i=setTimeout((()=>{t(),e+=1}),n)))}));return l.observe(o,r),{disconnect:()=>{l.disconnect()},reconnect:()=>{l.observe(o,r)}}})(b))})(n)};"undefined"==typeof chrome||void 0===chrome.runtime?$():chrome.runtime.onMessage.addListener(((e,t,n)=>{"highlight_selection"===e&&($(),n("done"))}))})();