Skip to content

Commit f0f3bb2

Browse files
committed
Merge branch 'dev'
2 parents 1257ca3 + e5b6a3b commit f0f3bb2

44 files changed

Lines changed: 1029 additions & 254 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [7.22.0](https://github.com/crimx/ext-saladict/compare/v7.21.0...v7.22.0) (2026-05-01)
6+
7+
8+
### Features
9+
10+
* add utility functions for DOM manipulation ([6340484](https://github.com/crimx/ext-saladict/commit/63404840427eef6181af07717c22c7803f28d6b3))
11+
* update theme mode ([8af665f](https://github.com/crimx/ext-saladict/commit/8af665f4f1cbc3be6b34620b4deb654a84e906ed))
12+
* update zip script ([94d8d2c](https://github.com/crimx/ext-saladict/commit/94d8d2c3c0f4500ec9756aeac57607b13c69b2ce))
13+
14+
15+
### Bug Fixes
16+
17+
* pdf sniffing ([62653e5](https://github.com/crimx/ext-saladict/commit/62653e58eb1590e7dc5e702a258b84e5c28a2f85))
18+
* update Firefox strict_min_version ([45cc47d](https://github.com/crimx/ext-saladict/commit/45cc47dfcc6f10b5e62e06b118de4956d974a085))
19+
520
## [7.21.0](https://github.com/crimx/ext-saladict/compare/v7.20.0...v7.21.0) (2026-04-25)
621

722

assets/pdf-viewer-bridge.js

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
;(function() {
22
var AUTO_MARKER = 'saladict-pdf'
33
var MAX_ATTEMPTS = 20
4+
var VIEWER_APP_MAX_ATTEMPTS = 80
45

56
function sleep(ms) {
67
return new Promise(function(resolve) {
@@ -15,18 +16,49 @@
1516
return viewerUrl.toString()
1617
}
1718

18-
async function fetchPendingPdfOpen() {
19+
async function waitForPDFViewerApplication() {
20+
for (var attempt = 0; attempt < VIEWER_APP_MAX_ATTEMPTS; attempt++) {
21+
if (
22+
window.PDFViewerApplication &&
23+
window.PDFViewerApplication.initializedPromise
24+
) {
25+
return window.PDFViewerApplication
26+
}
27+
28+
await sleep(50)
29+
}
30+
31+
return null
32+
}
33+
34+
async function getViewerTabContext() {
35+
var context = {}
36+
37+
try {
38+
if (browser.tabs && browser.tabs.getCurrent) {
39+
var tab = await browser.tabs.getCurrent()
40+
if (tab && typeof tab.id === 'number') {
41+
context.tabId = tab.id
42+
}
43+
}
44+
} catch (error) {
45+
/* fall back to the message sender metadata */
46+
}
47+
48+
return context
49+
}
50+
51+
async function fetchPendingPdfOpen(context) {
1952
return browser.runtime.sendMessage({
20-
type: 'GET_PDF_SNIFF_PENDING'
53+
type: 'GET_PDF_SNIFF_PENDING',
54+
payload: context
2155
})
2256
}
2357

24-
async function openStandaloneIfNeeded(url) {
58+
async function openStandaloneIfNeeded(url, context) {
2559
return browser.runtime.sendMessage({
2660
type: 'OPEN_PDF_VIEWER_STANDALONE_IF_NEEDED',
27-
payload: {
28-
url: url
29-
}
61+
payload: Object.assign({ url: url }, context)
3062
})
3163
}
3264

@@ -36,20 +68,19 @@
3668
return
3769
}
3870

39-
if (
40-
!window.PDFViewerApplication ||
41-
!window.PDFViewerApplication.initializedPromise
42-
) {
71+
var pdfViewerApplication = await waitForPDFViewerApplication()
72+
if (!pdfViewerApplication) {
4373
return
4474
}
4575

46-
await window.PDFViewerApplication.initializedPromise
76+
await pdfViewerApplication.initializedPromise
77+
var viewerTabContext = await getViewerTabContext()
4778

4879
for (var attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
4980
var pending = null
5081

5182
try {
52-
pending = await fetchPendingPdfOpen()
83+
pending = await fetchPendingPdfOpen(viewerTabContext)
5384
} catch (error) {
5485
pending = null
5586
}
@@ -65,7 +96,11 @@
6596
}
6697

6798
try {
68-
if (await openStandaloneIfNeeded(pending.url)) {
99+
var openedStandalone = await openStandaloneIfNeeded(
100+
pending.url,
101+
viewerTabContext
102+
)
103+
if (openedStandalone) {
69104
return
70105
}
71106
} catch (error) {
@@ -77,7 +112,7 @@
77112
'',
78113
buildViewerUrl(pending.url)
79114
)
80-
await window.PDFViewerApplication.open(pending.url)
115+
await pdfViewerApplication.open({ url: pending.url })
81116
return
82117
}
83118

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "saladict",
3-
"version": "7.21.0",
3+
"version": "7.22.0",
44
"description": "Chrome extension and Firefox WebExtension; inline translator powered by multiple online dictionaries",
55
"private": true,
66
"scripts": {
@@ -14,7 +14,7 @@
1414
"type-check": "tsc --noEmit",
1515
"test": "jest --testTimeout 20000",
1616
"test:watch": "jest --watch",
17-
"zip": "yarn neutrino-webextension-zip '!test' '!.git' '.env' 'assets/pdf' 'deps'",
17+
"zip": "node scripts/zip.js '!test' '!.git' '.env' 'assets/pdf' 'deps'",
1818
"postinstall": "node scripts/setup-env.js",
1919
"commit": "git-cz",
2020
"release": "standard-version",
@@ -68,7 +68,6 @@
6868
"@types/react": "^16.8.23",
6969
"@types/react-beautiful-dnd": "^13.0.0",
7070
"@types/react-dom": "^16.8.4",
71-
"@types/react-helmet": "^5.0.15",
7271
"@types/react-redux": "^7.1.2",
7372
"@types/react-resize-detector": "^4.0.2",
7473
"@types/react-textarea-autosize": "^4.3.4",
@@ -93,7 +92,6 @@
9392
"react": "^16.10.0",
9493
"react-beautiful-dnd": "^13.0.0",
9594
"react-dom": "^16.10.0",
96-
"react-helmet": "^6.0.0-beta.2",
9795
"react-hot-loader": "^4",
9896
"react-number-editor": "^4.0.3",
9997
"react-redux": "^7.1.0",
@@ -135,6 +133,7 @@
135133
"@types/storybook__react": "4.0.2",
136134
"@typescript-eslint/eslint-plugin": "^2.20.0",
137135
"@typescript-eslint/parser": "^2.20.0",
136+
"archiver": "^3.0.0",
138137
"autoprefixer": "^9.6.1",
139138
"axios-mock-adapter": "^1.17.0",
140139
"babel-plugin-import": "^1.12.1",
@@ -153,10 +152,12 @@
153152
"eslint-plugin-promise": "^4.2.1",
154153
"eslint-plugin-react": "^7.18.3",
155154
"eslint-plugin-standard": "^4.0.1",
155+
"extract-zip": "^2.0.1",
156156
"faker": "^4.1.0",
157157
"fast-glob": "^3.1.1",
158158
"form-data": "^2.5.1",
159159
"franc-min": "^4.1.1",
160+
"globby": "^10.0.1",
160161
"husky": "^4.3.0",
161162
"jest": "^26.1.0",
162163
"jest-fetch-mock": "^2.1.2",

0 commit comments

Comments
 (0)