-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighlight_selection_bookmark.js
1991 lines (1675 loc) · 52.4 KB
/
highlight_selection_bookmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
javascript: (() => {/* eslint-disable-line no-unused-labels */
const g_version = "1.4.0";
const g_debug = 0;
const g_message = "highlight_selection";
/**
* MutationObserverから起動した回数を示す変数。
* MutationObserverから起動したら+1する。
* 手動ハイライトしたら0にリセットする。
*/
let g_count_mutation_start = 0;
/**
* MutationObserverから起動する最大回数。
*/
const g_max_count_mutation_start = 10;
/**
* Copyright (c) 2013 Blake Embrey ([email protected])
* Released under the MIT license
* https://github.com/plurals/pluralize/blob/master/LICENSE
* Pluralize v8.0.0
*/
const pluralize = (() => {
/* Rule storage - pluralize and singularize need to be run sequentially,
while other rules can be optimized using an object for instant lookups. */
const pluralRules = [];
const singularRules = [];
const uncountables = {};
const irregularPlurals = {};
const irregularSingles = {};
/**
* Sanitize a pluralization rule to a usable regular expression.
*
* @param {(RegExp|string)} rule
* @return {RegExp}
*/
function sanitizeRule(rule) {
if (typeof rule === 'string') {
return new RegExp(`^${rule}$`, 'iu');
}
return rule;
}
/**
* Pass in a word token to produce a function that can replicate the case on
* another word.
*
* @param {string} word
* @param {string} token
* @return {Function}
*/
function restoreCase(word, token) {
/* Tokens are an exact match. */
if (word === token) { return token; }
/* Lower cased words. E.g. "hello". */
if (word === word.toLowerCase()) { return token.toLowerCase(); }
/* Upper cased words. E.g. "WHISKY". */
if (word === word.toUpperCase()) { return token.toUpperCase(); }
/* Title cased words. E.g. "Title". */
if (word[0] === word[0].toUpperCase()) {
return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
}
/* Lower cased words. E.g. "test". */
return token.toLowerCase();
}
/**
* Interpolate a regexp string.
*
* @param {string} str
* @param {Array} args
* @return {string}
*/
function interpolate(str, args) {
return str.replace(/\$(\d{1,2})/gu, function (match, index) {
return args[index] || '';
});
}
/**
* Replace a word using a rule.
*
* @param {string} word
* @param {Array} rule
* @return {string}
*/
function replace(word, rule) {
return word.replace(rule[0], function (match, index) {
/* eslint-disable-next-line prefer-rest-params */
const result = interpolate(rule[1], arguments);
if (match === '') {
return restoreCase(word[index - 1], result);
}
return restoreCase(match, result);
});
}
/**
* Sanitize a word by passing in the word and sanitization rules.
*
* @param {string} token
* @param {string} word
* @param {Array} rules
* @return {string}
*/
function sanitizeWord(token, word, rules) {
/* Empty string or doesn't need fixing. */
if (!token.length || Object.prototype.hasOwnProperty.call(uncountables, token)) {
return word;
}
let len = rules.length;
/* Iterate over the sanitization rules and use the first one to match. */
while (len--) {
const rule = rules[len];
if (rule[0].test(word)) { return replace(word, rule); }
}
return word;
}
/**
* Replace a word with the updated word.
*
* @param {Object} replaceMap
* @param {Object} keepMap
* @param {Array} rules
* @return {Function}
*/
function replaceWord(replaceMap, keepMap, rules) {
return function (word) {
/* Get the correct token and case restoration functions. */
const token = word.toLowerCase();
/* Check against the keep object map. */
if (Object.prototype.hasOwnProperty.call(keepMap, token)) {
return restoreCase(word, token);
}
/* Check against the replacement map for a direct word replacement. */
if (Object.prototype.hasOwnProperty.call(replaceMap, token)) {
return restoreCase(word, replaceMap[token]);
}
/* Run all the rules against the word. */
return sanitizeWord(token, word, rules);
};
}
/**
* Check if a word is part of the map.
*/
function checkWord(replaceMap, keepMap, rules) {
return function (word) {
const token = word.toLowerCase();
if (Object.prototype.hasOwnProperty.call(keepMap, token)) { return true; }
if (Object.prototype.hasOwnProperty.call(replaceMap, token)) { return false; }
return sanitizeWord(token, token, rules) === token;
};
}
/**
* Pluralize or singularize a word based on the passed in count.
*
* @param {string} word The word to pluralize
* @param {number} count How many of the word exist
* @param {boolean} inclusive Whether to prefix with the number (e.g. 3 ducks)
* @return {string}
*/
function pluralize_in(word, count, inclusive) {
const pluralized = count === 1
? pluralize_in.singular(word)
: pluralize_in.plural(word);
return (inclusive ? `${count} ` : '') + pluralized;
}
/**
* Pluralize a word.
*
* @type {Function}
*/
pluralize_in.plural = replaceWord(
irregularSingles, irregularPlurals, pluralRules
);
/**
* Check if a word is plural.
*
* @type {Function}
*/
pluralize_in.isPlural = checkWord(
irregularSingles, irregularPlurals, pluralRules
);
/**
* Singularize a word.
*
* @type {Function}
*/
pluralize_in.singular = replaceWord(
irregularPlurals, irregularSingles, singularRules
);
/**
* Check if a word is singular.
*
* @type {Function}
*/
pluralize_in.isSingular = checkWord(
irregularPlurals, irregularSingles, singularRules
);
/**
* Add a pluralization rule to the collection.
*
* @param {(string|RegExp)} rule
* @param {string} replacement
*/
pluralize_in.addPluralRule = function (rule, replacement) {
pluralRules.push([sanitizeRule(rule), replacement]);
};
/**
* Add a singularization rule to the collection.
*
* @param {(string|RegExp)} rule
* @param {string} replacement
*/
pluralize_in.addSingularRule = function (rule, replacement) {
singularRules.push([sanitizeRule(rule), replacement]);
};
/**
* Add an uncountable word rule.
*
* @param {(string|RegExp)} word
*/
pluralize_in.addUncountableRule = function (word) {
if (typeof word === 'string') {
uncountables[word.toLowerCase()] = true;
return;
}
/* Set singular and plural references for the word. */
pluralize_in.addPluralRule(word, '$0');
pluralize_in.addSingularRule(word, '$0');
};
/**
* Add an irregular word definition.
*
* @param {string} single
* @param {string} plural
*/
pluralize_in.addIrregularRule = function (single, plural) {
plural = plural.toLowerCase();
single = single.toLowerCase();
irregularSingles[single] = plural;
irregularPlurals[plural] = single;
};
/**
* Irregular rules.
*/
[
/* Pronouns. */
/* ['I', 'we'],
['me', 'us'],
['he', 'they'],
['she', 'they'], */
['them', 'them'],
['myself', 'ourselves'],
['yourself', 'yourselves'],
['itself', 'themselves'],
['herself', 'themselves'],
['himself', 'themselves'],
['themself', 'themselves'],
['is', 'are'],
['was', 'were'],
['has', 'have'],
['this', 'these'],
['that', 'those'],
/* Words ending in with a consonant and `o`. */
['echo', 'echoes'],
['dingo', 'dingoes'],
['volcano', 'volcanoes'],
['tornado', 'tornadoes'],
['torpedo', 'torpedoes'],
/* Ends with `us`. */
['genus', 'genera'],
['viscus', 'viscera'],
/* Ends with `ma`. */
['stigma', 'stigmata'],
['stoma', 'stomata'],
['dogma', 'dogmata'],
['lemma', 'lemmata'],
['schema', 'schemata'],
['anathema', 'anathemata'],
/* Other irregular rules. */
['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 (rule) {
return pluralize_in.addIrregularRule(rule[0], rule[1]);
});
/**
* Pluralization rules.
*/
[
[/s?$/iu, 's'],
/* eslint-disable-next-line no-control-regex */
[/[^\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 (rule) {
return pluralize_in.addPluralRule(rule[0], rule[1]);
});
/**
* Singularization rules.
*/
[
/* [/s$/iu, ''], */
[/(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 (rule) {
return pluralize_in.addSingularRule(rule[0], rule[1]);
});
/**
* Uncountable rules.
*/
[
/* added */
'as',
/* Singular words with no plurals. */
'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,
/* Regexes. */
/[^aeiou]ese$/iu, /* "chinese", "japanese" */
/deer$/iu, /* "deer", "reindeer" */
/fish$/iu, /* "fish", "blowfish", "angelfish" */
/measles$/iu,
/o[iu]s$/iu, /* "carnivorous" */
/pox$/iu, /* "chickpox", "smallpox" */
/sheep$/iu
].forEach(pluralize_in.addUncountableRule);
return pluralize_in;
})();
/**
* 要素が可視ならtrueを返し、非表示ならfalseを返す。
* @param {HTMLElement|null} elem
* @returns {boolean}
*/
const is_visible = (elem) => {
if (!elem) {
return false;
}
const bcr = elem.getBoundingClientRect();
if (bcr.height === 0 || bcr.width === 0) {
return false;
}
return true;
};
/**
* console.logを取り戻す。
*/
const recover_console_log = () => {
let e_iframe = document.querySelector("iframe");
if (!e_iframe) {
e_iframe = document.createElement("iframe");
if (!e_iframe) {
return;
}
e_iframe.style.display = 'none';
document.body.append(e_iframe);
}
try {
console.log = e_iframe.contentWindow?.console.log;
} catch (error) {
/* cross-origin frame */
if (g_debug) {
console.log(`${error.name}: ${error.message}`);
}
e_iframe = document.createElement("iframe");
e_iframe.style.display = 'none';
document.body.append(e_iframe);
try {
console.log = e_iframe.contentWindow?.console.log;
} catch (error2) {
/* cross-origin frame(sandbox) */
if (g_debug) {
console.log(`nested: ${error2.name}: ${error2.message}`);
}
}
}
};
/**
* 正規表現で使えうようにメタ文字をエスケープした文字列を返す。
* @param {string} s_regexp
* @returns {string}
*/
const escape_regexp = (s_regexp) => s_regexp.replace(/[()[\]{}*+.$^\\|?]/gu, '\\$&');
/**
* ターゲットノードを置換用ノードの配列と置換する。
* @param {Node} N_target
* @param {Node[]|NodeList} N_replaced_items
*/
const replace_node_with = (N_target, N_replaced_items) => {
const N_origin = N_target.previousSibling;
const e_parent = N_target.parentElement;
N_target.remove();
/* target_nodeが最初の子ノードかで分岐する。 */
if (N_origin) {
N_origin.after(...N_replaced_items);
} else {
e_parent?.prepend(...N_replaced_items);
}
};
/**
* Pluralizeを使って単数形に変換する。
*/
const singular = (s_text) => s_text.replaceAll(/[a-zA-Z]+/gu, (a) => pluralize.singular(a));
/**
* 全角から半角へ変換する。
* [A-Za-z0-9]から[!-~]へ変更して、より多くの全角文字を含めた。
* @param {string} s_text
*/
const zenkaku2hankaku = (s_text) => s_text.replace(/[!-~]/gu, (a) => String.fromCharCode(a.charCodeAt(0) - 0xFEE0));
/**
* カタカナをひらがなへ変換する。
* ゐ,ヰ→い
* ゑ,ヱ→え
* @param {string} s_text
*/
const katakana2hiragana = (s_text) => s_text.replace(/[ァ-ン]/gu, (a) => String.fromCharCode(a.charCodeAt(0) - 0x60)).replaceAll('ゐ', 'い').
replaceAll('ゑ', 'え');
const kanjinumber2number_table = {
'一': 1,
'二': 2,
'三': 3,
'四': 4,
'五': 5,
'六': 6,
'七': 7,
'八': 8,
'九': 9
};
/**
* 漢数字を半角数値に変換する。
* @param {string} s_text
* @returns {string}
*/
const kanjinumber2number = (s_text) => s_text.replace(/[一二三四五六七八九]/gu, (a) => kanjinumber2number_table[a]);
/**
* 引数の文字列を単数形にして、空白文字を除いて、全角を半角にして、カタカナをひらがなにして、漢数字を半角数値にして、小文字に変換する。
* (注)空白を除いた後に単数形にできない。
* @param {string|null} s_text
* @returns {string}
*/
const remove_white_spaces_hankaku = (s_text) => kanjinumber2number(katakana2hiragana(zenkaku2hankaku(singular(s_text).replaceAll(/\s+/gu, '')))).toLowerCase();
/**
* textContentに空白文字(\s)が存在することと、単数形・複数形の文字数差を考慮した位置を返す。
* @param {number} n_position
* @param {string} textContent_arg
* @param {{f_include_end_spaces?: boolean}} param2 f_include_end_spacesがtrueなら範囲の後の空白文字を含む。
* @returns {number}
*/
const get_adjusted_position = (n_position, textContent_arg, { f_include_end_spaces = false } = {}) => {
const a_convert_items = textContent_arg.split(/([^a-zA-Z]+)/u).map((a) => [a.length, singular(a).length]);
const textContent = singular(textContent_arg);
let n_spaces = textContent.substring(0, n_position).match(/\s/gu)?.length ?? 0;
let n_cursor = n_position;
let s_cursor;
while (n_spaces) {
s_cursor = textContent[n_cursor];
if (!/^\s$/u.test(s_cursor)) {
n_spaces -= 1;
}
n_cursor += 1;
}
if (f_include_end_spaces) {
s_cursor = textContent[n_cursor];
for (; /^\s$/u.test(s_cursor);) {
n_cursor += 1;
s_cursor = textContent[n_cursor];
}
}
let n_cursor_org = n_cursor;
let n_sum = 0;
for (let index = 0; index < a_convert_items.length; index++) {
const a_convert_item = a_convert_items[index];
n_sum += a_convert_item[1];
if (n_sum > n_cursor) {
break;
}
n_cursor_org += a_convert_item[0] - a_convert_item[1];
}
return n_cursor_org;
};
/**
* スタイルシートを追加する。
*/
const add_style_sheet = () => {
const e_style = document.querySelector('#highlight_selection_style');
if (e_style) {
return;
}
document.head.insertAdjacentHTML('beforeend', `
<style id="highlight_selection_style">
.highlight_selection:not(#a) {
position: relative;
padding: 2px 0;
font-style: normal;
line-height: inherit;
background: revert;
text-shadow: initial;
font-size: inherit;
}
.highlight_selection[data-s_count_highlights="1"] {
opacity: 0.8;
outline: 4px dashed pink!important;
}
/* .highlight_selection[data-s_count_highlights="1"]のopacityがStacking contextを作ってz-indexに影響するため。 */
.highlight_selection:hover {
z-index: 1000000000;
}
.highlight_selection:hover:before {
position: absolute;
top: 100%;
left: 50%;
transform: translate(-50%);
color: white;
font-size: .8rem;
background-color: #645b5b;
padding: .3rem .6rem;
border-radius: 3px;
margin-top: 3px;
z-index: 1000000000;
content: attr(data-s_count_highlights);
letter-spacing: 0;
text-indent: 0;
line-height: initial;
width: max-content;
}
.highlight_selection_close:not(#a) {
position: absolute;
left: -5px;
top: -5px;
background-color: white;
color: black;
border: 1px solid;
user-select: none;
line-height: 0;
text-indent: 0;
padding: 0;
margin: 0;
width: auto;
}
.highlight_selection_close:hover:not(#a) {
color: white;
background-color: hotpink;
cursor: pointer;
}
.highlight_selection_close_svg:not(#a) {
width: 10px;
height: 10px;
fill: currentColor;
max-width: unset;
margin: 0;
padding: 0;
}
.highlight_selection_0 {
color: yellow !important;
background-color: red !important;
}
.highlight_selection_1 {
color: #ffff91 !important;
background-color: #2091eb !important;
}
.highlight_selection_2 {
color: #b3fcff !important;
background-color: #085230 !important;
}
.highlight_selection_3 {
color: blue !important;
background-color: orange !important;
}
.highlight_selection_4 {
color: #eee113 !important;
background-color: #6c0570 !important;
}
.highlight_selection_5 {
color: #fdcfe7 !important;
background-color: #006899 !important;
}
.highlight_selection_6 {
color: lightpink !important;
background-color: blue !important;
}
.highlight_selection_7 {
color: #c2ffd9 !important;
background-color: #e00079 !important;
}
.highlight_selection_8 {
color: #e1ff92 !important;
background-color: #1bbb04 !important;
}
.highlight_selection_9 {
color: #10a235 !important;
background-color: #e9df27 !important;
}
.highlight_selection_10 {
color: #f4d83f !important;
background-color: #904f40 !important;
}
.highlight_selection_11 {
color: #cefff6 !important;
background-color: #1a4db6 !important;
}
.highlight_selection_12 {
color: #321a93 !important;
background-color: #f78be0 !important;
}
.highlight_selection_13 {
color: #dfffad !important;
background-color: #8338ec !important;
}
.highlight_selection_14 {
color: #e4ffde !important;
background-color: #cf5a3e !important;
}
.highlight_selection_15 {
color: #f2e038 !important;
background-color: #0086a4 !important;
}
.highlight_selection_16 {
color: #e8fff8 !important;
background-color: #f75454 !important;
}
.highlight_selection_17 {
color: #69370b !important;
background-color: #f4dc02 !important;
}
.highlight_selection_18 {
color: #ddf1ff !important;
background-color: #87322a !important;
}
.highlight_selection_19 {
color: #f3f3ff !important;
background-color: #5b8db5 !important;
}
.highlight_selection_20 {
color: #4c02f9 !important;
background-color: #8ffca0 !important;
}
.highlight_selection_21 {
color: cyan !important;
background-color: red !important;
}
.highlight_selection_22 {
color: #f0ffed !important;
background-color: #744e67 !important;
}
.highlight_selection_23 {
color: #ffeeee !important;
background-color: #18b7cf !important;
}
.highlight_selection_24 {
color: #03ac6b !important;
background-color: #f7f5e1 !important;
}
.highlight_selection_25 {
color: #e5f7ff !important;
background-color: #f29f18 !important;
}
.highlight_selection_26 {
color: #3789f1 !important;
background-color: #f7f701 !important;
}
.highlight_selection_27 {
color: #fff2d6 !important;
background-color: #ed5b9d !important;
}
.highlight_selection_28 {
color: #7f82c5 !important;
background-color: #e2e3f7 !important;
}
.highlight_selection_29 {
color: #007a65 !important;
background-color: #f7bf61 !important;
}
.highlight_selection_30 {
color: #ed0597 !important;
background-color: #d0f5f7 !important;
}
.highlight_selection_31 {
color: #2884b3 !important;
background-color: #f7c8ca !important;
}
.highlight_selection_32 {
color: #000091 !important;
background-color: #f3dfe9 !important;
}
.highlight_selection_33 {
color: #73fa79 !important;
background-color: black !important;
}
.highlight_selection_34 {
color: #fffb00 !important;
background-color: #8881f0 !important;
}
.highlight_selection_35 {
color: #f7b0b0 !important;
background-color: #053530 !important;
}
</style>`);
};
/**
* 再利用するためにsvgを追加する
*/
const add_svg_template = () => {
const e_svg_template = document.querySelector('#highlight_selection_svg_template');
if (e_svg_template) {
return;
}
document.body.insertAdjacentHTML('afterbegin',
`<svg xmlns="http://www.w3.org/2000/svg" style="display:none;" id="highlight_selection_svg_template">
<symbol viewBox="0 0 32 32" id="highlight_selection_close_xlink">
<path d="m32 4-4-4-12 12L4 0 0 4l12 12L0 28l4 4 12-12 12 12 4-4-12-12z"/>
</symbol>
</svg>`);
};
/**
* 深さ優先探索をして可視テキストを返す
* @param {HTMLElement|Node} e_arg
* @param {string[]} s_texts
* @param {Range} r_selection
* @returns
*/
const get_visible_text_dfs = (e_arg, s_texts, r_selection) => {
switch (e_arg.nodeType) {
case Node.ELEMENT_NODE: {
if (['SCRIPT', 'STYLE'].includes(e_arg.nodeName.toLocaleUpperCase())) {
return;
}
const e_childNodes = e_arg.childNodes;
for (let index = 0; index < e_childNodes.length; index++) {
const e_childNode = e_childNodes[index];
get_visible_text_dfs(e_childNode, s_texts, r_selection);
}