mirror of
https://github.com/obsqrbtz/goose-highlighter.git
synced 2026-04-09 04:29:09 +03:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c634f6bc8b | ||
| 67577c89cf | |||
|
|
326e585021 | ||
| 8be53f3240 | |||
| f07617fa55 | |||
| e79874922a | |||
| 71216cbcd9 | |||
| f292bd7149 | |||
| 584ced252f | |||
|
|
ff5752da84 | ||
| d7c8dbb5f0 |
6
.github/workflows/publish-extension.yml
vendored
6
.github/workflows/publish-extension.yml
vendored
@@ -2,7 +2,8 @@ name: Publish Chrome Extension
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
@@ -32,6 +33,9 @@ jobs:
|
||||
id: version
|
||||
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
|
||||
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'
|
||||
|
||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"kiroAgent.configureMCP": "Enabled"
|
||||
}
|
||||
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,3 +1,24 @@
|
||||
## [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,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.
|
||||
|
||||
|
||||
BIN
img/logo.png
Normal file
BIN
img/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
@@ -2,7 +2,7 @@
|
||||
"manifest_version": 3,
|
||||
"name": "__MSG_extension_name__",
|
||||
"description": "__MSG_extension_description__",
|
||||
"version": "1.8.2",
|
||||
"version": "1.8.5",
|
||||
"default_locale": "en",
|
||||
"permissions": [
|
||||
"scripting",
|
||||
|
||||
@@ -613,3 +613,39 @@ body::-webkit-scrollbar-corner,
|
||||
.exception-remove:hover {
|
||||
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);
|
||||
}
|
||||
@@ -149,6 +149,16 @@
|
||||
</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>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ export class ContentScript {
|
||||
private matchCase = false;
|
||||
private matchWhole = false;
|
||||
private highlightEngine: HighlightEngine;
|
||||
private isProcessing = false;
|
||||
|
||||
constructor() {
|
||||
this.highlightEngine = new HighlightEngine(() => this.processHighlights());
|
||||
@@ -67,7 +68,7 @@ export class ContentScript {
|
||||
}
|
||||
|
||||
private setupScrollHandler(): void {
|
||||
const debouncedProcess = DOMUtils.debounce(() => this.processHighlights(), 300);
|
||||
const debouncedProcess = DOMUtils.debounce(() => this.processHighlights(), CONSTANTS.DEBOUNCE_DELAY);
|
||||
window.addEventListener('scroll', debouncedProcess);
|
||||
}
|
||||
|
||||
@@ -96,11 +97,19 @@ export class ContentScript {
|
||||
}
|
||||
|
||||
private processHighlights(): void {
|
||||
if (this.isProcessing) return;
|
||||
this.isProcessing = true;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,31 @@ export class HighlightEngine {
|
||||
private styleSheet: CSSStyleSheet | null = null;
|
||||
private wordStyleMap = new Map<string, string>();
|
||||
private observer: MutationObserver;
|
||||
private isHighlighting = false;
|
||||
|
||||
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 {
|
||||
@@ -19,7 +41,7 @@ export class HighlightEngine {
|
||||
}
|
||||
}
|
||||
|
||||
private updateWordStyles(activeWords: ActiveWord[]): void {
|
||||
private updateWordStyles(activeWords: ActiveWord[], matchCase: boolean): void {
|
||||
this.initializeStyleSheet();
|
||||
|
||||
while (this.styleSheet!.cssRules.length > 0) {
|
||||
@@ -39,20 +61,14 @@ export class HighlightEngine {
|
||||
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)!);
|
||||
}
|
||||
}
|
||||
|
||||
clearHighlights(): 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();
|
||||
}
|
||||
});
|
||||
this.observer.disconnect();
|
||||
this.clearHighlightsInternal();
|
||||
}
|
||||
|
||||
private getTextNodes(): Text[] {
|
||||
@@ -99,16 +115,21 @@ export class HighlightEngine {
|
||||
}
|
||||
|
||||
highlight(lists: HighlightList[], matchCase: boolean, matchWhole: boolean): void {
|
||||
if (this.isHighlighting) return;
|
||||
this.isHighlighting = true;
|
||||
|
||||
this.observer.disconnect();
|
||||
this.clearHighlights();
|
||||
|
||||
this.clearHighlightsInternal();
|
||||
|
||||
const activeWords = this.extractActiveWords(lists);
|
||||
if (activeWords.length === 0) {
|
||||
this.startObserving();
|
||||
this.isHighlighting = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateWordStyles(activeWords);
|
||||
this.updateWordStyles(activeWords, matchCase);
|
||||
|
||||
const wordMap = new Map<string, ActiveWord>();
|
||||
for (const word of activeWords) {
|
||||
@@ -144,13 +165,35 @@ export class HighlightEngine {
|
||||
}
|
||||
|
||||
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 {
|
||||
this.observer.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
characterData: true
|
||||
attributes: false
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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 () => {
|
||||
localizePage();
|
||||
displayVersion();
|
||||
const controller = new PopupController();
|
||||
await controller.initialize();
|
||||
});
|
||||
Reference in New Issue
Block a user