13 Commits

Author SHA1 Message Date
semantic-release-bot
6d7d9ac151 chore(release): 1.9.0
# [1.9.0](https://github.com/obsqrbtz/goose-highlighter/compare/v1.8.5...v1.9.0) (2025-10-31)

### Features

* haloween styling ([5ef380e](5ef380e544))
2025-10-31 11:17:28 +03:00
5ef380e544 feat: haloween styling 2025-10-31 11:17:08 +03:00
semantic-release-bot
c634f6bc8b chore(release): 1.8.5
## [1.8.5](https://github.com/obsqrbtz/goose-highlighter/compare/v1.8.4...v1.8.5) (2025-10-29)

### Bug Fixes

* highlight colors when multiple list have different configurations ([67577c8](67577c89cf))
2025-10-29 12:30:37 +03:00
67577c89cf fix: highlight colors when multiple list have different configurations 2025-10-29 12:29:55 +03:00
semantic-release-bot
326e585021 chore(release): 1.8.4
## [1.8.4](https://github.com/obsqrbtz/goose-highlighter/compare/v1.8.3...v1.8.4) (2025-10-28)

### Bug Fixes

* do not re-highlight when already processing highlights ([8be53f3](8be53f3240))
2025-10-28 15:32:14 +03:00
8be53f3240 fix: do not re-highlight when already processing highlights 2025-10-28 15:31:46 +03:00
f07617fa55 Merge branch 'main' of https://github.com/obsqrbtz/goose-highlighter 2025-10-09 16:18:53 +03:00
e79874922a added logo 2025-10-09 16:18:36 +03:00
71216cbcd9 ci: update manifest in publish workflow 2025-10-08 17:54:06 +03:00
f292bd7149 nit: added footer with version and github. 2025-10-08 16:32:04 +03:00
584ced252f ci: publish on version tag push 2025-10-08 16:26:32 +03:00
semantic-release-bot
ff5752da84 chore(release): 1.8.3
## [1.8.3](https://github.com/obsqrbtz/goose-highlighter/compare/v1.8.2...v1.8.3) (2025-10-08)

### Bug Fixes

* stop observing when highlightting is disabled ([d7c8dbb](d7c8dbb5f0))
2025-10-08 16:11:52 +03:00
d7c8dbb5f0 fix: stop observing when highlightting is disabled 2025-10-08 16:11:25 +03:00
12 changed files with 263 additions and 59 deletions

View File

@@ -2,7 +2,8 @@ name: Publish Chrome Extension
on: on:
push: push:
branches: [ main ] tags:
- 'v*'
jobs: jobs:
publish: publish:
@@ -32,6 +33,9 @@ jobs:
id: version id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Update manifest version
run: node scripts/update-manifest-version.js ${{ steps.version.outputs.VERSION }}
- name: Create zip package - name: Create zip package
run: | run: |
zip -r goose-highlighter.zip . -x '*.git*' 'node_modules/*' 'src/*' 'scripts/*' 'versioning.md' '.releaserc.json' 'package.json' 'package-lock.json' 'README.md' 'tsconfig.json' 'eslint.config.mjs' zip -r goose-highlighter.zip . -x '*.git*' 'node_modules/*' 'src/*' 'scripts/*' 'versioning.md' '.releaserc.json' 'package.json' 'package-lock.json' 'README.md' 'tsconfig.json' 'eslint.config.mjs'

View File

@@ -1,3 +0,0 @@
{
"kiroAgent.configureMCP": "Enabled"
}

View File

