mirror of
https://github.com/obsqrbtz/goose-highlighter.git
synced 2026-04-09 12:37:48 +03:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ef21d0975 | ||
| ae1cf48c53 | |||
| bca37e690f | |||
|
|
50c3facfae |
23
CHANGELOG.md
23
CHANGELOG.md
@@ -1,3 +1,26 @@
|
|||||||
|
## [1.7.1](https://github.com/obsqrbtz/goose-highlighter/compare/v1.7.0...v1.7.1) (2025-06-27)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* unicode support in regex ([ae1cf48](https://github.com/obsqrbtz/goose-highlighter/commit/ae1cf48c53cd42e65279cf2acde1a2860d8a31ee))
|
||||||
|
|
||||||
|
# [1.7.0](https://github.com/obsqrbtz/goose-highlighter/compare/v1.6.0...v1.7.0) (2025-06-26)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* colorbox styling ([1e704b5](https://github.com/obsqrbtz/goose-highlighter/commit/1e704b51a859845e539224aeb389a4e493d64520))
|
||||||
|
* colorbox styling ([08ad7c4](https://github.com/obsqrbtz/goose-highlighter/commit/08ad7c432541ea4240dec05a340ad0b3279ce82f))
|
||||||
|
* moved import/export to options section ([fe15965](https://github.com/obsqrbtz/goose-highlighter/commit/fe15965e89e8483f6b96eb779617053664c9d5b1))
|
||||||
|
* wordlist scrollbar styling ([b30fac5](https://github.com/obsqrbtz/goose-highlighter/commit/b30fac5deda7941035d8ae23001c998c2584c03e))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add word search ([80d4bff](https://github.com/obsqrbtz/goose-highlighter/commit/80d4bff0b4ef7c9e97506d1fe43a827bcc4b28fd))
|
||||||
|
* added matching flags ([759307f](https://github.com/obsqrbtz/goose-highlighter/commit/759307f9834a2bbb23e963e2042b7d41d5cfda44))
|
||||||
|
|
||||||
# [1.6.0](https://github.com/obsqrbtz/goose-highlighter/compare/v1.5.0...v1.6.0) (2025-06-25)
|
# [1.6.0](https://github.com/obsqrbtz/goose-highlighter/compare/v1.5.0...v1.6.0) (2025-06-25)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
27
main.js
27
main.js
@@ -60,29 +60,38 @@ function processNodes() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeWords.length > 0) {
|
if (activeWords.length > 0) {
|
||||||
const wordMap = new Map();
|
const wordMap = new Map();
|
||||||
for (const word of activeWords) wordMap.set(word.text.toLowerCase(), word);
|
for (const word of activeWords) {
|
||||||
|
wordMap.set(matchCase ? word.text : word.text.toLowerCase(), word);
|
||||||
let flags = matchCase ? 'g' : 'gi';
|
|
||||||
let wordsPattern = Array.from(wordMap.keys()).map(escapeRegex).join('|');
|
|
||||||
if (matchWhole) {
|
|
||||||
wordsPattern = `\\b(?:${wordsPattern})\\b`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let flags = matchCase ? 'gu' : 'giu';
|
||||||
|
let wordsPattern = Array.from(wordMap.keys()).map(escapeRegex).join('|');
|
||||||
|
|
||||||
|
if (matchWhole) {
|
||||||
|
wordsPattern = `(?:(?<!\\p{L})|^)(${wordsPattern})(?:(?!\\p{L})|$)`;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const pattern = new RegExp(`(${wordsPattern})`, flags);
|
const pattern = new RegExp(`(${wordsPattern})`, flags);
|
||||||
|
|
||||||
for (const node of textNodes) {
|
for (const node of textNodes) {
|
||||||
if (!pattern.test(node.nodeValue)) continue;
|
if (!node.nodeValue || !pattern.test(node.nodeValue)) continue;
|
||||||
|
|
||||||
const span = document.createElement('span');
|
const span = document.createElement('span');
|
||||||
span.innerHTML = node.nodeValue.replace(pattern, match => {
|
span.innerHTML = node.nodeValue.replace(pattern, match => {
|
||||||
const word = wordMap.get(match.toLowerCase()) || { background: '#ffff00', foreground: '#000000' };
|
const lookup = matchCase ? match : match.toLowerCase();
|
||||||
|
const word = wordMap.get(lookup) || { background: '#ffff00', foreground: '#000000' };
|
||||||
return `<mark data-gh style="background:${word.background};color:${word.foreground};padding:0 2px;">${match}</mark>`;
|
return `<mark data-gh style="background:${word.background};color:${word.foreground};padding:0 2px;">${match}</mark>`;
|
||||||
});
|
});
|
||||||
|
|
||||||
node.parentNode.replaceChild(span, node);
|
node.parentNode.replaceChild(span, node);
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Regex error:", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
observer.observe(document.body, {
|
observer.observe(document.body, {
|
||||||
childList: true,
|
childList: true,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "__MSG_extension_name__",
|
"name": "__MSG_extension_name__",
|
||||||
"description": "__MSG_extension_description__",
|
"description": "__MSG_extension_description__",
|
||||||
"version": "1.6.0",
|
"version": "1.7.1",
|
||||||
"default_locale": "en",
|
"default_locale": "en",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"scripting",
|
"scripting",
|
||||||
|
|||||||
Reference in New Issue
Block a user