mirror of
https://github.com/obsqrbtz/goose-highlighter.git
synced 2026-04-08 20:19:06 +03:00
chore: migrated to typescript
This commit is contained in:
14
.github/workflows/publish-extension.yml
vendored
14
.github/workflows/publish-extension.yml
vendored
@@ -16,13 +16,25 @@ jobs:
|
|||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '18'
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build extension
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
- name: Set version from tag
|
- name: Set version from tag
|
||||||
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: Create zip package
|
- name: Create zip package
|
||||||
run: |
|
run: |
|
||||||
zip -r goose-highlighter.zip . -x '*.git*' 'node_modules/*' 'versioning.md' '.releaserc.json' 'package.json' 'package-lock.json' 'README.md'
|
zip -r goose-highlighter.zip . -x '*.git*' 'node_modules/*' 'src/*' 'versioning.md' '.releaserc.json' 'package.json' 'package-lock.json' 'README.md' 'tsconfig.json' 'eslint.config.mjs'
|
||||||
|
|
||||||
- name: Install webstore upload CLI
|
- name: Install webstore upload CLI
|
||||||
run: npm install -g chrome-webstore-upload-cli
|
run: npm install -g chrome-webstore-upload-cli
|
||||||
|
|||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1 +1,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
|
dist
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
|
||||||
if (changeInfo.status === 'complete' && /^https?:/.test(tab.url)) {
|
|
||||||
chrome.scripting.executeScript({
|
|
||||||
target: { tabId },
|
|
||||||
files: ['main.js']
|
|
||||||
}).catch(err => {
|
|
||||||
console.warn('Injection failed:', err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
chrome.runtime.onInstalled.addListener(() => {
|
|
||||||
chrome.storage.local.get(['exceptionsList'], (result) => {
|
|
||||||
if (!result.exceptionsList) {
|
|
||||||
chrome.storage.local.set({ exceptionsList: [] });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
"default_icon": "icons/icon128.png"
|
"default_icon": "icons/icon128.png"
|
||||||
},
|
},
|
||||||
"background": {
|
"background": {
|
||||||
"service_worker": "background.js"
|
"service_worker": "dist/background.js"
|
||||||
},
|
},
|
||||||
"icons": {
|
"icons": {
|
||||||
"48": "icons/icon48.png",
|
"48": "icons/icon48.png",
|
||||||
|
|||||||
53
package-lock.json
generated
53
package-lock.json
generated
@@ -10,9 +10,11 @@
|
|||||||
"@semantic-release/changelog": "^6.0.3",
|
"@semantic-release/changelog": "^6.0.3",
|
||||||
"@semantic-release/exec": "^7.1.0",
|
"@semantic-release/exec": "^7.1.0",
|
||||||
"@semantic-release/git": "^10.0.1",
|
"@semantic-release/git": "^10.0.1",
|
||||||
|
"@types/chrome": "^0.0.270",
|
||||||
"eslint": "^9.30.0",
|
"eslint": "^9.30.0",
|
||||||
"globals": "^16.2.0",
|
"globals": "^16.2.0",
|
||||||
"semantic-release": "^24.2.5"
|
"semantic-release": "^24.2.5",
|
||||||
|
"typescript": "^5.6.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/code-frame": {
|
"node_modules/@babel/code-frame": {
|
||||||
@@ -1213,6 +1215,17 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/chrome": {
|
||||||
|
"version": "0.0.270",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.270.tgz",
|
||||||
|
"integrity": "sha512-ADvkowV7YnJfycZZxL2brluZ6STGW+9oKG37B422UePf2PCXuFA/XdERI0T18wtuWPx0tmFeZqq6MOXVk1IC+Q==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/filesystem": "*",
|
||||||
|
"@types/har-format": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/estree": {
|
"node_modules/@types/estree": {
|
||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
|
||||||
@@ -1220,6 +1233,30 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/filesystem": {
|
||||||
|
"version": "0.0.36",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.36.tgz",
|
||||||
|
"integrity": "sha512-vPDXOZuannb9FZdxgHnqSwAG/jvdGM8Wq+6N4D/d80z+D4HWH+bItqsZaVRQykAn6WEVeEkLm2oQigyHtgb0RA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/filewriter": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/filewriter": {
|
||||||
|
"version": "0.0.33",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.33.tgz",
|
||||||
|
"integrity": "sha512-xFU8ZXTw4gd358lb2jw25nxY9QAgqn2+bKKjKOYfNCzN4DKCFetK7sPtrlpg66Ywe3vWY9FNxprZawAh9wfJ3g==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/har-format": {
|
||||||
|
"version": "1.2.16",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/har-format/-/har-format-1.2.16.tgz",
|
||||||
|
"integrity": "sha512-fluxdy7ryD3MV6h8pTfTYpy/xQzCFC7m89nOH9y94cNqJ1mDIDPut7MnRHI3F6qRmh/cT2fUjG1MLdCNb4hE9A==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/json-schema": {
|
"node_modules/@types/json-schema": {
|
||||||
"version": "7.0.15",
|
"version": "7.0.15",
|
||||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
|
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
|
||||||
@@ -7624,6 +7661,20 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/typescript": {
|
||||||
|
"version": "5.9.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||||
|
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bin": {
|
||||||
|
"tsc": "bin/tsc",
|
||||||
|
"tsserver": "bin/tsserver"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.17"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/uglify-js": {
|
"node_modules/uglify-js": {
|
||||||
"version": "3.19.3",
|
"version": "3.19.3",
|
||||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.3.tgz",
|
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.3.tgz",
|
||||||
|
|||||||
10
package.json
10
package.json
@@ -5,11 +5,17 @@
|
|||||||
"@semantic-release/changelog": "^6.0.3",
|
"@semantic-release/changelog": "^6.0.3",
|
||||||
"@semantic-release/exec": "^7.1.0",
|
"@semantic-release/exec": "^7.1.0",
|
||||||
"@semantic-release/git": "^10.0.1",
|
"@semantic-release/git": "^10.0.1",
|
||||||
|
"@types/chrome": "^0.0.270",
|
||||||
"eslint": "^9.30.0",
|
"eslint": "^9.30.0",
|
||||||
"globals": "^16.2.0",
|
"globals": "^16.2.0",
|
||||||
"semantic-release": "^24.2.5"
|
"semantic-release": "^24.2.5",
|
||||||
|
"typescript": "^5.6.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "node scripts/update-manifest-version.js"
|
"build": "tsc",
|
||||||
|
"watch": "tsc --watch",
|
||||||
|
"clean": "rimraf dist",
|
||||||
|
"rebuild": "npm run clean && npm run build",
|
||||||
|
"prepare": "npm run build && node scripts/update-manifest-version.js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,8 +148,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="../storage.js"></script>
|
<script src="../dist/popup/popup.js"></script>
|
||||||
<script src="popup.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
20
src/background.ts
Normal file
20
src/background.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Handle tab updates to inject content script
|
||||||
|
chrome.tabs.onUpdated.addListener((tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab): void => {
|
||||||
|
if (changeInfo.status === 'complete' && tab.url && /^https?:/.test(tab.url)) {
|
||||||
|
chrome.scripting.executeScript({
|
||||||
|
target: { tabId },
|
||||||
|
files: ['dist/main.js']
|
||||||
|
}).catch((err: unknown) => {
|
||||||
|
console.warn('Injection failed:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize storage on extension install
|
||||||
|
chrome.runtime.onInstalled.addListener((): void => {
|
||||||
|
chrome.storage.local.get(['exceptionsList'], (result: any) => {
|
||||||
|
if (!result.exceptionsList) {
|
||||||
|
chrome.storage.local.set({ exceptionsList: [] });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// @ts-nocheck
|
||||||
let currentLists = [];
|
let currentLists = [];
|
||||||
let isGlobalHighlightEnabled = true;
|
let isGlobalHighlightEnabled = true;
|
||||||
let exceptionsList = [];
|
let exceptionsList = [];
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// @ts-nocheck
|
||||||
const listSelect = document.getElementById('listSelect');
|
const listSelect = document.getElementById('listSelect');
|
||||||
const listName = document.getElementById('listName');
|
const listName = document.getElementById('listName');
|
||||||
const listBg = document.getElementById('listBg');
|
const listBg = document.getElementById('listBg');
|
||||||
75
src/types.ts
Normal file
75
src/types.ts
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
// Type definitions for the Goose Highlighter extension
|
||||||
|
|
||||||
|
export interface HighlightWord {
|
||||||
|
wordStr: string;
|
||||||
|
background: string;
|
||||||
|
foreground: string;
|
||||||
|
active: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HighlightList {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
background: string;
|
||||||
|
foreground: string;
|
||||||
|
active: boolean;
|
||||||
|
words: HighlightWord[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StorageData {
|
||||||
|
lists: HighlightList[];
|
||||||
|
globalHighlightEnabled: boolean;
|
||||||
|
matchCaseEnabled: boolean;
|
||||||
|
matchWholeEnabled: boolean;
|
||||||
|
exceptionsList: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ActiveWord {
|
||||||
|
text: string;
|
||||||
|
background: string;
|
||||||
|
foreground: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MessageData {
|
||||||
|
type: 'WORD_LIST_UPDATED' | 'GLOBAL_TOGGLE_UPDATED' | 'MATCH_OPTIONS_UPDATED' | 'EXCEPTIONS_LIST_UPDATED';
|
||||||
|
enabled?: boolean;
|
||||||
|
matchCase?: boolean;
|
||||||
|
matchWhole?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SectionStates {
|
||||||
|
[sectionName: string]: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ExportData {
|
||||||
|
lists: HighlightList[];
|
||||||
|
exceptionsList: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// DOM element selectors used in popup
|
||||||
|
export interface PopupElements {
|
||||||
|
listSelect: HTMLSelectElement;
|
||||||
|
listName: HTMLInputElement;
|
||||||
|
listBg: HTMLInputElement;
|
||||||
|
listFg: HTMLInputElement;
|
||||||
|
listActive: HTMLInputElement;
|
||||||
|
bulkPaste: HTMLTextAreaElement;
|
||||||
|
wordList: HTMLDivElement;
|
||||||
|
importInput: HTMLInputElement;
|
||||||
|
matchCase: HTMLInputElement;
|
||||||
|
matchWhole: HTMLInputElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default storage values
|
||||||
|
export const DEFAULT_STORAGE: Partial<StorageData> = {
|
||||||
|
lists: [],
|
||||||
|
globalHighlightEnabled: true,
|
||||||
|
matchCaseEnabled: false,
|
||||||
|
matchWholeEnabled: false,
|
||||||
|
exceptionsList: []
|
||||||
|
};
|
||||||
|
|
||||||
|
// Constants
|
||||||
|
export const WORD_ITEM_HEIGHT = 32;
|
||||||
|
export const DEBOUNCE_DELAY = 300;
|
||||||
|
export const SCROLL_THROTTLE = 16; // ~60fps
|
||||||
30
tsconfig.json
Normal file
30
tsconfig.json
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "CommonJS",
|
||||||
|
"lib": ["ES2022", "DOM"],
|
||||||
|
"outDir": "./dist",
|
||||||
|
"rootDir": "./src",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"noEmitOnError": false,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"noUnusedLocals": false,
|
||||||
|
"noUnusedParameters": false,
|
||||||
|
"exactOptionalPropertyTypes": false,
|
||||||
|
"types": ["chrome"]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"dist"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user