@@ -1,3 +1,31 @@
# [1.9.0](https://github.com/obsqrbtz/goose-highlighter/compare/v1.8.5...v1.9.0) (2025-10-31)
### Features
* haloween styling ([5ef380e](https://github.com/obsqrbtz/goose-highlighter/commit/5ef380e54447f45f7360dd4b7b84456aae55bfee))
## [1.8.5](https://github.com/obsqrbtz/goose-highlighter/compare/v1.8.4...v1.8.5) (2025-10-29)
### Bug Fixes
* highlight colors when multiple list have different configurations ([67577c8](https://github.com/obsqrbtz/goose-highlighter/commit/67577c89cffca1ab6d40a8913e51b7c3c6f91c85))
## [1.8.4](https://github.com/obsqrbtz/goose-highlighter/compare/v1.8.3...v1.8.4) (2025-10-28)
### Bug Fixes
* do not re-highlight when already processing highlights ([8be53f3](https://github.com/obsqrbtz/goose-highlighter/commit/8be53f32402c2f0f228ca003ef3805c5ff0b6e88))
## [1.8.3](https://github.com/obsqrbtz/goose-highlighter/compare/v1.8.2...v1.8.3) (2025-10-08)
### Bug Fixes
* stop observing when highlightting is disabled ([d7c8dbb](https://github.com/obsqrbtz/goose-highlighter/commit/d7c8dbb5f0011afe83739841218aa737794074e3))
## [1.8.2](https://github.com/obsqrbtz/goose-highlighter/compare/v1.8.1...v1.8.2) (2025-10-08) ## [1.8.2](https://github.com/obsqrbtz/goose-highlighter/compare/v1.8.1...v1.8.2) (2025-10-08)

View File

@@ -1,4 +1,4 @@
# Goose Highlighter # <img src="img/logo.png" alt="Goose Highlighter Logo" width="32" style="vertical-align: middle;"> Goose Highlighter
Goose Highlighter is a browser extension that allows you to highlight words on any webpage. Goose Highlighter is a browser extension that allows you to highlight words on any webpage.

BIN
img/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

BIN
img/pumpkin.webm Normal file

Binary file not shown.

View File

@@ -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.8.2", "version": "1.9.0",
"default_locale": "en", "default_locale": "en",
"permissions": [ "permissions": [
"scripting", "scripting",

View File

@@ -6,8 +6,8 @@
--button-bg: #222; --button-bg: #222;
--button-hover: #444; --button-hover: #444;
--button-text: white; --button-text: white;
--accent: #ec9c23; --accent: #ff6b35;
--accent-hover: #ffb84d; --accent-hover: #ff8c42;
--accent-text: #000; --accent-text: #000;
--highlight-tag: #292929; --highlight-tag: #292929;
--highlight-tag-border: #444; --highlight-tag-border: #444;
@@ -17,7 +17,7 @@
--border-radius: 12px; --border-radius: 12px;
--section-bg: #111; --section-bg: #111;
--switch-bg: #444; --switch-bg: #444;
--checkbox-accent: #ec9c23; --checkbox-accent: #ff6b35;
--checkbox-border: #666; --checkbox-border: #666;
--scrollbar-bg: var(--section-bg); --scrollbar-bg: var(--section-bg);
--scrollbar-thumb: var(--accent); --scrollbar-thumb: var(--accent);
@@ -28,6 +28,10 @@
body { body {
font-family: 'Inter', sans-serif; font-family: 'Inter', sans-serif;
background: var(--bg-color); background: var(--bg-color);
background-image:
radial-gradient(circle at 20% 80%, rgba(255, 107, 53, 0.03) 0%, transparent 50%),
radial-gradient(circle at 80% 20%, rgba(255, 140, 0, 0.02) 0%, transparent 50%),
radial-gradient(circle at 40% 40%, rgba(139, 69, 19, 0.01) 0%, transparent 50%);
color: var(--text-color); color: var(--text-color);
margin: 0; margin: 0;
padding: 0; padding: 0;
@@ -45,7 +49,7 @@ body.light {
--button-bg: #e0e0e0; --button-bg: #e0e0e0;
--button-hover: #d0d0d0; --button-hover: #d0d0d0;
--button-text: #222; --button-text: #222;
--accent: #ec9c23; --accent: #ff6b35;
--accent-text: #000; --accent-text: #000;
--highlight-tag: #f0f0f0; --highlight-tag: #f0f0f0;
--highlight-tag-border: #d0d0d0; --highlight-tag-border: #d0d0d0;
@@ -54,7 +58,7 @@ body.light {
--shadow: 0 2px 6px rgba(0, 0, 0, 0.1); --shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
--section-bg: #fff; --section-bg: #fff;
--switch-bg: #ccc; --switch-bg: #ccc;
--checkbox-accent: #ec9c23; --checkbox-accent: #ff6b35;
--checkbox-border: #999; --checkbox-border: #999;
} }
@@ -178,7 +182,7 @@ input[type="color"] {
background: none; background: none;
border: 2px solid var(--input-border); border: 2px solid var(--input-border);
border-radius: 8px; border-radius: 8px;
box-shadow: 0 1px 4px rgba(0,0,0,0.10); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.10);
width: 36px; width: 36px;
height: 36px; height: 36px;
margin-left: 6px; margin-left: 6px;
@@ -230,7 +234,7 @@ input[type="checkbox"]:checked::after {
position: absolute; position: absolute;
top: 1px; top: 1px;
left: 3px; left: 3px;
width: 3px; width: 3px;
height: 7px; height: 7px;
border: solid var(--checkbox-accent); border: solid var(--checkbox-accent);
border-width: 0 2px 2px 0; border-width: 0 2px 2px 0;
@@ -339,9 +343,9 @@ button.danger:hover {
gap: 6px; gap: 6px;
} }
#wordSearch{ #wordSearch {
width:100%; width: 100%;
margin-bottom:8px; margin-bottom: 8px;
margin-top: 8px; margin-top: 8px;
} }
@@ -415,11 +419,14 @@ input[type="file"] {
align-items: center; align-items: center;
padding: 12px 16px; padding: 12px 16px;
background: var(--bg-color); background: var(--bg-color);
background-image: linear-gradient(135deg, rgba(255, 107, 53, 0.05) 0%, transparent 50%);
border-radius: 12px; border-radius: 12px;
border: 1px solid rgba(255, 107, 53, 0.1);
color: var(--fg-color); color: var(--fg-color);
font-weight: bold; font-weight: bold;
font-size: 16px; font-size: 16px;
margin-bottom: 16px; margin-bottom: 16px;
box-shadow: 0 2px 8px rgba(255, 107, 53, 0.1);
} }
.icon-toggles { .icon-toggles {
@@ -485,6 +492,55 @@ input[type="file"] {
font-weight: 900; font-weight: 900;
} }
/* Halloween */
.halloween-icon {
color: #ff6b35;
text-shadow: 0 0 8px rgba(255, 107, 53, 0.3);
animation: halloween-glow 3s ease-in-out infinite alternate;
}
@keyframes halloween-glow {
0% {
text-shadow: 0 0 8px rgba(255, 107, 53, 0.3);
}
100% {
text-shadow: 0 0 12px rgba(255, 107, 53, 0.6), 0 0 16px rgba(255, 140, 0, 0.2);
}
}
.section-header:hover .halloween-icon {
color: #ff8c42;
text-shadow: 0 0 15px rgba(255, 140, 66, 0.8);
}
.flying-pumpkin-video {
display: inline-block;
width: 24px;
height: 24px;
margin-left: 4px;
vertical-align: middle;
filter: drop-shadow(0 0 8px rgba(255, 107, 53, 0.4));
transition: filter 0.3s ease;
background: transparent;
}
.header-pumpkin {
width: 32px;
height: 32px;
margin-right: 8px;
margin-left: 0;
filter: drop-shadow(0 0 10px rgba(255, 107, 53, 0.5));
}
.title:hover .flying-pumpkin-video {
filter: drop-shadow(0 0 12px rgba(255, 107, 53, 0.7));
}
.title:hover .header-pumpkin {
filter: drop-shadow(0 0 16px rgba(255, 107, 53, 0.8));
}
label:has(input.switch) { label:has(input.switch) {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -529,7 +585,9 @@ body::-webkit-scrollbar-corner {
--scrollbar-thumb-border: var(--section-bg); --scrollbar-thumb-border: var(--section-bg);
} }
html, body, #wordList { html,
body,
#wordList {
scrollbar-width: thin; scrollbar-width: thin;
scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-bg); scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-bg);
} }
@@ -612,4 +670,40 @@ body::-webkit-scrollbar-corner,
.exception-remove:hover { .exception-remove:hover {
background: #d00030; background: #d00030;
}
/* Footer Styles */
.footer {
margin-top: 16px;
padding: 12px 16px;
border-top: 1px solid var(--input-border);
background: var(--section-bg);
}
.footer-content {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.8em;
color: var(--text-color);
opacity: 0.7;
}
.version {
font-weight: 500;
}
.github-link {
display: flex;
align-items: center;
gap: 4px;
color: var(--text-color);
text-decoration: none;
opacity: 0.7;
transition: opacity 0.2s ease, color 0.2s ease;
}
.github-link:hover {
opacity: 1;
color: var(--accent);
} }

View File

@@ -8,6 +8,7 @@
<link rel="stylesheet" href="popup.css" /> <link rel="stylesheet" href="popup.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" />
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap" rel="stylesheet">
</head> </head>
<body class="dark"> <body class="dark">
@@ -15,7 +16,9 @@
<div class="header-bar"> <div class="header-bar">
<span class="title"> <span class="title">
<i class="fa-solid fa-highlighter"></i> Goose Highlighter <video class="flying-pumpkin-video header-pumpkin" autoplay loop muted>
<source src="../img/pumpkin.webm" type="video/webm">
</video> Goose Highlighter
</span> </span>
<div class="icon-toggles"> <div class="icon-toggles">
<label class="icon-toggle" title="Toggle highlighting"> <label class="icon-toggle" title="Toggle highlighting">
@@ -31,27 +34,31 @@
<div class="section" data-section="exceptions"> <div class="section" data-section="exceptions">
<div class="section-header"> <div class="section-header">
<h2><i class="fa-solid fa-ban"></i> <span data-i18n="site_exceptions">Site Exceptions</span></h2> <h2><i class="fa-solid fa-ban halloween-icon"></i> <span data-i18n="site_exceptions">Site Exceptions</span></h2>
<button class="collapse-toggle" data-target="exceptions"> <button class="collapse-toggle" data-target="exceptions">
<i class="fa-solid fa-chevron-up"></i> <i class="fa-solid fa-chevron-up"></i>
</button> </button>
</div> </div>
<div class="section-content" id="exceptions-content"> <div class="section-content" id="exceptions-content">
<div class="button-row"> <div class="button-row">
<button id="toggleExceptionBtn"><i class="fa-solid fa-ban"></i> <span id="exceptionBtnText" data-i18n="add_exception">Add to Exceptions</span></button> <button id="toggleExceptionBtn"><i class="fa-solid fa-ban"></i> <span id="exceptionBtnText"
<button id="manageExceptionsBtn"><i class="fa-solid fa-list"></i> <span data-i18n="manage_exceptions">Manage</span></button> data-i18n="add_exception">Add to Exceptions</span></button>
<button id="manageExceptionsBtn"><i class="fa-solid fa-list"></i> <span
data-i18n="manage_exceptions">Manage</span></button>
</div> </div>
<div id="exceptionsPanel" class="exceptions-panel" style="display: none;"> <div id="exceptionsPanel" class="exceptions-panel" style="display: none;">
<h3 data-i18n="exceptions_list">Exception Sites:</h3> <h3 data-i18n="exceptions_list">Exception Sites:</h3>
<div id="exceptionsList" class="exceptions-list"></div> <div id="exceptionsList" class="exceptions-list"></div>
<button id="clearExceptionsBtn" class="danger"><i class="fa-solid fa-trash"></i> <span data-i18n="clear_all">Clear All</span></button> <button id="clearExceptionsBtn" class="danger"><i class="fa-solid fa-trash"></i> <span
data-i18n="clear_all">Clear All</span></button>
</div> </div>
</div> </div>
</div> </div>
<div class="section" data-section="lists"> <div class="section" data-section="lists">
<div class="section-header"> <div class="section-header">
<h2><i class="fa-solid fa-list"></i> <span data-i18n="highlight_lists">Highlight Lists</span></h2> <h2><i class="fa-solid fa-list halloween-icon"></i> <span data-i18n="highlight_lists">Highlight Lists</span>
</h2>
<button class="collapse-toggle" data-target="lists"> <button class="collapse-toggle" data-target="lists">
<i class="fa-solid fa-chevron-up"></i> <i class="fa-solid fa-chevron-up"></i>
</button> </button>
@@ -69,7 +76,7 @@
<div class="section" data-section="settings"> <div class="section" data-section="settings">
<div class="section-header"> <div class="section-header">
<h2><i class="fa-solid fa-gear"></i> <span data-i18n="list_settings">List Settings</span></h2> <h2><i class="fa-solid fa-gear halloween-icon"></i> <span data-i18n="list_settings">List Settings</span></h2>
<button class="collapse-toggle" data-target="settings"> <button class="collapse-toggle" data-target="settings">
<i class="fa-solid fa-chevron-up"></i> <i class="fa-solid fa-chevron-up"></i>
</button> </button>
@@ -90,13 +97,14 @@
<span data-i18n="enable_highlight">Enable Highlighting</span> <span data-i18n="enable_highlight">Enable Highlighting</span>
<input type="checkbox" class="switch" id="listActive" /> <input type="checkbox" class="switch" id="listActive" />
</label> </label>
<button id="applyListSettingsBtn"><i class="fa-solid fa-check"></i> <span data-i18n="apply">Apply</span></button> <button id="applyListSettingsBtn"><i class="fa-solid fa-check"></i> <span
data-i18n="apply">Apply</span></button>
</div> </div>
</div> </div>
<div class="section" data-section="addwords"> <div class="section" data-section="addwords">
<div class="section-header"> <div class="section-header">
<h2><i class="fa-solid fa-pen"></i> <span data-i18n="add_words">Add Words</span></h2> <h2><i class="fa-solid fa-pen halloween-icon"></i> <span data-i18n="add_words">Add Words</span></h2>
<button class="collapse-toggle" data-target="addwords"> <button class="collapse-toggle" data-target="addwords">
<i class="fa-solid fa-chevron-up"></i> <i class="fa-solid fa-chevron-up"></i>
</button> </button>
@@ -109,7 +117,8 @@
<div class="section" data-section="wordlist"> <div class="section" data-section="wordlist">
<div class="section-header"> <div class="section-header">
<h2><i class="fa-solid fa-tags"></i> <span data-i18n="word_list">Word List</span>(<span id="wordCount">0</span>) <h2><i class="fa-solid fa-tags halloween-icon"></i> <span data-i18n="word_list">Word List</span>(<span
id="wordCount">0</span>)
</h2> </h2>
<button class="collapse-toggle" data-target="wordlist"> <button class="collapse-toggle" data-target="wordlist">
<i class="fa-solid fa-chevron-up"></i> <i class="fa-solid fa-chevron-up"></i>
@@ -130,7 +139,7 @@
<div class="section" data-section="options"> <div class="section" data-section="options">
<div class="section-header"> <div class="section-header">
<h2><i class="fa-solid fa-sliders"></i> <span data-i18n="options">Options</span></h2> <h2><i class="fa-solid fa-sliders halloween-icon"></i> <span data-i18n="options">Options</span></h2>
<button class="collapse-toggle" data-target="options"> <button class="collapse-toggle" data-target="options">
<i class="fa-solid fa-chevron-up"></i> <i class="fa-solid fa-chevron-up"></i>
</button> </button>
@@ -143,12 +152,23 @@
<div class="button-row"> <div class="button-row">
<button id="importBtn"><i class="fa-solid fa-upload"></i> <span data-i18n="import_list">Import</span></button> <button id="importBtn"><i class="fa-solid fa-upload"></i> <span data-i18n="import_list">Import</span></button>
<input type="file" id="importInput" accept="application/json" hidden /> <input type="file" id="importInput" accept="application/json" hidden />
<button id="exportBtn"><i class="fa-solid fa-download"></i> <span data-i18n="export_list">Export</span></button> <button id="exportBtn"><i class="fa-solid fa-download"></i> <span
data-i18n="export_list">Export</span></button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<footer class="footer">
<div class="footer-content">
<span class="version">v<span id="version-number">...</span></span>
<a href="https://github.com/obsqrbtz/goose-highlighter" target="_blank" class="github-link">
<i class="fa-brands fa-github"></i>
<span>GitHub</span>
</a>
</div>
</footer>
<script type="module" src="../dist/popup/popup.js"></script> <script type="module" src="../dist/popup/popup.js"></script>
</body> </body>

View File

@@ -12,6 +12,7 @@ export class ContentScript {
private matchCase = false; private matchCase = false;
private matchWhole = false; private matchWhole = false;
private highlightEngine: HighlightEngine; private highlightEngine: HighlightEngine;
private isProcessing = false;
constructor() { constructor() {
this.highlightEngine = new HighlightEngine(() => this.processHighlights()); this.highlightEngine = new HighlightEngine(() => this.processHighlights());
@@ -67,7 +68,7 @@ export class ContentScript {
} }
private setupScrollHandler(): void { private setupScrollHandler(): void {
const debouncedProcess = DOMUtils.debounce(() => this.processHighlights(), 300); const debouncedProcess = DOMUtils.debounce(() => this.processHighlights(), CONSTANTS.DEBOUNCE_DELAY);
window.addEventListener('scroll', debouncedProcess); window.addEventListener('scroll', debouncedProcess);
} }
@@ -96,11 +97,19 @@ export class ContentScript {
} }
private processHighlights(): void { private processHighlights(): void {
if (!this.isGlobalHighlightEnabled || this.isCurrentSiteException) { if (this.isProcessing) return;
this.highlightEngine.clearHighlights(); this.isProcessing = true;
return;
}
this.highlightEngine.highlight(this.lists, this.matchCase, this.matchWhole); try {
if (!this.isGlobalHighlightEnabled || this.isCurrentSiteException) {
this.highlightEngine.clearHighlights();
this.highlightEngine.stopObserving();
return;
}
this.highlightEngine.highlight(this.lists, this.matchCase, this.matchWhole);
} finally {
this.isProcessing = false;
}
} }
} }

View File

@@ -5,9 +5,31 @@ export class HighlightEngine {
private styleSheet: CSSStyleSheet | null = null; private styleSheet: CSSStyleSheet | null = null;
private wordStyleMap = new Map<string, string>(); private wordStyleMap = new Map<string, string>();
private observer: MutationObserver; private observer: MutationObserver;
private isHighlighting = false;
constructor(private onUpdate: () => void) { constructor(private onUpdate: () => void) {
this.observer = new MutationObserver(DOMUtils.debounce(onUpdate, 300)); this.observer = new MutationObserver(DOMUtils.debounce((mutations: MutationRecord[]) => {
if (this.isHighlighting) return;
const hasContentChanges = mutations.some((mutation: MutationRecord) => {
if (mutation.type !== 'childList') return false;
if (mutation.target instanceof Element && mutation.target.hasAttribute('data-gh')) {
return false;
}
const allNodes = [...Array.from(mutation.addedNodes), ...Array.from(mutation.removedNodes)];
return allNodes.some(node => {
if (node.nodeType === Node.TEXT_NODE) return true;
if (node instanceof Element && !node.hasAttribute('data-gh')) return true;
return false;
});
});
if (hasContentChanges) {
this.onUpdate();
}
}, CONSTANTS.DEBOUNCE_DELAY));
} }
private initializeStyleSheet(): void { private initializeStyleSheet(): void {
@@ -19,47 +41,41 @@ export class HighlightEngine {
} }
} }
private updateWordStyles(activeWords: ActiveWord[]): void { private updateWordStyles(activeWords: ActiveWord[], matchCase: boolean): void {
this.initializeStyleSheet(); this.initializeStyleSheet();
while (this.styleSheet!.cssRules.length > 0) { while (this.styleSheet!.cssRules.length > 0) {
this.styleSheet!.deleteRule(0); this.styleSheet!.deleteRule(0);
} }
this.wordStyleMap.clear(); this.wordStyleMap.clear();
const uniqueStyles = new Map<string, string>(); const uniqueStyles = new Map<string, string>();
for (const word of activeWords) { for (const word of activeWords) {
const styleKey = `${word.background}-${word.foreground}`; const styleKey = `${word.background}-${word.foreground}`;
if (!uniqueStyles.has(styleKey)) { if (!uniqueStyles.has(styleKey)) {
const className = `highlighted-word-${uniqueStyles.size}`; const className = `highlighted-word-${uniqueStyles.size}`;
uniqueStyles.set(styleKey, className); uniqueStyles.set(styleKey, className);
const rule = `.${className} { background: ${word.background}; color: ${word.foreground}; padding: 0 2px; }`; const rule = `.${className} { background: ${word.background}; color: ${word.foreground}; padding: 0 2px; }`;
this.styleSheet!.insertRule(rule, this.styleSheet!.cssRules.length); this.styleSheet!.insertRule(rule, this.styleSheet!.cssRules.length);
} }
const lookup = word.text; const lookup = matchCase ? word.text : word.text.toLowerCase();
this.wordStyleMap.set(lookup, uniqueStyles.get(styleKey)!); this.wordStyleMap.set(lookup, uniqueStyles.get(styleKey)!);
} }
} }
clearHighlights(): void { clearHighlights(): void {
const highlightedElements = document.querySelectorAll('[data-gh]'); this.observer.disconnect();
highlightedElements.forEach(element => { this.clearHighlightsInternal();
const parent = element.parentNode;
if (parent) {
parent.replaceChild(document.createTextNode(element.textContent || ''), element);
parent.normalize();
}
});
} }
private getTextNodes(): Text[] { private getTextNodes(): Text[] {
const textNodes: Text[] = []; const textNodes: Text[] = [];
const walker = document.createTreeWalker( const walker = document.createTreeWalker(
document.body, document.body,
NodeFilter.SHOW_TEXT, NodeFilter.SHOW_TEXT,
{ {
acceptNode: (node: Text) => { acceptNode: (node: Text) => {
if (node.parentNode && (node.parentNode as Element).hasAttribute('data-gh')) { if (node.parentNode && (node.parentNode as Element).hasAttribute('data-gh')) {
@@ -99,17 +115,22 @@ export class HighlightEngine {
} }
highlight(lists: HighlightList[], matchCase: boolean, matchWhole: boolean): void { highlight(lists: HighlightList[], matchCase: boolean, matchWhole: boolean): void {
if (this.isHighlighting) return;
this.isHighlighting = true;
this.observer.disconnect(); this.observer.disconnect();
this.clearHighlights();
this.clearHighlightsInternal();
const activeWords = this.extractActiveWords(lists); const activeWords = this.extractActiveWords(lists);
if (activeWords.length === 0) { if (activeWords.length === 0) {
this.startObserving(); this.startObserving();
this.isHighlighting = false;
return; return;
} }
this.updateWordStyles(activeWords); this.updateWordStyles(activeWords, matchCase);
const wordMap = new Map<string, ActiveWord>(); const wordMap = new Map<string, ActiveWord>();
for (const word of activeWords) { for (const word of activeWords) {
const key = matchCase ? word.text : word.text.toLowerCase(); const key = matchCase ? word.text : word.text.toLowerCase();
@@ -118,11 +139,11 @@ export class HighlightEngine {
const flags = matchCase ? 'gu' : 'giu'; const flags = matchCase ? 'gu' : 'giu';
let wordsPattern = Array.from(wordMap.keys()).map(DOMUtils.escapeRegex).join('|'); let wordsPattern = Array.from(wordMap.keys()).map(DOMUtils.escapeRegex).join('|');
if (matchWhole) { if (matchWhole) {
wordsPattern = `(?:(?<!\\p{L})|^)(${wordsPattern})(?:(?!\\p{L})|$)`; wordsPattern = `(?:(?<!\\p{L})|^)(${wordsPattern})(?:(?!\\p{L})|$)`;
} }
try { try {
const pattern = new RegExp(`(${wordsPattern})`, flags); const pattern = new RegExp(`(${wordsPattern})`, flags);
const textNodes = this.getTextNodes(); const textNodes = this.getTextNodes();
@@ -144,13 +165,35 @@ export class HighlightEngine {
} }
this.startObserving(); this.startObserving();
this.isHighlighting = false;
}
private clearHighlightsInternal(): void {
const highlightedElements = document.querySelectorAll('[data-gh]');
highlightedElements.forEach(element => {
const parent = element.parentNode;
if (parent) {
parent.replaceChild(document.createTextNode(element.textContent || ''), element);
parent.normalize();
}
});
if (this.styleSheet && this.styleSheet.cssRules.length > 0) {
while (this.styleSheet.cssRules.length > 0) {
this.styleSheet.deleteRule(0);
}
}
}
stopObserving(): void {
this.observer.disconnect();
} }
private startObserving(): void { private startObserving(): void {
this.observer.observe(document.body, { this.observer.observe(document.body, {
childList: true, childList: true,
subtree: true, subtree: true,
characterData: true attributes: false
}); });
} }

View File

@@ -15,8 +15,17 @@ function localizePage(): void {
}); });
} }
function displayVersion(): void {
const manifest = chrome.runtime.getManifest();
const versionElement = document.getElementById('version-number');
if (versionElement && manifest.version) {
versionElement.textContent = manifest.version;
}
}
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
localizePage(); localizePage();
displayVersion();
const controller = new PopupController(); const controller = new PopupController();
await controller.initialize(); await controller.initialize();
}); });