Compare commits
108 Commits
Author | SHA1 | Date | |
---|---|---|---|
c2b9664b4b | |||
e760d2b022 | |||
1a836d914b | |||
1b0e6eb6c4 | |||
39827ad485 | |||
79c4d4e98f | |||
427bd2f348 | |||
4fefd0e128 | |||
d79060237d | |||
2df7a1c592 | |||
8c4ceb3e4b | |||
bf725ece72 | |||
76992bd4f4 | |||
dccd530475 | |||
f1fa01a0eb | |||
7949142ef6 | |||
af1da8fc0a | |||
39f4237cde | |||
b676ed74cd | |||
bf474877ca | |||
7ee13af238 | |||
d488e5874a | |||
b1a7c22452 | |||
e928d202ee | |||
c39961d253 | |||
c6d11fcd7f | |||
eb96103478 | |||
583ccfc7b1 | |||
e0437718a0 | |||
2126ae022b | |||
2ef39dcb19 | |||
047c865e76 | |||
c586cd00cc | |||
ee7f470269 | |||
f04dda308b | |||
071458e262 | |||
9ffc96de4d | |||
26e9a5404a | |||
f44fe59054 | |||
e4b0629dee | |||
5c2700ca36 | |||
639a582804 | |||
2d1f185fcd | |||
38735ed0ae | |||
216bc590da | |||
1c10d8005a | |||
1fcfbe5360 | |||
8d3dda1cec | |||
be18f667d9 | |||
027b2c4fb1 | |||
4ed92878be | |||
a6930f309e | |||
fdcdae0412 | |||
2c18ddaaa8 | |||
994e7ad0a6 | |||
95536b36be | |||
9c159d5d24 | |||
42ccfd5dc5 | |||
dabf7f8a28 | |||
9cac48f439 | |||
ef6bc840d8 | |||
1c38ec1357 | |||
a4436bd6c8 | |||
5a4b8143b2 | |||
00a5712427 | |||
6e55ee0745 | |||
56098a382e | |||
5ba9c7179b | |||
be9256ff1f | |||
92b2c32dd3 | |||
1935c7f444 | |||
4d48a2c395 | |||
3cf30aaf08 | |||
262c3e169b | |||
2a0cb6720f | |||
295077dd75 | |||
c484f82cf5 | |||
05aaac7ed8 | |||
9ef497028c | |||
380325bd43 | |||
164aa99eca | |||
0a9155dcec | |||
0bf9e76441 | |||
392681c1b7 | |||
d4024a16ad | |||
fba985482c | |||
094fb0ee84 | |||
2ccc12de90 | |||
28e6866db8 | |||
7185964649 | |||
cd1005823d | |||
0afceb9850 | |||
e6dc205b9d | |||
8e473c778b | |||
7a71ae5f37 | |||
d04f3db22f | |||
adc6b9dbb2 | |||
e8f09c80f3 | |||
46c4e66558 | |||
a8ea416a67 | |||
320c1ddafa | |||
4c576ba720 | |||
7b58779f9e | |||
45d835fe19 | |||
2d2826d192 | |||
4c77ad0f1f | |||
4d72ac4534 | |||
cdda0835d8 |
15
.github/ISSUE_TEMPLATE/bug_report.md
vendored
15
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -7,6 +7,11 @@ assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
@ -23,16 +28,6 @@ A clear and concise description of what you expected to happen.
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. iPhone6]
|
||||
- OS: [e.g. iOS8.1]
|
||||
- Browser [e.g. stock browser, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
10
LICENSE.md
10
LICENSE.md
@ -77,3 +77,13 @@ Licensed under the Mozilla Public License 2.0.
|
||||
|
||||
The list itself is licensed under the Mozilla Public License 2.0.
|
||||
The javascript library accessing it is licensed under the MIT license.
|
||||
|
||||
## whatwg-mimetype
|
||||
|
||||
Licensed under MIT
|
||||
|
||||
|
||||
## CDHeaderParser
|
||||
|
||||
Licensed under MPL-2
|
||||
(c) 2017 Rob Wu <rob@robwu.nl> (https://robwu.nl)
|
||||
|
51
Readme.md
51
Readme.md
@ -1,12 +1,10 @@
|
||||
DownThemAll! WE
|
||||
===
|
||||
# DownThemAll! WE
|
||||
|
||||
The DownThemAll! WebExtension.
|
||||
|
||||
For those still on supported browser: [Non-WebExtension legacy code](https://github.com/downthemall/downthemall-legacy).
|
||||
|
||||
About
|
||||
---
|
||||
## About
|
||||
|
||||
This is the WebExtension version of DownThemAll!, a complete re-development from scratch.
|
||||
Being a WebExtension it lacks a ton of features the original DownThemAll! had. Sorry, but there is no way around it since Mozilla decided to adopt WebExtensions as the *only* extension type and WebExtensions are extremely limited in what they can do.
|
||||
@ -23,25 +21,48 @@ But it is what it is...
|
||||
|
||||
**What we *can* do and did do is bring the mass selection, organizing (renaming masks, etc) and queueing tools of DownThemAll! over to the WebExtension, so you can easily queue up hundreds or thousands files at once without the downloads going up in flames because the browser tried to download them all at once.**
|
||||
|
||||
Translations
|
||||
---
|
||||
## Translations
|
||||
|
||||
If you would like to help out translating DTA, please see our [translation guide](_locales/Readme.md).
|
||||
|
||||
Development
|
||||
---
|
||||
## Development
|
||||
|
||||
|
||||
You will want to `yarn` the development dependencies such as webpack first.
|
||||
|
||||
Afterwards there is two important commands to run
|
||||
Afterwards, you will want to run`yarn watch`.
|
||||
This will run the webpack bundler in watch mode, transpiling the TypeScript to Javascript and updating bundles as you change the source.
|
||||
|
||||
* `yarn watch` - This will run the webpack bundler in watch mode, updating bundles as you change the source.
|
||||
* `yarn webext` - This will run the WebExtension in a development profile using the [`web-ext` tool from mozilla](https://www.npmjs.com/package/web-ext) (which you need to install separately). This will use the directory `../dtalite.p` to keep a development profile. You might need to create this directory before you use this command first.
|
||||
|
||||
Please note: You have to run `yarn watch` (at least once) as it builds the actual script bundles.
|
||||
|
||||
### Firefox
|
||||
|
||||
I recommend you install the [`web-ext`](https://www.npmjs.com/package/web-ext) tools from mozilla. It is not listed as a dependency by design at it causes problems with dependency resolution in yarn right now if installed in the same location as the rest of the dependencies.
|
||||
|
||||
If you did, then running `yarn webext` (additionally to `yarn watch`) will run the WebExtension in a development profile. This will use the directory `../dtalite.p` to keep a development profile. You might need to create this directory before you use this command. Furthermore `yarn webext` will watch for changes to the sources and automatically reload the extension.
|
||||
|
||||
Alternative, you can also `yarn build`, which then builds an *unsigned* zip that you can then install permanently in a browser that does not enforce signing (i.e. Nightly or the Unbranded Firefox).
|
||||
Alternative, you can also `yarn build`, which then builds an *unsigned* zip that you can then install permanently in a browser that does not enforce signing (i.e. Nightly or the Unbranded Firefox with the right about:config preferences).
|
||||
|
||||
Before submitting patches, please make sure you run eslint, if this isn't done automatically, and eslint does not report any open issues. Code contributions should favor typescript code over javascript code. External dependencies that would ship with the final product (including all npm/yarn packages) should be kept to a bare minimum.
|
||||
### Chrome
|
||||
|
||||
The code base is comparatively large for a WebExtension, with over 10K sloc of typescript and over 14K sloc total.
|
||||
You have to build the bundles first, of course.
|
||||
|
||||
Then put your Chrome into Developement Mode on the Extensions page, and Load Unpacked the directory of your downthemall clone.
|
||||
|
||||
### Patches
|
||||
|
||||
Before submitting patches, please make sure you run eslint (if this isn't done automatically in your text editor/IDE), and eslint does not report any open issues. Code contributions should favor typescript code over javascript code. External dependencies that would ship with the final product (including all npm/yarn packages) should be kept to a bare minimum and need justification.
|
||||
|
||||
Please submit your patches as Pull Requests, and rebase your commits onto the current `master` before submitting.
|
||||
|
||||
### Code structure
|
||||
|
||||
The code base is comparatively large for a WebExtension, with over 11K sloc of typescript.
|
||||
It isn't as well organized as it should be in some places; hope you don't mind.
|
||||
|
||||
* `uikit/` - The base User Interface Kit, which currently consists of
|
||||
* the `VirtualTable` implementation, aka that interactive HTML table with columns, columns resizing and hiding, etc you see in the Manager, Select and Preferences windows/tabs
|
||||
* the `ContextMenu` and related classes that drive the HTML-based context menus
|
||||
* `lib/` - The "backend stuff" and assorted library routines and classes.
|
||||
* `windows/` - The "frontend stuff" so all the HTML and corresponding code to make that HTML into something interactive
|
||||
* `style/` - CSS and images
|
||||
|
6
TODO.md
6
TODO.md
@ -13,12 +13,7 @@ Planned for later.
|
||||
* Delete files (well, as far as the browser allows)
|
||||
* Inter-addon API (basic)
|
||||
* Add downloads
|
||||
* Chrome support
|
||||
* vtable perf: cache column widths
|
||||
* Localizations
|
||||
* Settle on system
|
||||
* Do the de-locale
|
||||
* Enagage translators
|
||||
* Download options
|
||||
* This is a bit more limited, as we cannot modify options of downloads that have been started (and paused) or that are done.
|
||||
|
||||
@ -39,7 +34,6 @@ Nice-to-haves.
|
||||
* Dark Theme support
|
||||
* os/browser define be default
|
||||
* overwritable
|
||||
* Get and cache system icons (because Firefox doesn't allow moz-icon: for WE, but makes them kinda accessible through the downloads API anyway, essentially copying them via a canvas on a privileged hidden page into a data URL... ikr)
|
||||
* Remove `any` types as possible, and generally improve typescript (new language to me)
|
||||
|
||||
P4
|
||||
|
22
_locales/all.json
Normal file
22
_locales/all.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"ar": "العربية [ar]",
|
||||
"cs": "Čeština (CZ) [cs]",
|
||||
"de": "Deutsch [de]",
|
||||
"el": "Ελληνικά [el]",
|
||||
"en": "English (US) [en]",
|
||||
"es": "Español (España) [es]",
|
||||
"et": "Eesti Keel [et]",
|
||||
"fr": "Français [fr]",
|
||||
"hu": "Magyar (HU) [hu]",
|
||||
"id": "Bahasa Indonesia [id]",
|
||||
"it": "Italiano [it]",
|
||||
"ja": "日本語 (JP) [ja]",
|
||||
"ko": "한국어 [ko]",
|
||||
"lt": "Lietuvių [lt]",
|
||||
"nl": "Nederlands [nl]",
|
||||
"pl": "Polski [pl]",
|
||||
"pt": "Português (Brasil) [pt]",
|
||||
"ru": "Русский [ru]",
|
||||
"zh_CN": "简体中文 [zh_CN]",
|
||||
"zh_TW": "正體中文 [zh_TW]"
|
||||
}
|
1170
_locales/ar/messages.json
Normal file
1170
_locales/ar/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
1170
_locales/cs/messages.json
Normal file
1170
_locales/cs/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1170
_locales/el/messages.json
Normal file
1170
_locales/el/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1170
_locales/et/messages.json
Normal file
1170
_locales/et/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1170
_locales/hu/messages.json
Normal file
1170
_locales/hu/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
1030
_locales/id/messages.json
Normal file
1030
_locales/id/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
1170
_locales/it/messages.json
Normal file
1170
_locales/it/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
1170
_locales/ja/messages.json
Normal file
1170
_locales/ja/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
1170
_locales/ko/messages.json
Normal file
1170
_locales/ko/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1170
_locales/nl/messages.json
Normal file
1170
_locales/nl/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1170
_locales/ru/messages.json
Normal file
1170
_locales/ru/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
1170
_locales/zh_CN/messages.json
Normal file
1170
_locales/zh_CN/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
1170
_locales/zh_TW/messages.json
Normal file
1170
_locales/zh_TW/messages.json
Normal file
File diff suppressed because it is too large
Load Diff
396
data/mime.json
Normal file
396
data/mime.json
Normal file
@ -0,0 +1,396 @@
|
||||
{
|
||||
"e": {
|
||||
"3gpp": "3gp",
|
||||
"asx": "asf",
|
||||
"gz": "gzip",
|
||||
"heic": "heif",
|
||||
"html": [
|
||||
"htm",
|
||||
"shtml",
|
||||
"php"
|
||||
],
|
||||
"jar": [
|
||||
"war",
|
||||
"ear"
|
||||
],
|
||||
"jpg": [
|
||||
"jpeg",
|
||||
"jpe",
|
||||
"jfif"
|
||||
],
|
||||
"js": "jsx",
|
||||
"mid": [
|
||||
"midi",
|
||||
"kar"
|
||||
],
|
||||
"mkv": [
|
||||
"mk3d",
|
||||
"mks"
|
||||
],
|
||||
"mov": [
|
||||
"qt",
|
||||
"moov"
|
||||
],
|
||||
"mpg": [
|
||||
"mpe",
|
||||
"mpeg"
|
||||
],
|
||||
"pem": [
|
||||
"crt",
|
||||
"der"
|
||||
],
|
||||
"pl": "pm",
|
||||
"prc": "pdb",
|
||||
"ps": [
|
||||
"eps",
|
||||
"ai"
|
||||
],
|
||||
"svg": "svgz",
|
||||
"tcl": "tk",
|
||||
"tif": "tiff"
|
||||
},
|
||||
"m": {
|
||||
"application/7z": "7z",
|
||||
"application/7z-compressed": "7z",
|
||||
"application/ai": "ps",
|
||||
"application/atom": "atom",
|
||||
"application/atom+xml": "atom",
|
||||
"application/bz2": "bz2",
|
||||
"application/bzip2": "bz2",
|
||||
"application/cco": "cco",
|
||||
"application/cocoa": "cco",
|
||||
"application/compressed": "gz",
|
||||
"application/crt": "pem",
|
||||
"application/der": "pem",
|
||||
"application/doc": "doc",
|
||||
"application/ear": "jar",
|
||||
"application/eot": "eot",
|
||||
"application/eps": "ps",
|
||||
"application/gz": "gz",
|
||||
"application/gzip": "gz",
|
||||
"application/hqx": "hqx",
|
||||
"application/jar": "jar",
|
||||
"application/jardiff": "jardiff",
|
||||
"application/java-archive": "jar",
|
||||
"application/java-archive-diff": "jardiff",
|
||||
"application/java-jnlp-file": "jnlp",
|
||||
"application/javascript": "js",
|
||||
"application/jnlp": "jnlp",
|
||||
"application/js": "js",
|
||||
"application/json": "json",
|
||||
"application/jsx": "js",
|
||||
"application/kml": "kml",
|
||||
"application/kmz": "kmz",
|
||||
"application/m3u8": "m3u8",
|
||||
"application/mac-binhex40": "hqx",
|
||||
"application/makeself": "run",
|
||||
"application/msword": "doc",
|
||||
"application/odg": "odg",
|
||||
"application/odp": "odp",
|
||||
"application/ods": "ods",
|
||||
"application/odt": "odt",
|
||||
"application/pdb": "prc",
|
||||
"application/pdf": "pdf",
|
||||
"application/pem": "pem",
|
||||
"application/perl": "pl",
|
||||
"application/pilot": "prc",
|
||||
"application/pl": "pl",
|
||||
"application/pm": "pl",
|
||||
"application/postscript": "ps",
|
||||
"application/ppt": "ppt",
|
||||
"application/prc": "prc",
|
||||
"application/ps": "ps",
|
||||
"application/rar": "rar",
|
||||
"application/rar-compressed": "rar",
|
||||
"application/redhat-package-manager": "rpm",
|
||||
"application/rpm": "rpm",
|
||||
"application/rss": "rss",
|
||||
"application/rss+xml": "rss",
|
||||
"application/rtf": "rtf",
|
||||
"application/run": "run",
|
||||
"application/sea": "sea",
|
||||
"application/shockwave-flash": "swf",
|
||||
"application/sit": "sit",
|
||||
"application/stuffit": "sit",
|
||||
"application/swf": "swf",
|
||||
"application/tar": "tar",
|
||||
"application/tcl": "tcl",
|
||||
"application/tk": "tcl",
|
||||
"application/vnd.apple.mpegurl": "m3u8",
|
||||
"application/vnd.google-earth.kml+xml": "kml",
|
||||
"application/vnd.google-earth.kmz": "kmz",
|
||||
"application/vnd.ms-excel": "xls",
|
||||
"application/vnd.ms-fontobject": "eot",
|
||||
"application/vnd.ms-powerpoint": "ppt",
|
||||
"application/vnd.oasis.opendocument.graphics": "odg",
|
||||
"application/vnd.oasis.opendocument.presentation": "odp",
|
||||
"application/vnd.oasis.opendocument.spreadsheet": "ods",
|
||||
"application/vnd.oasis.opendocument.text": "odt",
|
||||
"application/vnd.wap.wmlc": "wmlc",
|
||||
"application/war": "jar",
|
||||
"application/wmlc": "wmlc",
|
||||
"application/x-7z": "7z",
|
||||
"application/x-7z-compressed": "7z",
|
||||
"application/x-ai": "ps",
|
||||
"application/x-atom": "atom",
|
||||
"application/x-atom+xml": "atom",
|
||||
"application/x-bz2": "bz2",
|
||||
"application/x-bzip2": "bz2",
|
||||
"application/x-cco": "cco",
|
||||
"application/x-cocoa": "cco",
|
||||
"application/x-compressed": "gz",
|
||||
"application/x-crt": "pem",
|
||||
"application/x-der": "pem",
|
||||
"application/x-doc": "doc",
|
||||
"application/x-ear": "jar",
|
||||
"application/x-eot": "eot",
|
||||
"application/x-eps": "ps",
|
||||
"application/x-gz": "gz",
|
||||
"application/x-gzip": "gz",
|
||||
"application/x-hqx": "hqx",
|
||||
"application/x-jar": "jar",
|
||||
"application/x-jardiff": "jardiff",
|
||||
"application/x-java-archive": "jar",
|
||||
"application/x-java-archive-diff": "jardiff",
|
||||
"application/x-java-jnlp-file": "jnlp",
|
||||
"application/x-javascript": "js",
|
||||
"application/x-jnlp": "jnlp",
|
||||
"application/x-js": "js",
|
||||
"application/x-json": "json",
|
||||
"application/x-jsx": "js",
|
||||
"application/x-kml": "kml",
|
||||
"application/x-kmz": "kmz",
|
||||
"application/x-m3u8": "m3u8",
|
||||
"application/x-mac-binhex40": "hqx",
|
||||
"application/x-makeself": "run",
|
||||
"application/x-msword": "doc",
|
||||
"application/x-odg": "odg",
|
||||
"application/x-odp": "odp",
|
||||
"application/x-ods": "ods",
|
||||
"application/x-odt": "odt",
|
||||
"application/x-pdb": "prc",
|
||||
"application/x-pdf": "pdf",
|
||||
"application/x-pem": "pem",
|
||||
"application/x-perl": "pl",
|
||||
"application/x-pilot": "prc",
|
||||
"application/x-pl": "pl",
|
||||
"application/x-pm": "pl",
|
||||
"application/x-postscript": "ps",
|
||||
"application/x-ppt": "ppt",
|
||||
"application/x-prc": "prc",
|
||||
"application/x-ps": "ps",
|
||||
"application/x-rar": "rar",
|
||||
"application/x-rar-compressed": "rar",
|
||||
"application/x-redhat-package-manager": "rpm",
|
||||
"application/x-rpm": "rpm",
|
||||
"application/x-rss": "rss",
|
||||
"application/x-rss+xml": "rss",
|
||||
"application/x-rtf": "rtf",
|
||||
"application/x-run": "run",
|
||||
"application/x-sea": "sea",
|
||||
"application/x-shockwave-flash": "swf",
|
||||
"application/x-sit": "sit",
|
||||
"application/x-stuffit": "sit",
|
||||
"application/x-swf": "swf",
|
||||
"application/x-tar": "tar",
|
||||
"application/x-tcl": "tcl",
|
||||
"application/x-tk": "tcl",
|
||||
"application/x-vnd.apple.mpegurl": "m3u8",
|
||||
"application/x-vnd.google-earth.kml+xml": "kml",
|
||||
"application/x-vnd.google-earth.kmz": "kmz",
|
||||
"application/x-vnd.ms-excel": "xls",
|
||||
"application/x-vnd.ms-fontobject": "eot",
|
||||
"application/x-vnd.ms-powerpoint": "ppt",
|
||||
"application/x-vnd.oasis.opendocument.graphics": "odg",
|
||||
"application/x-vnd.oasis.opendocument.presentation": "odp",
|
||||
"application/x-vnd.oasis.opendocument.spreadsheet": "ods",
|
||||
"application/x-vnd.oasis.opendocument.text": "odt",
|
||||
"application/x-vnd.wap.wmlc": "wmlc",
|
||||
"application/x-war": "jar",
|
||||
"application/x-wmlc": "wmlc",
|
||||
"application/x-x509-ca-cert": "pem",
|
||||
"application/x-xhtml": "xhtml",
|
||||
"application/x-xhtml+xml": "xhtml",
|
||||
"application/x-xls": "xls",
|
||||
"application/x-xpi": "xpi",
|
||||
"application/x-xpinstall": "xpi",
|
||||
"application/x-xspf": "xspf",
|
||||
"application/x-xspf+xml": "xspf",
|
||||
"application/x-xz": "xz",
|
||||
"application/x-zip": "zip",
|
||||
"application/x509-ca-cert": "pem",
|
||||
"application/xhtml": "xhtml",
|
||||
"application/xhtml+xml": "xhtml",
|
||||
"application/xls": "xls",
|
||||
"application/xpi": "xpi",
|
||||
"application/xpinstall": "xpi",
|
||||
"application/xspf": "xspf",
|
||||
"application/xspf+xml": "xspf",
|
||||
"application/xz": "xz",
|
||||
"application/zip": "zip",
|
||||
"audio/kar": "mid",
|
||||
"audio/m4a": "m4a",
|
||||
"audio/matroska": "mka",
|
||||
"audio/mid": "mid",
|
||||
"audio/midi": "mid",
|
||||
"audio/mka": "mka",
|
||||
"audio/mp3": "mp3",
|
||||
"audio/mpeg": "mp3",
|
||||
"audio/ogg": "ogg",
|
||||
"audio/ra": "ra",
|
||||
"audio/realaudio": "ra",
|
||||
"audio/x-kar": "mid",
|
||||
"audio/x-m4a": "m4a",
|
||||
"audio/x-matroska": "mka",
|
||||
"audio/x-mid": "mid",
|
||||
"audio/x-midi": "mid",
|
||||
"audio/x-mka": "mka",
|
||||
"audio/x-mp3": "mp3",
|
||||
"audio/x-mpeg": "mp3",
|
||||
"audio/x-ogg": "ogg",
|
||||
"audio/x-ra": "ra",
|
||||
"audio/x-realaudio": "ra",
|
||||
"font/woff": "woff",
|
||||
"font/woff2": "woff2",
|
||||
"font/x-woff": "woff",
|
||||
"font/x-woff2": "woff2",
|
||||
"image/bmp": "bmp",
|
||||
"image/gif": "gif",
|
||||
"image/heic": "heic",
|
||||
"image/heif": "heic",
|
||||
"image/heif-sequence": "heic",
|
||||
"image/ico": "ico",
|
||||
"image/icon": "ico",
|
||||
"image/jfif": "jpg",
|
||||
"image/jng": "jng",
|
||||
"image/jpe": "jpg",
|
||||
"image/jpeg": "jpg",
|
||||
"image/jpg": "jpg",
|
||||
"image/ms-bmp": "bmp",
|
||||
"image/png": "png",
|
||||
"image/svg": "svg",
|
||||
"image/svg+xml": "svg",
|
||||
"image/svgz": "svg",
|
||||
"image/tif": "tif",
|
||||
"image/tiff": "tif",
|
||||
"image/vnd.wap.wbmp": "wbmp",
|
||||
"image/wbmp": "wbmp",
|
||||
"image/webp": "webp",
|
||||
"image/x-bmp": "bmp",
|
||||
"image/x-gif": "gif",
|
||||
"image/x-heic": "heic",
|
||||
"image/x-heif": "heic",
|
||||
"image/x-heif-sequence": "heic",
|
||||
"image/x-ico": "ico",
|
||||
"image/x-icon": "ico",
|
||||
"image/x-jfif": "jpg",
|
||||
"image/x-jng": "jng",
|
||||
"image/x-jpe": "jpg",
|
||||
"image/x-jpeg": "jpg",
|
||||
"image/x-jpg": "jpg",
|
||||
"image/x-ms-bmp": "bmp",
|
||||
"image/x-png": "png",
|
||||
"image/x-svg": "svg",
|
||||
"image/x-svg+xml": "svg",
|
||||
"image/x-svgz": "svg",
|
||||
"image/x-tif": "tif",
|
||||
"image/x-tiff": "tif",
|
||||
"image/x-vnd.wap.wbmp": "wbmp",
|
||||
"image/x-wbmp": "wbmp",
|
||||
"image/x-webp": "webp",
|
||||
"text/component": "htc",
|
||||
"text/css": "css",
|
||||
"text/htc": "htc",
|
||||
"text/htm": "html",
|
||||
"text/html": "html",
|
||||
"text/jad": "jad",
|
||||
"text/javascript": "js",
|
||||
"text/js": "js",
|
||||
"text/jsx": "js",
|
||||
"text/mathml": "mml",
|
||||
"text/mml": "mml",
|
||||
"text/php": "html",
|
||||
"text/plain": "txt",
|
||||
"text/shtml": "html",
|
||||
"text/txt": "txt",
|
||||
"text/vnd.sun.j2me.app-descriptor": "jad",
|
||||
"text/vnd.wap.wml": "wml",
|
||||
"text/wml": "wml",
|
||||
"text/x-component": "htc",
|
||||
"text/x-css": "css",
|
||||
"text/x-htc": "htc",
|
||||
"text/x-htm": "html",
|
||||
"text/x-html": "html",
|
||||
"text/x-jad": "jad",
|
||||
"text/x-javascript": "js",
|
||||
"text/x-js": "js",
|
||||
"text/x-jsx": "js",
|
||||
"text/x-mathml": "mml",
|
||||
"text/x-mml": "mml",
|
||||
"text/x-php": "html",
|
||||
"text/x-plain": "txt",
|
||||
"text/x-shtml": "html",
|
||||
"text/x-txt": "txt",
|
||||
"text/x-vnd.sun.j2me.app-descriptor": "jad",
|
||||
"text/x-vnd.wap.wml": "wml",
|
||||
"text/x-wml": "wml",
|
||||
"text/x-xml": "xml",
|
||||
"text/xml": "xml",
|
||||
"video/3gp": "3gpp",
|
||||
"video/3gpp": "3gpp",
|
||||
"video/asf": "asx",
|
||||
"video/asx": "asx",
|
||||
"video/avi": "avi",
|
||||
"video/flv": "flv",
|
||||
"video/m4v": "m4v",
|
||||
"video/matroska": "mkv",
|
||||
"video/mk3d": "mkv",
|
||||
"video/mks": "mkv",
|
||||
"video/mkv": "mkv",
|
||||
"video/mng": "mng",
|
||||
"video/moov": "mov",
|
||||
"video/mov": "mov",
|
||||
"video/mp2t": "ts",
|
||||
"video/mp4": "mp4",
|
||||
"video/mpe": "mpg",
|
||||
"video/mpeg": "mpg",
|
||||
"video/mpg": "mpg",
|
||||
"video/ms-asf": "asx",
|
||||
"video/ms-wmv": "wmv",
|
||||
"video/msvideo": "avi",
|
||||
"video/opus": "opus",
|
||||
"video/qt": "mov",
|
||||
"video/quicktime": "mov",
|
||||
"video/ts": "ts",
|
||||
"video/webm": "webm",
|
||||
"video/wmv": "wmv",
|
||||
"video/x-3gp": "3gpp",
|
||||
"video/x-3gpp": "3gpp",
|
||||
"video/x-asf": "asx",
|
||||
"video/x-asx": "asx",
|
||||
"video/x-avi": "avi",
|
||||
"video/x-flv": "flv",
|
||||
"video/x-m4v": "m4v",
|
||||
"video/x-matroska": "mkv",
|
||||
"video/x-mk3d": "mkv",
|
||||
"video/x-mks": "mkv",
|
||||
"video/x-mkv": "mkv",
|
||||
"video/x-mng": "mng",
|
||||
"video/x-moov": "mov",
|
||||
"video/x-mov": "mov",
|
||||
"video/x-mp2t": "ts",
|
||||
"video/x-mp4": "mp4",
|
||||
"video/x-mpe": "mpg",
|
||||
"video/x-mpeg": "mpg",
|
||||
"video/x-mpg": "mpg",
|
||||
"video/x-ms-asf": "asx",
|
||||
"video/x-ms-wmv": "wmv",
|
||||
"video/x-msvideo": "avi",
|
||||
"video/x-opus": "opus",
|
||||
"video/x-qt": "mov",
|
||||
"video/x-quicktime": "mov",
|
||||
"video/x-ts": "ts",
|
||||
"video/x-webm": "webm",
|
||||
"video/x-wmv": "wmv"
|
||||
}
|
||||
}
|
@ -17,7 +17,11 @@ import {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
Tab,
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
MenuClickInfo
|
||||
MenuClickInfo,
|
||||
CHROME,
|
||||
runtime,
|
||||
history,
|
||||
sessions,
|
||||
} from "./browser";
|
||||
import { Bus } from "./bus";
|
||||
import { filterInSitu } from "./util";
|
||||
@ -27,9 +31,26 @@ const menus = typeof (_menus) !== "undefined" && _menus || _cmenus;
|
||||
|
||||
const GATHER = "/bundles/content-gather.js";
|
||||
|
||||
const CHROME_CONTEXTS = Object.freeze(new Set([
|
||||
"all",
|
||||
"audio",
|
||||
"browser_action",
|
||||
"editable",
|
||||
"frame",
|
||||
"image",
|
||||
"launcher",
|
||||
"link",
|
||||
"page",
|
||||
"page_action",
|
||||
"selection",
|
||||
"video",
|
||||
]));
|
||||
|
||||
async function runContentJob(tab: Tab, file: string, msg: any) {
|
||||
try {
|
||||
if (tab && tab.incognito && msg) {
|
||||
msg.private = tab.incognito;
|
||||
}
|
||||
const res = await tabs.executeScript(tab.id, {
|
||||
file,
|
||||
allFrames: true,
|
||||
@ -83,11 +104,15 @@ class Handler {
|
||||
|
||||
async performSelection(options: SelectionOptions) {
|
||||
try {
|
||||
const toptions: any = {
|
||||
currentWindow: true,
|
||||
discarded: false,
|
||||
};
|
||||
if (!CHROME) {
|
||||
toptions.hidden = false;
|
||||
}
|
||||
const selectedTabs = options.allTabs ?
|
||||
await tabs.query({
|
||||
currentWindow: true,
|
||||
discarded: false,
|
||||
hidden: false}) as any[] :
|
||||
await tabs.query(toptions) as any[] :
|
||||
[options.tab];
|
||||
|
||||
const textLinks = await Prefs.get("text-links", true);
|
||||
@ -146,10 +171,18 @@ locale.then(() => {
|
||||
this.onClicked = this.onClicked.bind(this);
|
||||
const alls = new Map<string, string[]>();
|
||||
const mcreate = (options: any) => {
|
||||
if (CHROME) {
|
||||
delete options.icons;
|
||||
options.contexts = options.contexts.
|
||||
filter((e: string) => CHROME_CONTEXTS.has(e));
|
||||
if (!options.contexts.length) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (options.contexts.includes("all")) {
|
||||
alls.set(options.id, options.contexts);
|
||||
}
|
||||
return menus.create(options);
|
||||
menus.create(options);
|
||||
};
|
||||
mcreate({
|
||||
id: "DTARegularLink",
|
||||
@ -389,7 +422,10 @@ locale.then(() => {
|
||||
}
|
||||
|
||||
async enumulate(action: string) {
|
||||
const tab = await tabs.query({active: true});
|
||||
const tab = await tabs.query({
|
||||
active: true,
|
||||
currentWindow: true,
|
||||
});
|
||||
if (!tab || !tab.length) {
|
||||
return;
|
||||
}
|
||||
@ -517,17 +553,62 @@ locale.then(() => {
|
||||
|
||||
function adjustAction(globalTurbo: boolean) {
|
||||
action.setPopup({
|
||||
popup: globalTurbo ? "" : null
|
||||
popup: globalTurbo ? "" : "/windows/popup.html"
|
||||
});
|
||||
action.setIcon({
|
||||
path: globalTurbo ? {
|
||||
16: "/style/button-turbo.png",
|
||||
32: "/style/button-turbo@2x.png",
|
||||
} : null
|
||||
} : {
|
||||
16: "/style/icon16.png",
|
||||
32: "/style/icon32.png",
|
||||
48: "/style/icon48.png",
|
||||
64: "/style/icon64.png",
|
||||
96: "/style/icon96.png",
|
||||
128: "/style/icon128.png",
|
||||
256: "/style/icon256.png"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
(async function init() {
|
||||
const urlBase = runtime.getURL("");
|
||||
history.onVisited.addListener(({url}: {url: string}) => {
|
||||
if (!url || !url.startsWith(urlBase)) {
|
||||
return;
|
||||
}
|
||||
history.deleteUrl({url});
|
||||
});
|
||||
const results: {url?: string}[] = await history.search({text: urlBase});
|
||||
for (const {url} of results) {
|
||||
if (!url) {
|
||||
continue;
|
||||
}
|
||||
history.deleteUrl({url});
|
||||
}
|
||||
|
||||
if (!CHROME) {
|
||||
const sessionRemover = async () => {
|
||||
for (const s of await sessions.getRecentlyClosed()) {
|
||||
if (s.tab) {
|
||||
if (s.tab.url.startsWith(urlBase)) {
|
||||
await sessions.forgetClosedTab(s.tab.windowId, s.tab.sessionId);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!s.window || !s.window.tabs || s.window.tabs.length > 1) {
|
||||
continue;
|
||||
}
|
||||
const [tab] = s.window.tabs;
|
||||
if (tab.url.startsWith(urlBase)) {
|
||||
await sessions.forgetClosedWindow(s.window.sessionId);
|
||||
}
|
||||
}
|
||||
};
|
||||
sessions.onChanged.addListener(sessionRemover);
|
||||
await sessionRemover();
|
||||
}
|
||||
|
||||
await Prefs.set("last-run", new Date());
|
||||
Prefs.get("global-turbo", false).then(v => adjustAction(v));
|
||||
Prefs.on("global-turbo", (prefs, key, value) => {
|
||||
|
@ -19,6 +19,7 @@ export interface MessageSender {
|
||||
|
||||
export interface Tab {
|
||||
id?: number;
|
||||
incognito?: boolean;
|
||||
}
|
||||
|
||||
export interface MenuClickInfo {
|
||||
@ -39,14 +40,71 @@ export interface RawPort {
|
||||
postMessage: (message: any) => void;
|
||||
}
|
||||
|
||||
export const {extension} = polyfill;
|
||||
export const {notifications} = polyfill;
|
||||
interface WebRequestFilter {
|
||||
urls?: string[];
|
||||
}
|
||||
|
||||
interface WebRequestListener {
|
||||
addListener(
|
||||
callback: Function,
|
||||
filter: WebRequestFilter,
|
||||
extraInfoSpec: string[]
|
||||
): void;
|
||||
removeListener(callback: Function): void;
|
||||
}
|
||||
|
||||
type Header = {name: string; value: string};
|
||||
|
||||
export interface DownloadOptions {
|
||||
conflictAction: string;
|
||||
filename: string;
|
||||
saveAs: boolean;
|
||||
url: string;
|
||||
method?: string;
|
||||
body?: string;
|
||||
incognito?: boolean;
|
||||
headers: Header[];
|
||||
}
|
||||
|
||||
export interface DownloadsQuery {
|
||||
id?: number;
|
||||
}
|
||||
|
||||
interface Downloads {
|
||||
download(download: DownloadOptions): Promise<number>;
|
||||
open(manId: number): Promise<void>;
|
||||
show(manId: number): Promise<void>;
|
||||
pause(manId: number): Promise<void>;
|
||||
resume(manId: number): Promise<void>;
|
||||
cancel(manId: number): Promise<void>;
|
||||
erase(query: DownloadsQuery): Promise<void>;
|
||||
search(query: DownloadsQuery): Promise<any[]>;
|
||||
getFileIcon(id: number, options?: any): Promise<string>;
|
||||
setShelfEnabled(state: boolean): void;
|
||||
onCreated: ExtensionListener;
|
||||
onChanged: ExtensionListener;
|
||||
onErased: ExtensionListener;
|
||||
}
|
||||
|
||||
interface WebRequest {
|
||||
onBeforeSendHeaders: WebRequestListener;
|
||||
onSendHeaders: WebRequestListener;
|
||||
onHeadersReceived: WebRequestListener;
|
||||
}
|
||||
|
||||
export const {browserAction} = polyfill;
|
||||
export const {contextMenus} = polyfill;
|
||||
export const {downloads} = polyfill;
|
||||
export const {downloads}: {downloads: Downloads} = polyfill;
|
||||
export const {extension} = polyfill;
|
||||
export const {history} = polyfill;
|
||||
export const {menus} = polyfill;
|
||||
export const {notifications} = polyfill;
|
||||
export const {runtime} = polyfill;
|
||||
export const {sessions} = polyfill;
|
||||
export const {storage} = polyfill;
|
||||
export const {tabs} = polyfill;
|
||||
export const {webNavigation} = polyfill;
|
||||
export const {webRequest}: {webRequest: WebRequest} = polyfill;
|
||||
export const {windows} = polyfill;
|
||||
|
||||
export const CHROME = navigator.appVersion.includes("Chrome/");
|
||||
|
230
lib/cdheaderparser.ts
Normal file
230
lib/cdheaderparser.ts
Normal file
@ -0,0 +1,230 @@
|
||||
/**
|
||||
* (c) 2017 Rob Wu <rob@robwu.nl> (https://robwu.nl)
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
/* eslint-disable max-len,no-magic-numbers */
|
||||
// License: MPL-2
|
||||
|
||||
/**
|
||||
* This typescript port was done by Nils Maier based on
|
||||
* https://github.com/Rob--W/open-in-browser/blob/83248155b633ed41bc9cdb1205042653e644abd2/extension/content-disposition.js
|
||||
* Special thanks goes to Rob doing all the heavy lifting and putting
|
||||
* it together in a reuseable, open source'd library.
|
||||
*/
|
||||
|
||||
const R_RFC6266 = /(?:^|;)\s*filename\*\s*=\s*([^";\s][^;\s]*|"(?:[^"\\]|\\"?)+"?)/i;
|
||||
const R_RFC5987 = /(?:^|;)\s*filename\s*=\s*([^";\s][^;\s]*|"(?:[^"\\]|\\"?)+"?)/i;
|
||||
|
||||
function unquoteRFC2616(value: string) {
|
||||
if (!value.startsWith("\"")) {
|
||||
return value;
|
||||
}
|
||||
|
||||
const parts = value.slice(1).split("\\\"");
|
||||
// Find the first unescaped " and terminate there.
|
||||
for (let i = 0; i < parts.length; ++i) {
|
||||
const quotindex = parts[i].indexOf("\"");
|
||||
if (quotindex !== -1) {
|
||||
parts[i] = parts[i].slice(0, quotindex);
|
||||
// Truncate and stop the iteration.
|
||||
parts.length = i + 1;
|
||||
}
|
||||
parts[i] = parts[i].replace(/\\(.)/g, "$1");
|
||||
}
|
||||
value = parts.join("\"");
|
||||
return value;
|
||||
}
|
||||
|
||||
export class CDHeaderParser {
|
||||
private needsFixup: boolean;
|
||||
|
||||
// We need to keep this per instance, because of the global flag.
|
||||
// Hence we need to reset it after a use.
|
||||
private R_MULTI = /(?:^|;)\s*filename\*((?!0\d)\d+)(\*?)\s*=\s*([^";\s][^;\s]*|"(?:[^"\\]|\\"?)+"?)/gi;
|
||||
|
||||
/**
|
||||
* Parse a content-disposition header, with relaxed spec tolerance
|
||||
*
|
||||
* @param {string} header Header to parse
|
||||
* @returns {string} Parsed header
|
||||
*/
|
||||
parse(header: string) {
|
||||
this.needsFixup = true;
|
||||
|
||||
// filename*=ext-value ("ext-value" from RFC 5987, referenced by RFC 6266).
|
||||
{
|
||||
const match = R_RFC6266.exec(header);
|
||||
if (match) {
|
||||
const [, tmp] = match;
|
||||
let filename = unquoteRFC2616(tmp);
|
||||
filename = unescape(filename);
|
||||
filename = this.decodeRFC5897(filename);
|
||||
filename = this.decodeRFC2047(filename);
|
||||
return this.maybeFixupEncoding(filename);
|
||||
}
|
||||
}
|
||||
|
||||
// Continuations (RFC 2231 section 3, referenced by RFC 5987 section 3.1).
|
||||
// filename*n*=part
|
||||
// filename*n=part
|
||||
{
|
||||
const tmp = this.getParamRFC2231(header);
|
||||
if (tmp) {
|
||||
// RFC 2047, section
|
||||
const filename = this.decodeRFC2047(tmp);
|
||||
return this.maybeFixupEncoding(filename);
|
||||
}
|
||||
}
|
||||
|
||||
// filename=value (RFC 5987, section 4.1).
|
||||
{
|
||||
const match = R_RFC5987.exec(header);
|
||||
if (match) {
|
||||
const [, tmp] = match;
|
||||
let filename = unquoteRFC2616(tmp);
|
||||
filename = this.decodeRFC2047(filename);
|
||||
return this.maybeFixupEncoding(filename);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private maybeDecode(encoding: string, value: string) {
|
||||
if (!encoding) {
|
||||
return value;
|
||||
}
|
||||
const bytes = Array.from(value, c => c.charCodeAt(0));
|
||||
if (!bytes.every(code => code <= 0xff)) {
|
||||
return value;
|
||||
}
|
||||
try {
|
||||
value = new TextDecoder(encoding, {fatal: true}).
|
||||
decode(new Uint8Array(bytes));
|
||||
this.needsFixup = false;
|
||||
}
|
||||
catch {
|
||||
// TextDecoder constructor threw - unrecognized encoding.
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private maybeFixupEncoding(value: string) {
|
||||
if (!this.needsFixup && /[\x80-\xff]/.test(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Maybe multi-byte UTF-8.
|
||||
value = this.maybeDecode("utf-8", value);
|
||||
if (!this.needsFixup) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Try iso-8859-1 encoding.
|
||||
return this.maybeDecode("iso-8859-1", value);
|
||||
}
|
||||
|
||||
private getParamRFC2231(value: string) {
|
||||
const matches: string[][] = [];
|
||||
|
||||
// Iterate over all filename*n= and filename*n*= with n being an integer
|
||||
// of at least zero. Any non-zero number must not start with '0'.
|
||||
let match;
|
||||
this.R_MULTI.lastIndex = 0;
|
||||
while ((match = this.R_MULTI.exec(value)) !== null) {
|
||||
const [, num, quot, part] = match;
|
||||
const n = parseInt(num, 10);
|
||||
if (n in matches) {
|
||||
// Ignore anything after the invalid second filename*0.
|
||||
if (n === 0) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
matches[n] = [quot, part];
|
||||
}
|
||||
|
||||
const parts: string[] = [];
|
||||
for (let n = 0; n < matches.length; ++n) {
|
||||
if (!(n in matches)) {
|
||||
// Numbers must be consecutive. Truncate when there is a hole.
|
||||
break;
|
||||
}
|
||||
const [quot, rawPart] = matches[n];
|
||||
let part = unquoteRFC2616(rawPart);
|
||||
if (quot) {
|
||||
part = unescape(part);
|
||||
if (n === 0) {
|
||||
part = this.decodeRFC5897(part);
|
||||
}
|
||||
}
|
||||
parts.push(part);
|
||||
}
|
||||
return parts.join("");
|
||||
}
|
||||
|
||||
private decodeRFC2047(value: string) {
|
||||
// RFC 2047-decode the result. Firefox tried to drop support for it, but
|
||||
// backed out because some servers use it - https://bugzil.la/875615
|
||||
// Firefox's condition for decoding is here:
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
// https://searchfox.org/mozilla-central/rev/4a590a5a15e35d88a3b23dd6ac3c471cf85b04a8/netwerk/mime/nsMIMEHeaderParamImpl.cpp#742-748
|
||||
|
||||
// We are more strict and only recognize RFC 2047-encoding if the value
|
||||
// starts with "=?", since then it is likely that the full value is
|
||||
// RFC 2047-encoded.
|
||||
|
||||
// Firefox also decodes words even where RFC 2047 section 5 states:
|
||||
// "An 'encoded-word' MUST NOT appear within a 'quoted-string'."
|
||||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
|
||||
return value;
|
||||
}
|
||||
// RFC 2047, section 2.4
|
||||
// encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
|
||||
// charset = token (but let's restrict to characters that denote a
|
||||
// possibly valid encoding).
|
||||
// encoding = q or b
|
||||
// encoded-text = any printable ASCII character other than ? or space.
|
||||
// ... but Firefox permits ? and space.
|
||||
return value.replace(
|
||||
/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,
|
||||
(_, charset, encoding, text) => {
|
||||
if (encoding === "q" || encoding === "Q") {
|
||||
// RFC 2047 section 4.2.
|
||||
text = text.replace(/_/g, " ");
|
||||
text = text.replace(/=([0-9a-fA-F]{2})/g,
|
||||
(_: string, hex: string) => String.fromCharCode(parseInt(hex, 16)));
|
||||
return this.maybeDecode(charset, text);
|
||||
}
|
||||
|
||||
// else encoding is b or B - base64 (RFC 2047 section 4.1)
|
||||
try {
|
||||
text = atob(text);
|
||||
}
|
||||
catch {
|
||||
// ignored
|
||||
}
|
||||
return this.maybeDecode(charset, text);
|
||||
});
|
||||
}
|
||||
|
||||
private decodeRFC5897(extValue: string) {
|
||||
// Decodes "ext-value" from RFC 5987.
|
||||
const extEnd = extValue.indexOf("'");
|
||||
if (extEnd < 0) {
|
||||
// Some servers send "filename*=" without encoding'language' prefix,
|
||||
// e.g. in https://github.com/Rob--W/open-in-browser/issues/26
|
||||
// Let's accept the value like Firefox (57) (Chrome 62 rejects it).
|
||||
return extValue;
|
||||
}
|
||||
const encoding = extValue.slice(0, extEnd);
|
||||
const langvalue = extValue.slice(extEnd + 1);
|
||||
// Ignore language (RFC 5987 section 3.2.1, and RFC 6266 section 4.1 ).
|
||||
return this.maybeDecode(encoding, langvalue.replace(/^[^']*'/, ""));
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ import { EventEmitter } from "./events";
|
||||
import { TYPE_LINK, TYPE_MEDIA, TYPE_ALL } from "./constants";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import { Overlayable } from "./objectoverlay";
|
||||
import * as DEFAULT_FILTERS from "../data/filters.json";
|
||||
import DEFAULT_FILTERS from "../data/filters.json";
|
||||
import { FASTFILTER } from "./recentlist";
|
||||
import { _, locale } from "./i18n";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
@ -94,7 +94,7 @@ function *parseIntoRegexpInternal(str: string): Iterable<RegExp> {
|
||||
|
||||
// multi-expression
|
||||
if (str.includes(",")) {
|
||||
for (const part in str.split(",")) {
|
||||
for (const part of str.split(",")) {
|
||||
yield *parseIntoRegexpInternal(part);
|
||||
}
|
||||
return;
|
||||
|
66
lib/i18n.ts
66
lib/i18n.ts
@ -2,6 +2,19 @@
|
||||
// License: MIT
|
||||
|
||||
import {memoize} from "./memoize";
|
||||
import langs from "../_locales/all.json";
|
||||
import { sorted, naturalCaseCompare } from "./sorting";
|
||||
|
||||
|
||||
export const ALL_LANGS = Object.freeze(new Map<string, string>(
|
||||
sorted(Object.entries(langs), e => {
|
||||
return [e[1], e[0]];
|
||||
}, naturalCaseCompare)));
|
||||
|
||||
let CURRENT = "en";
|
||||
export function getCurrentLanguage() {
|
||||
return CURRENT;
|
||||
}
|
||||
|
||||
declare let browser: any;
|
||||
declare let chrome: any;
|
||||
@ -9,6 +22,8 @@ declare let chrome: any;
|
||||
const CACHE_KEY = "_cached_locales";
|
||||
const CUSTOM_KEY = "_custom_locale";
|
||||
|
||||
const normalizer = /[^A-Za-z0-9_]/g;
|
||||
|
||||
interface JSONEntry {
|
||||
message: string;
|
||||
placeholders: any;
|
||||
@ -72,7 +87,7 @@ class Localization {
|
||||
}
|
||||
|
||||
localize(id: string, ...args: any[]) {
|
||||
const entry = this.strings.get(id);
|
||||
const entry = this.strings.get(id.replace(normalizer, "_"));
|
||||
if (!entry) {
|
||||
return "";
|
||||
}
|
||||
@ -119,16 +134,36 @@ function loadCached() {
|
||||
}
|
||||
|
||||
async function loadRawLocales() {
|
||||
// en is the base locale
|
||||
// en is the base locale, always to be loaded
|
||||
// The loader will override string from it with more specific string
|
||||
// from other locales
|
||||
const langs = new Set<string>(["en"]);
|
||||
const ui = (browser.i18n || chrome.i18n).getUILanguage();
|
||||
langs.add(ui);
|
||||
if (ui.includes("-")) {
|
||||
// Try the base too
|
||||
langs.add(ui.split(/[_-]+/)[0]);
|
||||
|
||||
const uiLang: string = (typeof browser !== "undefined" ? browser : chrome).
|
||||
i18n.getUILanguage();
|
||||
|
||||
// Chrome will only look for underscore versions of locale codes,
|
||||
// while Firefox will look for both.
|
||||
// So we better normalize the code to the underscore version.
|
||||
// However, the API seems to always return the dash-version.
|
||||
|
||||
// Add all base locales into ascending order of priority,
|
||||
// starting with the most unspecific base locale, ending
|
||||
// with the most specific locale.
|
||||
// e.g. this will transform ["zh", "CN"] -> ["zh", "zh_CN"]
|
||||
uiLang.split(/[_-]/g).reduce<string[]>((prev, curr) => {
|
||||
prev.push(curr);
|
||||
langs.add(prev.join("_"));
|
||||
return prev;
|
||||
}, []);
|
||||
|
||||
if (CURRENT && CURRENT !== "default") {
|
||||
langs.delete(CURRENT);
|
||||
langs.add(CURRENT);
|
||||
}
|
||||
|
||||
const fetched = await Promise.all(Array.from(langs, fetchLanguage));
|
||||
const valid = Array.from(langs).filter(e => ALL_LANGS.has(e));
|
||||
const fetched = await Promise.all(Array.from(valid, fetchLanguage));
|
||||
return fetched.filter(e => !!e);
|
||||
}
|
||||
|
||||
@ -136,6 +171,21 @@ async function load(): Promise<Localization> {
|
||||
try {
|
||||
checkBrowser();
|
||||
try {
|
||||
let currentLang: any = "";
|
||||
if (typeof browser !== "undefined") {
|
||||
currentLang = await browser.storage.sync.get("language");
|
||||
}
|
||||
else {
|
||||
currentLang = await new Promise(
|
||||
resolve => chrome.storage.sync.get("language", resolve));
|
||||
}
|
||||
if ("language" in currentLang) {
|
||||
currentLang = currentLang.language;
|
||||
}
|
||||
if (!currentLang || !currentLang.length) {
|
||||
currentLang = "default";
|
||||
}
|
||||
CURRENT = currentLang;
|
||||
// en is the base locale
|
||||
let valid = loadCached();
|
||||
if (!valid) {
|
||||
|
162
lib/iconcache.ts
Normal file
162
lib/iconcache.ts
Normal file
@ -0,0 +1,162 @@
|
||||
"use strict";
|
||||
// License: MIT
|
||||
|
||||
import { downloads, CHROME } from "./browser";
|
||||
import { EventEmitter } from "../uikit/lib/events";
|
||||
import { PromiseSerializer } from "./pserializer";
|
||||
|
||||
const VERSION = 1;
|
||||
const STORE = "iconcache";
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
const CACHE_SIZES = CHROME ? [16, 32] : [16, 32, 64, 127];
|
||||
|
||||
const BLACKLISTED = Object.freeze(new Set([
|
||||
"",
|
||||
"ext",
|
||||
"ico",
|
||||
"pif",
|
||||
"scr",
|
||||
"ani",
|
||||
"cur",
|
||||
"ttf",
|
||||
"otf",
|
||||
"woff",
|
||||
"woff2",
|
||||
"cpl",
|
||||
"desktop",
|
||||
"app",
|
||||
]));
|
||||
|
||||
async function getIcon(size: number, manId: number) {
|
||||
const raw = await downloads.getFileIcon(manId, {size});
|
||||
const icon = new URL(raw);
|
||||
if (icon.protocol === "data:") {
|
||||
const res = await fetch(icon.toString());
|
||||
const blob = await res.blob();
|
||||
return {size, icon: blob};
|
||||
}
|
||||
return {size, icon};
|
||||
}
|
||||
|
||||
const SYNONYMS = Object.freeze(new Map<string, string>([
|
||||
["jpe", "jpg"],
|
||||
["jpeg", "jpg"],
|
||||
["jfif", "jpg"],
|
||||
["mpe", "mpg"],
|
||||
["mpeg", "mpg"],
|
||||
["m4v", "mp4"],
|
||||
]));
|
||||
|
||||
export const IconCache = new class IconCache extends EventEmitter {
|
||||
private db: Promise<IDBDatabase>;
|
||||
|
||||
private cache: Map<string, string>;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.db = this.init();
|
||||
this.cache = new Map();
|
||||
this.get = PromiseSerializer.wrapNew(8, this, this.get);
|
||||
this.set = PromiseSerializer.wrapNew(1, this, this.set);
|
||||
}
|
||||
|
||||
private async init() {
|
||||
return await new Promise<IDBDatabase>((resolve, reject) => {
|
||||
const req = indexedDB.open(STORE, VERSION);
|
||||
req.onupgradeneeded = evt => {
|
||||
const db = req.result;
|
||||
switch (evt.oldVersion) {
|
||||
case 0: {
|
||||
db.createObjectStore(STORE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
req.onerror = ex => reject(ex);
|
||||
req.onsuccess = () => {
|
||||
resolve(req.result);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private normalize(ext: string) {
|
||||
ext = ext.toLocaleLowerCase();
|
||||
return SYNONYMS.get(ext) || ext;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
async get(ext: string, size = 16) {
|
||||
ext = this.normalize(ext);
|
||||
if (BLACKLISTED.has(ext)) {
|
||||
return undefined;
|
||||
}
|
||||
const sext = `${ext}-${size}`;
|
||||
let rv = this.cache.get(sext);
|
||||
if (rv) {
|
||||
return rv;
|
||||
}
|
||||
const db = await this.db;
|
||||
rv = this.cache.get(sext);
|
||||
if (rv) {
|
||||
return rv;
|
||||
}
|
||||
return await new Promise<string | undefined>(resolve => {
|
||||
const trans = db.transaction(STORE, "readonly");
|
||||
trans.onerror = () => resolve(undefined);
|
||||
const store = trans.objectStore(STORE);
|
||||
const req = store.get(sext);
|
||||
req.onerror = () => resolve(undefined);
|
||||
req.onsuccess = () => {
|
||||
const rv = this.cache.get(sext);
|
||||
if (rv) {
|
||||
resolve(rv);
|
||||
return;
|
||||
}
|
||||
let {result} = req;
|
||||
if (!result) {
|
||||
resolve(undefined);
|
||||
return;
|
||||
}
|
||||
if (typeof req.result !== "string") {
|
||||
result = URL.createObjectURL(result).toString();
|
||||
}
|
||||
this.cache.set(sext, result);
|
||||
this.cache.set(ext, "");
|
||||
resolve(result);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async set(ext: string, manId: number) {
|
||||
ext = this.normalize(ext);
|
||||
if (BLACKLISTED.has(ext)) {
|
||||
return;
|
||||
}
|
||||
if (this.cache.has(ext)) {
|
||||
// already processed in this session
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
const urls = await Promise.all(CACHE_SIZES.map(
|
||||
size => getIcon(size, manId)));
|
||||
if (this.cache.has(ext)) {
|
||||
// already processed in this session
|
||||
return;
|
||||
}
|
||||
for (const {size, icon} of urls) {
|
||||
this.cache.set(`${ext}-${size}`, URL.createObjectURL(icon));
|
||||
}
|
||||
this.cache.set(ext, "");
|
||||
const db = await this.db;
|
||||
await new Promise((resolve, reject) => {
|
||||
const trans = db.transaction(STORE, "readwrite");
|
||||
trans.onerror = reject;
|
||||
trans.oncomplete = resolve;
|
||||
const store = trans.objectStore(STORE);
|
||||
for (const {size, icon} of urls) {
|
||||
store.put(icon, `${ext}-${size}`);
|
||||
}
|
||||
});
|
||||
this.emit("cached", ext);
|
||||
}
|
||||
}();
|
@ -27,6 +27,9 @@ const SAVEDPROPS = [
|
||||
"written",
|
||||
// server stuff
|
||||
"serverName",
|
||||
"browserName",
|
||||
"mime",
|
||||
"prerolled",
|
||||
// other options
|
||||
"private",
|
||||
// db
|
||||
@ -39,10 +42,13 @@ const DEFAULTS = {
|
||||
state: QUEUED,
|
||||
error: "",
|
||||
serverName: "",
|
||||
browserName: "",
|
||||
fileName: "",
|
||||
totalSize: 0,
|
||||
written: 0,
|
||||
manId: 0,
|
||||
mime: "",
|
||||
prerolled: false
|
||||
};
|
||||
|
||||
let sessionId = 0;
|
||||
@ -59,14 +65,26 @@ export class BaseDownload {
|
||||
|
||||
public url: string;
|
||||
|
||||
public usable: string;
|
||||
|
||||
public uReferrer: URLd;
|
||||
|
||||
public referrer: string;
|
||||
|
||||
public usableReferrer: string;
|
||||
|
||||
public startDate: Date;
|
||||
|
||||
public fileName: string;
|
||||
|
||||
public description?: string;
|
||||
|
||||
public title?: string;
|
||||
|
||||
public batch: number;
|
||||
|
||||
public idx: number;
|
||||
|
||||
public error: string;
|
||||
|
||||
public postData: any;
|
||||
@ -79,8 +97,13 @@ export class BaseDownload {
|
||||
|
||||
public serverName: string;
|
||||
|
||||
public browserName: string;
|
||||
|
||||
public mime: string;
|
||||
|
||||
public mask: string;
|
||||
|
||||
public prerolled: boolean;
|
||||
|
||||
constructor(options: any) {
|
||||
Object.assign(this, DEFAULTS);
|
||||
@ -115,6 +138,10 @@ export class BaseDownload {
|
||||
return this.serverName || this.fileName || this.urlName || "index.html";
|
||||
}
|
||||
|
||||
get currentName() {
|
||||
return this.browserName || this.dest.name || this.finalName;
|
||||
}
|
||||
|
||||
get urlName() {
|
||||
const path = parsePath(this.uURL);
|
||||
if (path.name) {
|
||||
@ -152,7 +179,9 @@ export class BaseDownload {
|
||||
rv.destName = dest.name;
|
||||
rv.destPath = dest.path;
|
||||
rv.destFull = dest.full;
|
||||
rv.currentName = this.browserName || rv.destName || rv.finalName;
|
||||
rv.error = this.error;
|
||||
rv.ext = this.renamer.p_ext;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,27 @@
|
||||
"use strict";
|
||||
// License: MIT
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import { CHROME, downloads, DownloadOptions } from "../browser";
|
||||
import { Prefs } from "../prefs";
|
||||
import { parsePath, filterInSitu } from "../util";
|
||||
import {
|
||||
QUEUED, RUNNING, CANCELED, PAUSED, MISSING, DONE,
|
||||
FORCABLE, PAUSABLE, CANCELABLE,
|
||||
} from "./state";
|
||||
import { BaseDownload } from "./basedownload";
|
||||
import { PromiseSerializer } from "../pserializer";
|
||||
import { filterInSitu, parsePath } from "../util";
|
||||
import { BaseDownload } from "./basedownload";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import { Manager } from "./man";
|
||||
import { downloads } from "../browser";
|
||||
|
||||
|
||||
const setShelfEnabled = downloads.setShelfEnabled || function() {
|
||||
// ignored
|
||||
};
|
||||
|
||||
type Header = {name: string; value: string};
|
||||
interface Options {
|
||||
conflictAction: string;
|
||||
filename: string;
|
||||
saveAs: boolean;
|
||||
url: string;
|
||||
method?: string;
|
||||
body?: string;
|
||||
incognito: boolean;
|
||||
headers: Header[];
|
||||
}
|
||||
import Renamer from "./renamer";
|
||||
import {
|
||||
CANCELABLE,
|
||||
CANCELED,
|
||||
DONE,
|
||||
FORCABLE,
|
||||
MISSING,
|
||||
PAUSABLE,
|
||||
PAUSED,
|
||||
QUEUED,
|
||||
RUNNING
|
||||
} from "./state";
|
||||
import { Preroller } from "./preroller";
|
||||
|
||||
export class Download extends BaseDownload {
|
||||
public manager: Manager;
|
||||
@ -50,6 +43,7 @@ export class Download extends BaseDownload {
|
||||
}
|
||||
|
||||
markDirty() {
|
||||
this.renamer = new Renamer(this);
|
||||
this.manager.setDirty(this);
|
||||
}
|
||||
|
||||
@ -71,18 +65,23 @@ export class Download extends BaseDownload {
|
||||
if (this.manId) {
|
||||
const {manId: id} = this;
|
||||
try {
|
||||
const state = await downloads.search({id});
|
||||
if (state[0].state === "in_progress") {
|
||||
const state = (await downloads.search({id})).pop() || {};
|
||||
if (state.state === "in_progress" && !state.error && !state.paused) {
|
||||
this.changeState(RUNNING);
|
||||
this.updateStateFromBrowser();
|
||||
return;
|
||||
}
|
||||
if (!state[0].canResume) {
|
||||
if (state.state === "complete") {
|
||||
this.changeState(DONE);
|
||||
this.updateStateFromBrowser();
|
||||
return;
|
||||
}
|
||||
if (!state.canResume) {
|
||||
throw new Error("Cannot resume");
|
||||
}
|
||||
// Cannot await here
|
||||
// Firefox bug: will not return until download is finished
|
||||
downloads.resume(id).catch(() => {});
|
||||
downloads.resume(id).catch(console.error);
|
||||
this.changeState(RUNNING);
|
||||
return;
|
||||
}
|
||||
@ -94,49 +93,64 @@ export class Download extends BaseDownload {
|
||||
if (this.state !== QUEUED) {
|
||||
throw new Error("invalid state");
|
||||
}
|
||||
console.trace("starting", this.toString(), this.toMsg());
|
||||
console.log("starting", this.toString(), this.toMsg());
|
||||
this.changeState(RUNNING);
|
||||
|
||||
// Do NOT await
|
||||
this.reallyStart();
|
||||
}
|
||||
|
||||
private async reallyStart() {
|
||||
try {
|
||||
const options: Options = {
|
||||
if (!this.prerolled) {
|
||||
await this.maybePreroll();
|
||||
if (this.state !== RUNNING) {
|
||||
// Aborted by preroll
|
||||
return;
|
||||
}
|
||||
}
|
||||
const options: DownloadOptions = {
|
||||
conflictAction: await Prefs.get("conflict-action"),
|
||||
filename: this.dest.full,
|
||||
saveAs: false,
|
||||
url: this.url,
|
||||
headers: [],
|
||||
incognito: this.private
|
||||
};
|
||||
if (!CHROME && this.private) {
|
||||
options.incognito = true;
|
||||
}
|
||||
if (this.postData) {
|
||||
options.body = this.postData;
|
||||
options.method = "POST";
|
||||
}
|
||||
if (this.referrer) {
|
||||
if (!CHROME && this.referrer) {
|
||||
options.headers.push({
|
||||
name: "Referer",
|
||||
value: this.referrer
|
||||
});
|
||||
}
|
||||
else if (CHROME) {
|
||||
options.headers.push({
|
||||
name: "X-DTA-ID",
|
||||
value: this.sessionId.toString(),
|
||||
});
|
||||
}
|
||||
if (this.manId) {
|
||||
this.manager.removeManId(this.manId);
|
||||
}
|
||||
|
||||
setShelfEnabled(false);
|
||||
try {
|
||||
try {
|
||||
this.manager.addManId(
|
||||
this.manId = await downloads.download(options), this);
|
||||
}
|
||||
catch (ex) {
|
||||
if (!this.referrer) {
|
||||
throw ex;
|
||||
}
|
||||
// Re-attempt without referrer
|
||||
filterInSitu(options.headers, h => h.name !== "Referer");
|
||||
this.manager.addManId(
|
||||
this.manId = await downloads.download(options), this);
|
||||
}
|
||||
this.manager.addManId(
|
||||
this.manId = await downloads.download(options), this);
|
||||
}
|
||||
finally {
|
||||
setShelfEnabled(true);
|
||||
catch (ex) {
|
||||
if (!this.referrer) {
|
||||
throw ex;
|
||||
}
|
||||
// Re-attempt without referrer
|
||||
filterInSitu(options.headers, h => h.name !== "Referer");
|
||||
this.manager.addManId(
|
||||
this.manId = await downloads.download(options), this);
|
||||
}
|
||||
this.markDirty();
|
||||
}
|
||||
@ -147,6 +161,42 @@ export class Download extends BaseDownload {
|
||||
}
|
||||
}
|
||||
|
||||
private async maybePreroll() {
|
||||
try {
|
||||
if (this.prerolled) {
|
||||
// Check again, just in case, async and all
|
||||
return;
|
||||
}
|
||||
const roller = new Preroller(this);
|
||||
if (!roller.shouldPreroll) {
|
||||
return;
|
||||
}
|
||||
const res = await roller.roll();
|
||||
if (!res) {
|
||||
return;
|
||||
}
|
||||
if (res.mime) {
|
||||
this.mime = res.mime;
|
||||
}
|
||||
if (res.name) {
|
||||
this.serverName = res.name;
|
||||
}
|
||||
if (res.error) {
|
||||
this.cancel();
|
||||
this.error = res.error;
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
console.error("Failed to preroll", this, ex.toString(), ex.stack, ex);
|
||||
}
|
||||
finally {
|
||||
if (this.state === RUNNING) {
|
||||
this.prerolled = true;
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resume(forced = false) {
|
||||
if (!(FORCABLE & this.state)) {
|
||||
return;
|
||||
@ -176,9 +226,10 @@ export class Download extends BaseDownload {
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.prerolled = false;
|
||||
this.manId = 0;
|
||||
this.written = this.totalSize = 0;
|
||||
this.serverName = "";
|
||||
this.mime = this.serverName = this.browserName = "";
|
||||
}
|
||||
|
||||
async removeFromBrowser() {
|
||||
@ -255,12 +306,18 @@ export class Download extends BaseDownload {
|
||||
const state = (await downloads.search({id: this.manId})).pop();
|
||||
const {filename, error} = state;
|
||||
const path = parsePath(filename);
|
||||
this.serverName = path.name;
|
||||
this.browserName = path.name;
|
||||
this.adoptSize(state);
|
||||
if (!this.mime && state.mime) {
|
||||
this.mime = state.mime;
|
||||
}
|
||||
this.markDirty();
|
||||
switch (state.state) {
|
||||
case "in_progress":
|
||||
if (error) {
|
||||
if (state.paused) {
|
||||
this.changeState(PAUSED);
|
||||
}
|
||||
else if (error) {
|
||||
this.cancel();
|
||||
this.error = error;
|
||||
}
|
||||
|
@ -12,22 +12,28 @@ import { Prefs } from "../prefs";
|
||||
import { _ } from "../i18n";
|
||||
import { CoalescedUpdate, mapFilterInSitu, filterInSitu } from "../util";
|
||||
import { PromiseSerializer } from "../pserializer";
|
||||
import {Download} from "./download";
|
||||
import {ManagerPort} from "./port";
|
||||
import {Scheduler} from "./scheduler";
|
||||
import {Limits} from "./limits";
|
||||
import { downloads } from "../browser";
|
||||
import { Download } from "./download";
|
||||
import { ManagerPort } from "./port";
|
||||
import { Scheduler } from "./scheduler";
|
||||
import { Limits } from "./limits";
|
||||
import { downloads, runtime, webRequest, CHROME } from "../browser";
|
||||
|
||||
const US = runtime.getURL("");
|
||||
|
||||
const AUTOSAVE_TIMEOUT = 2000;
|
||||
const DIRTY_TIMEOUT = 100;
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
const MISSING_TIMEOUT = 12 * 1000;
|
||||
const RELOAD_TIMEOUT = 10 * 1000;
|
||||
|
||||
const setShelfEnabled = downloads.setShelfEnabled || function() {
|
||||
// ignored
|
||||
};
|
||||
|
||||
export class Manager extends EventEmitter {
|
||||
private items: Download[];
|
||||
|
||||
private active: boolean;
|
||||
public active: boolean;
|
||||
|
||||
private notifiedFinished: boolean;
|
||||
|
||||
@ -45,9 +51,12 @@ export class Manager extends EventEmitter {
|
||||
|
||||
private scheduler: Scheduler | null;
|
||||
|
||||
private shouldReload: boolean;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.active = true;
|
||||
this.shouldReload = false;
|
||||
this.notifiedFinished = true;
|
||||
this.items = [];
|
||||
this.saveQueue = new CoalescedUpdate(
|
||||
@ -75,6 +84,14 @@ export class Manager extends EventEmitter {
|
||||
Limits.on("changed", () => {
|
||||
this.resetScheduler();
|
||||
});
|
||||
|
||||
if (CHROME) {
|
||||
webRequest.onBeforeSendHeaders.addListener(
|
||||
this.stuffReferrer.bind(this),
|
||||
{urls: ["<all_urls>"]},
|
||||
["blocking", "requestHeaders", "extraHeaders"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async init() {
|
||||
@ -88,9 +105,19 @@ export class Manager extends EventEmitter {
|
||||
}
|
||||
this.items.push(rv);
|
||||
});
|
||||
await this.resetScheduler();
|
||||
|
||||
// Do not wait for the scheduler
|
||||
this.resetScheduler();
|
||||
|
||||
this.emit("inited");
|
||||
setTimeout(() => this.checkMissing(), MISSING_TIMEOUT);
|
||||
runtime.onUpdateAvailable.addListener(() => {
|
||||
if (this.running.size) {
|
||||
this.shouldReload = true;
|
||||
return;
|
||||
}
|
||||
runtime.reload();
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -136,7 +163,7 @@ export class Manager extends EventEmitter {
|
||||
}
|
||||
const next = await this.scheduler.next(this.running);
|
||||
if (!next) {
|
||||
this.maybeNotifyFinished();
|
||||
this.maybeRunFinishActions();
|
||||
break;
|
||||
}
|
||||
if (this.running.has(next) || next.state !== QUEUED) {
|
||||
@ -156,10 +183,31 @@ export class Manager extends EventEmitter {
|
||||
async startDownload(download: Download) {
|
||||
// Add to running first, so we don't confuse the scheduler and other parts
|
||||
this.running.add(download);
|
||||
setShelfEnabled(false);
|
||||
await download.start();
|
||||
this.notifiedFinished = false;
|
||||
}
|
||||
|
||||
async maybeRunFinishActions() {
|
||||
if (this.running.size) {
|
||||
return;
|
||||
}
|
||||
await this.maybeNotifyFinished();
|
||||
if (this.running.size) {
|
||||
return;
|
||||
}
|
||||
if (this.shouldReload) {
|
||||
this.saveQueue.trigger();
|
||||
setTimeout(() => {
|
||||
if (this.running.size) {
|
||||
return;
|
||||
}
|
||||
runtime.reload();
|
||||
}, RELOAD_TIMEOUT);
|
||||
}
|
||||
setShelfEnabled(true);
|
||||
}
|
||||
|
||||
async maybeNotifyFinished() {
|
||||
if (!(await Prefs.get("finish-notification"))) {
|
||||
return;
|
||||
@ -216,7 +264,7 @@ export class Manager extends EventEmitter {
|
||||
this.emit("dirty", items);
|
||||
}
|
||||
|
||||
save(items: Download[]) {
|
||||
private save(items: Download[]) {
|
||||
DB.saveItems(items.filter(i => !i.removed)).
|
||||
catch(console.error);
|
||||
}
|
||||
@ -341,6 +389,35 @@ export class Manager extends EventEmitter {
|
||||
}
|
||||
this.emit("active", this.active);
|
||||
}
|
||||
|
||||
getMsgItems() {
|
||||
return this.items.map(e => e.toMsg());
|
||||
}
|
||||
|
||||
stuffReferrer(details: any): any {
|
||||
if (details.tabId > 0 && !US.startsWith(details.initiator)) {
|
||||
return undefined;
|
||||
}
|
||||
const sidx = details.requestHeaders.findIndex(
|
||||
(e: any) => e.name.toLowerCase() === "x-dta-id");
|
||||
if (sidx < 0) {
|
||||
return undefined;
|
||||
}
|
||||
const sid = parseInt(details.requestHeaders[sidx].value, 10);
|
||||
details.requestHeaders.splice(sidx, 1);
|
||||
const item = this.sids.get(sid);
|
||||
if (!item) {
|
||||
return undefined;
|
||||
}
|
||||
details.requestHeaders.push({
|
||||
name: "Referer",
|
||||
value: (item.uReferrer || item.uURL).toString()
|
||||
});
|
||||
const rv: any = {
|
||||
requestHeaders: details.requestHeaders
|
||||
};
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
let inited: Promise<Manager>;
|
||||
|
@ -5,6 +5,10 @@ import { donate, openPrefs } from "../windowutils";
|
||||
import { API } from "../api";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import { BaseDownload } from "./basedownload";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import { Manager } from "./man";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import { Port } from "../bus";
|
||||
|
||||
type SID = {sid: number};
|
||||
type SIDS = {
|
||||
@ -13,9 +17,9 @@ type SIDS = {
|
||||
};
|
||||
|
||||
export class ManagerPort {
|
||||
private manager: any;
|
||||
private manager: Manager;
|
||||
|
||||
private port: any;
|
||||
private port: Port;
|
||||
|
||||
constructor(manager: any, port: any) {
|
||||
this.manager = manager;
|
||||
@ -61,6 +65,7 @@ export class ManagerPort {
|
||||
delete this.manager;
|
||||
delete this.port;
|
||||
});
|
||||
|
||||
this.port.post("active", this.manager.active);
|
||||
this.sendAll();
|
||||
}
|
||||
@ -78,7 +83,6 @@ export class ManagerPort {
|
||||
}
|
||||
|
||||
sendAll() {
|
||||
this.port.post(
|
||||
"all", this.manager.items.map((e: BaseDownload) => e.toMsg()));
|
||||
this.port.post("all", this.manager.getMsgItems());
|
||||
}
|
||||
}
|
||||
|
234
lib/manager/preroller.ts
Normal file
234
lib/manager/preroller.ts
Normal file
@ -0,0 +1,234 @@
|
||||
"use strict";
|
||||
// License: MIT
|
||||
|
||||
import MimeType from "whatwg-mimetype";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import { Download } from "./download";
|
||||
import { CHROME, webRequest } from "../browser";
|
||||
import { CDHeaderParser } from "../cdheaderparser";
|
||||
import { sanitizePath, parsePath } from "../util";
|
||||
import { MimeDB } from "../mime";
|
||||
|
||||
const PREROLL_HEURISTICS = /dl|attach|download|name|file|get|retr|^n$|\.(php|asp|py|pl|action|htm|shtm)/i;
|
||||
const PREROLL_HOSTS = /4cdn|chan/;
|
||||
const PREROLL_TIMEOUT = 10000;
|
||||
const PREROLL_NOPE = new Set<string>();
|
||||
|
||||
/* eslint-disable no-magic-numbers */
|
||||
const NOPE_STATUSES = Object.freeze(new Set([
|
||||
400,
|
||||
401,
|
||||
402,
|
||||
405,
|
||||
416,
|
||||
]));
|
||||
/* eslint-enable no-magic-numbers */
|
||||
|
||||
const PREROLL_SEARCHEXTS = Object.freeze(new Set<string>([
|
||||
"php",
|
||||
"asp",
|
||||
"aspx",
|
||||
"inc",
|
||||
"py",
|
||||
"pl",
|
||||
"action",
|
||||
"htm",
|
||||
"html",
|
||||
"shtml"
|
||||
]));
|
||||
const NAME_TESTER = /\.[a-z0-9]{1,5}$/i;
|
||||
const CDPARSER = new CDHeaderParser();
|
||||
|
||||
export interface PrerollResults {
|
||||
error?: string;
|
||||
name?: string;
|
||||
mime?: string;
|
||||
finalURL?: string;
|
||||
}
|
||||
|
||||
export class Preroller {
|
||||
private readonly download: Download
|
||||
|
||||
constructor(download: Download) {
|
||||
this.download = download;
|
||||
}
|
||||
|
||||
get shouldPreroll() {
|
||||
const {uURL, renamer} = this.download;
|
||||
const {pathname, search, host} = uURL;
|
||||
if (PREROLL_NOPE.has(host)) {
|
||||
return false;
|
||||
}
|
||||
if (!renamer.p_ext) {
|
||||
return true;
|
||||
}
|
||||
if (search.length) {
|
||||
return true;
|
||||
}
|
||||
if (uURL.pathname.endsWith("/")) {
|
||||
return true;
|
||||
}
|
||||
if (PREROLL_HEURISTICS.test(pathname)) {
|
||||
return true;
|
||||
}
|
||||
if (PREROLL_HOSTS.test(host)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async roll() {
|
||||
try {
|
||||
return await (CHROME ? this.prerollChrome() : this.prerollFirefox());
|
||||
}
|
||||
catch (ex) {
|
||||
console.error("Failed to preroll", this, ex.toString(), ex.stack, ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async prerollFirefox() {
|
||||
const controller = new AbortController();
|
||||
const {signal} = controller;
|
||||
const {uURL, uReferrer} = this.download;
|
||||
const res = await fetch(uURL.toString(), {
|
||||
method: "GET",
|
||||
headers: new Headers({
|
||||
Range: "bytes=0-1",
|
||||
}),
|
||||
mode: "same-origin",
|
||||
signal,
|
||||
referrer: (uReferrer || uURL).toString(),
|
||||
});
|
||||
if (res.body) {
|
||||
res.body.cancel();
|
||||
}
|
||||
controller.abort();
|
||||
const {headers} = res;
|
||||
return this.finalize(headers, res);
|
||||
}
|
||||
|
||||
private async prerollChrome() {
|
||||
let rid = "";
|
||||
const {uURL, uReferrer} = this.download;
|
||||
const rurl = uURL.toString();
|
||||
let listener: any;
|
||||
const wr = new Promise<any[]>(resolve => {
|
||||
listener = (details: any) => {
|
||||
const {url, requestId, statusCode} = details;
|
||||
if (rid !== requestId && url !== rurl) {
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
if (statusCode >= 300 && statusCode < 400) {
|
||||
// Redirect, continue tracking;
|
||||
rid = requestId;
|
||||
return;
|
||||
}
|
||||
resolve(details.responseHeaders);
|
||||
};
|
||||
webRequest.onHeadersReceived.addListener(
|
||||
listener, {urls: ["<all_urls>"]}, ["responseHeaders"]);
|
||||
});
|
||||
const p = Promise.race([
|
||||
wr,
|
||||
new Promise<any[]>((_, reject) =>
|
||||
setTimeout(() => reject(new Error("timeout")), PREROLL_TIMEOUT))
|
||||
]);
|
||||
|
||||
p.finally(() => {
|
||||
webRequest.onHeadersReceived.removeListener(listener);
|
||||
});
|
||||
const controller = new AbortController();
|
||||
const {signal} = controller;
|
||||
const res = await fetch(rurl, {
|
||||
method: "GET",
|
||||
headers: new Headers({
|
||||
"Range": "bytes=0-1",
|
||||
"X-DTA-ID": this.download.sessionId.toString(),
|
||||
}),
|
||||
signal,
|
||||
referrer: (uReferrer || uURL).toString(),
|
||||
});
|
||||
if (res.body) {
|
||||
res.body.cancel();
|
||||
}
|
||||
controller.abort();
|
||||
const headers = await p;
|
||||
return this.finalize(
|
||||
new Headers(headers.map(i => [i.name, i.value])), res);
|
||||
}
|
||||
|
||||
private finalize(headers: Headers, res: Response): PrerollResults {
|
||||
const rv: PrerollResults = {};
|
||||
|
||||
const type = MimeType.parse(headers.get("content-type") || "");
|
||||
if (type) {
|
||||
rv.mime = type.essence;
|
||||
}
|
||||
|
||||
const {p_ext: ext} = this.download.renamer;
|
||||
const dispHeader = headers.get("content-disposition");
|
||||
if (dispHeader) {
|
||||
const file = CDPARSER.parse(dispHeader);
|
||||
// Sanitize
|
||||
rv.name = sanitizePath(file.replace(/[/\\]+/g, "-"));
|
||||
}
|
||||
else if (!ext || PREROLL_SEARCHEXTS.has(ext.toLocaleLowerCase())) {
|
||||
const {searchParams} = this.download.uURL;
|
||||
let detected = "";
|
||||
for (const [, value] of searchParams) {
|
||||
if (!NAME_TESTER.test(value)) {
|
||||
continue;
|
||||
}
|
||||
const p = parsePath(value);
|
||||
if (!p.base || !p.ext) {
|
||||
continue;
|
||||
}
|
||||
if (!MimeDB.hasExtension(p.ext)) {
|
||||
continue;
|
||||
}
|
||||
if (rv.mime) {
|
||||
const mime = MimeDB.getMime(rv.mime);
|
||||
if (mime && !mime.extensions.has(p.ext.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const sanitized = sanitizePath(p.name);
|
||||
if (sanitized.length <= detected.length) {
|
||||
continue;
|
||||
}
|
||||
detected = sanitized;
|
||||
}
|
||||
if (detected) {
|
||||
rv.name = detected;
|
||||
}
|
||||
}
|
||||
|
||||
rv.finalURL = res.url;
|
||||
|
||||
/* eslint-disable no-magic-numbers */
|
||||
const {status} = res;
|
||||
if (status === 404) {
|
||||
rv.error = "SERVER_BAD_CONTENT";
|
||||
}
|
||||
else if (status === 403) {
|
||||
rv.error = "SERVER_FORBIDDEN";
|
||||
}
|
||||
else if (status === 402 || status === 407) {
|
||||
rv.error = "SERVER_UNAUTHORIZED";
|
||||
}
|
||||
else if (NOPE_STATUSES.has(status)) {
|
||||
PREROLL_NOPE.add(this.download.uURL.host);
|
||||
if (PREROLL_NOPE.size > 1000) {
|
||||
PREROLL_NOPE.delete(PREROLL_NOPE.keys().next().value);
|
||||
}
|
||||
}
|
||||
else if (status > 400 && status < 500) {
|
||||
rv.error = "SERVER_FAILED";
|
||||
}
|
||||
/* eslint-enable no-magic-numbers */
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
@ -2,8 +2,12 @@
|
||||
"use strict";
|
||||
// License: MIT
|
||||
|
||||
import { parsePath, sanitizePath } from "../util";
|
||||
import { _ } from "../i18n";
|
||||
import { MimeDB } from "../mime";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import { parsePath, PathInfo, sanitizePath } from "../util";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import { BaseDownload } from "./basedownload";
|
||||
|
||||
const REPLACE_EXPR = /\*\w+\*/gi;
|
||||
|
||||
@ -22,21 +26,41 @@ const DATE_FORMATTER = new Intl.NumberFormat(undefined, {
|
||||
});
|
||||
|
||||
export default class Renamer {
|
||||
private readonly d: any;
|
||||
private readonly d: BaseDownload;
|
||||
|
||||
constructor(download: any) {
|
||||
private readonly nameinfo: PathInfo;
|
||||
|
||||
constructor(download: BaseDownload) {
|
||||
this.d = download;
|
||||
const info = parsePath(this.d.finalName);
|
||||
this.nameinfo = this.fixupExtension(info);
|
||||
}
|
||||
|
||||
get nameinfo() {
|
||||
return parsePath(this.d.finalName);
|
||||
private fixupExtension(info: PathInfo): PathInfo {
|
||||
if (!this.d.mime) {
|
||||
return info;
|
||||
}
|
||||
const mime = MimeDB.getMime(this.d.mime);
|
||||
if (!mime) {
|
||||
return info;
|
||||
}
|
||||
const {ext} = info;
|
||||
if (mime.major === "image" || mime.major === "video") {
|
||||
if (ext && mime.extensions.has(ext.toLowerCase())) {
|
||||
return info;
|
||||
}
|
||||
return new PathInfo(info.base, mime.primary, info.path);
|
||||
}
|
||||
if (ext) {
|
||||
return info;
|
||||
}
|
||||
return new PathInfo(info.base, mime.primary, info.path);
|
||||
}
|
||||
|
||||
get ref() {
|
||||
return this.d.uReferrer;
|
||||
}
|
||||
|
||||
|
||||
get p_name() {
|
||||
return this.nameinfo.base;
|
||||
}
|
||||
@ -184,7 +208,7 @@ export default class Renamer {
|
||||
(self[prop] || "").trim() :
|
||||
type;
|
||||
if (flat) {
|
||||
return rv.replace(/\/+/g, "-");
|
||||
return rv.replace(/[/\\]+/g, "-");
|
||||
}
|
||||
return rv;
|
||||
}));
|
||||
|
65
lib/mime.ts
Normal file
65
lib/mime.ts
Normal file
@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
// License: MIT
|
||||
|
||||
import mime from "../data/mime.json";
|
||||
|
||||
export class MimeInfo {
|
||||
public readonly type: string;
|
||||
|
||||
public readonly extensions: Set<string>;
|
||||
|
||||
public readonly major: string;
|
||||
|
||||
public readonly minor: string;
|
||||
|
||||
public readonly primary: string;
|
||||
|
||||
constructor(type: string, extensions: string[]) {
|
||||
this.type = type;
|
||||
const [major, minor] = type.split("/", 2);
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
[this.primary] = extensions;
|
||||
this.extensions = new Set(extensions);
|
||||
Object.freeze(this);
|
||||
}
|
||||
}
|
||||
|
||||
export const MimeDB = new class MimeDB {
|
||||
private readonly mimeToExts: Map<string, MimeInfo>;
|
||||
|
||||
private readonly registeredExtensions: Set<string>;
|
||||
|
||||
constructor() {
|
||||
const exts = new Map<string, string[]>();
|
||||
for (const [prim, more] of Object.entries(mime.e)) {
|
||||
let toadd = more;
|
||||
if (!Array.isArray(toadd)) {
|
||||
toadd = [toadd];
|
||||
}
|
||||
toadd.unshift(prim);
|
||||
exts.set(prim, toadd);
|
||||
}
|
||||
this.mimeToExts = new Map(Array.from(
|
||||
Object.entries(mime.m),
|
||||
([mime, prim]) => [mime, new MimeInfo(mime, exts.get(prim) || [prim])]
|
||||
));
|
||||
const all = Array.from(
|
||||
this.mimeToExts.values(),
|
||||
m => Array.from(m.extensions, e => e.toLowerCase()));
|
||||
this.registeredExtensions = new Set(all.flat());
|
||||
}
|
||||
|
||||
getPrimary(mime: string) {
|
||||
const info = this.mimeToExts.get(mime.trim().toLocaleLowerCase());
|
||||
return info ? info.primary : "";
|
||||
}
|
||||
|
||||
getMime(mime: string) {
|
||||
return this.mimeToExts.get(mime.trim().toLocaleLowerCase());
|
||||
}
|
||||
|
||||
hasExtension(ext: string) {
|
||||
return this.registeredExtensions.has(ext.toLowerCase());
|
||||
}
|
||||
}();
|
@ -12,13 +12,20 @@ const DEFAULTS = {
|
||||
message: "message",
|
||||
};
|
||||
|
||||
const TIMEOUT = 4000;
|
||||
|
||||
let gid = 1;
|
||||
|
||||
export class Notification extends EventEmitter {
|
||||
private notification: any;
|
||||
|
||||
private readonly generated: boolean;
|
||||
|
||||
constructor(id: string | null, options = {}) {
|
||||
super();
|
||||
|
||||
id = id || "DownThemAll-notification";
|
||||
this.generated = !id;
|
||||
id = id || `DownThemAll-notification${++gid}`;
|
||||
if (typeof options === "string") {
|
||||
options = {message: options};
|
||||
}
|
||||
@ -39,11 +46,16 @@ export class Notification extends EventEmitter {
|
||||
opened(notification: any) {
|
||||
this.notification = notification;
|
||||
this.emit("opened", this);
|
||||
if (this.generated) {
|
||||
setTimeout(() => {
|
||||
notifications.clear(notification);
|
||||
}, TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
clicked(notification: any, button?: number) {
|
||||
// We can only be clicked, when we were opened, at which point the
|
||||
// notification id is availablfalse
|
||||
// notification id is available
|
||||
if (notification !== this.notification) {
|
||||
return;
|
||||
}
|
||||
@ -52,6 +64,7 @@ export class Notification extends EventEmitter {
|
||||
return;
|
||||
}
|
||||
this.emit("clicked", this);
|
||||
console.log("clicked", notification);
|
||||
}
|
||||
|
||||
async closed(notification: any) {
|
||||
|
@ -1,9 +1,9 @@
|
||||
"use strict";
|
||||
// License: MIT
|
||||
|
||||
import * as DEFAULT_PREFS from "../data/prefs.json";
|
||||
import DEFAULT_PREFS from "../data/prefs.json";
|
||||
import { EventEmitter } from "./events";
|
||||
import {loadOverlay} from "./objectoverlay";
|
||||
import { loadOverlay } from "./objectoverlay";
|
||||
import { storage } from "./browser";
|
||||
|
||||
const PREFS = Symbol("PREFS");
|
||||
|
@ -98,6 +98,7 @@ export async function select(links: BaseItem[], media: BaseItem[]) {
|
||||
type: "popup",
|
||||
});
|
||||
const window = await windows.create(windowOptions);
|
||||
tracker.track(window.id, null);
|
||||
try {
|
||||
const port = await Promise.race<Port>([
|
||||
new Promise<Port>(resolve => Bus.oncePort("select", resolve)),
|
||||
@ -186,8 +187,8 @@ export async function select(links: BaseItem[], media: BaseItem[]) {
|
||||
openPrefs();
|
||||
});
|
||||
|
||||
port.on("openUrls", ({urls}) => {
|
||||
openUrls(urls);
|
||||
port.on("openUrls", ({urls, incognito}) => {
|
||||
openUrls(urls, incognito);
|
||||
});
|
||||
|
||||
try {
|
||||
|
@ -21,6 +21,7 @@ export async function single(item: BaseItem | null) {
|
||||
type: "popup",
|
||||
});
|
||||
const window = await windows.create(windowOptions);
|
||||
tracker.track(window.id, null);
|
||||
try {
|
||||
const port: Port = await Promise.race<Port>([
|
||||
new Promise<Port>(resolve => Bus.oncePort("single", resolve)),
|
||||
|
78
lib/util.ts
78
lib/util.ts
@ -2,8 +2,8 @@
|
||||
// License: MIT
|
||||
|
||||
import * as psl from "psl";
|
||||
import {memoize, identity} from "./memoize";
|
||||
export {debounce} from "../uikit/lib/util";
|
||||
import { identity, memoize } from "./memoize";
|
||||
export { debounce } from "../uikit/lib/util";
|
||||
|
||||
export class Promised {
|
||||
private promise: Promise<any>;
|
||||
@ -96,8 +96,72 @@ export const IS_WIN = typeof navigator !== "undefined" &&
|
||||
export const sanitizePath = identity(
|
||||
IS_WIN ? sanitizePathWindows : sanitizePathGeneric);
|
||||
|
||||
export class PathInfo {
|
||||
private baseField: string;
|
||||
|
||||
private extField: string;
|
||||
|
||||
private pathField: string;
|
||||
|
||||
private nameField: string;
|
||||
|
||||
private fullField: string;
|
||||
|
||||
constructor(base: string, ext: string, path: string) {
|
||||
this.baseField = base;
|
||||
this.extField = ext;
|
||||
this.pathField = path;
|
||||
this.update();
|
||||
}
|
||||
|
||||
get base() {
|
||||
return this.baseField;
|
||||
}
|
||||
|
||||
set base(nv) {
|
||||
this.baseField = sanitizePath(nv);
|
||||
this.update();
|
||||
}
|
||||
|
||||
get ext() {
|
||||
return this.extField;
|
||||
}
|
||||
|
||||
set ext(nv) {
|
||||
this.extField = sanitizePath(nv);
|
||||
this.update();
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.nameField;
|
||||
}
|
||||
|
||||
get path() {
|
||||
return this.pathField;
|
||||
}
|
||||
|
||||
set path(nv) {
|
||||
this.pathField = sanitizePath(nv);
|
||||
this.update();
|
||||
}
|
||||
|
||||
get full() {
|
||||
return this.fullField;
|
||||
}
|
||||
|
||||
private update() {
|
||||
this.nameField = this.extField ? `${this.baseField}.${this.extField}` : this.baseField;
|
||||
this.fullField = this.pathField ? `${this.pathField}/${this.nameField}` : this.nameField;
|
||||
}
|
||||
|
||||
clone() {
|
||||
return new PathInfo(this.baseField, this.extField, this.pathField);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX cleanup + test
|
||||
export const parsePath = memoize(function parsePath(path: string | URL) {
|
||||
export const parsePath = memoize(function parsePath(
|
||||
path: string | URL): PathInfo {
|
||||
if (path instanceof URL) {
|
||||
path = decodeURIComponent(path.pathname);
|
||||
}
|
||||
@ -127,13 +191,7 @@ export const parsePath = memoize(function parsePath(path: string | URL) {
|
||||
}
|
||||
|
||||
path = pieces.join("/");
|
||||
return {
|
||||
path,
|
||||
name,
|
||||
base,
|
||||
ext,
|
||||
full: path ? `${path}/${name}` : name
|
||||
};
|
||||
return new PathInfo(base, ext, path);
|
||||
});
|
||||
|
||||
export class CoalescedUpdate<T> extends Set<T> {
|
||||
|
@ -55,13 +55,15 @@ export class WindowStateTracker {
|
||||
|
||||
getOptions(options: any) {
|
||||
const result = Object.assign(options, {
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
state: this.state,
|
||||
});
|
||||
if (this.top >= 0) {
|
||||
result.top = this.top;
|
||||
result.left = this.left;
|
||||
if (result.state !== "maximized") {
|
||||
result.width = this.width;
|
||||
result.height = this.height;
|
||||
if (this.top >= 0) {
|
||||
result.top = this.top;
|
||||
result.left = this.left;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -3,28 +3,50 @@
|
||||
|
||||
import { windows, tabs, runtime } from "../lib/browser";
|
||||
import {getManager} from "./manager/man";
|
||||
import * as DEFAULT_ICONS from "../data/icons.json";
|
||||
import DEFAULT_ICONS from "../data/icons.json";
|
||||
|
||||
const DONATE_URL = "https://www.downthemall.org/howto/donate/";
|
||||
const MANAGER_URL = "/windows/manager.html";
|
||||
|
||||
const IS_CHROME = navigator && navigator.userAgent.includes("Chrome");
|
||||
|
||||
|
||||
export async function mostRecentBrowser(): Promise<any> {
|
||||
let window = Array.from(await windows.getAll({windowTypes: ["normal"]})).
|
||||
filter((w: any) => w.type === "normal").pop();
|
||||
export async function mostRecentBrowser(incognito: boolean): Promise<any> {
|
||||
let window;
|
||||
try {
|
||||
window = await windows.getCurrent();
|
||||
if (window.type !== "normal") {
|
||||
throw new Error("not a normal window");
|
||||
}
|
||||
if (incognito && !window.incognito) {
|
||||
throw new Error("Not incognito");
|
||||
}
|
||||
}
|
||||
catch {
|
||||
try {
|
||||
window = await windows.getlastFocused();
|
||||
if (window.type !== "normal") {
|
||||
throw new Error("not a normal window");
|
||||
}
|
||||
if (incognito && !window.incognito) {
|
||||
throw new Error("Not incognito");
|
||||
}
|
||||
}
|
||||
catch {
|
||||
window = Array.from(await windows.getAll({windowTypes: ["normal"]})).
|
||||
filter(
|
||||
(w: any) => w.type === "normal" && !!w.incognito === !!incognito).
|
||||
pop();
|
||||
}
|
||||
}
|
||||
if (!window) {
|
||||
window = await windows.create({
|
||||
url: DONATE_URL,
|
||||
incognito: !!incognito,
|
||||
type: "normal",
|
||||
});
|
||||
}
|
||||
return window;
|
||||
}
|
||||
|
||||
export async function openInTab(url: string) {
|
||||
const window = await mostRecentBrowser();
|
||||
export async function openInTab(url: string, incognito: boolean) {
|
||||
const window = await mostRecentBrowser(incognito);
|
||||
await tabs.create({
|
||||
active: true,
|
||||
url,
|
||||
@ -33,7 +55,7 @@ export async function openInTab(url: string) {
|
||||
await windows.update(window.id, {focused: true});
|
||||
}
|
||||
|
||||
export async function openInTabOrFocus(url: string) {
|
||||
export async function openInTabOrFocus(url: string, incognito: boolean) {
|
||||
const etabs = await tabs.query({
|
||||
url
|
||||
});
|
||||
@ -43,21 +65,21 @@ export async function openInTabOrFocus(url: string) {
|
||||
await windows.update(tab.windowId, {focused: true});
|
||||
return;
|
||||
}
|
||||
await openInTab(url);
|
||||
await openInTab(url, incognito);
|
||||
}
|
||||
|
||||
export async function maybeOpenInTab(url: string) {
|
||||
export async function maybeOpenInTab(url: string, incognito: boolean) {
|
||||
const etabs = await tabs.query({
|
||||
url
|
||||
});
|
||||
if (etabs.length) {
|
||||
return;
|
||||
}
|
||||
await openInTab(url);
|
||||
await openInTab(url, incognito);
|
||||
}
|
||||
|
||||
export async function donate() {
|
||||
await openInTab(DONATE_URL);
|
||||
await openInTab(DONATE_URL, false);
|
||||
}
|
||||
|
||||
export async function openPrefs() {
|
||||
@ -72,15 +94,15 @@ export async function openManager(focus = true) {
|
||||
console.error(ex.toString(), ex);
|
||||
}
|
||||
if (focus) {
|
||||
await openInTabOrFocus(await runtime.getURL(MANAGER_URL));
|
||||
await openInTabOrFocus(await runtime.getURL(MANAGER_URL), false);
|
||||
}
|
||||
else {
|
||||
await maybeOpenInTab(await runtime.getURL(MANAGER_URL));
|
||||
await maybeOpenInTab(await runtime.getURL(MANAGER_URL), false);
|
||||
}
|
||||
}
|
||||
|
||||
export async function openUrls(urls: string) {
|
||||
const window = await mostRecentBrowser();
|
||||
export async function openUrls(urls: string, incognito: boolean) {
|
||||
const window = await mostRecentBrowser(incognito);
|
||||
for (const url of urls) {
|
||||
try {
|
||||
await tabs.create({
|
||||
@ -106,32 +128,10 @@ const ICONS = Object.freeze((() => {
|
||||
return new Map<string, string>(rv);
|
||||
})());
|
||||
|
||||
let iconForPathPlatform: Function;
|
||||
if (IS_CHROME) {
|
||||
const FOUR = 128;
|
||||
const DOUBLE = 64;
|
||||
iconForPathPlatform = function(icon: string, size: number) {
|
||||
let scale = "1x";
|
||||
if (size > FOUR) {
|
||||
// wishful thinking at this point
|
||||
scale = "4x";
|
||||
}
|
||||
else if (size > DOUBLE) {
|
||||
scale = "2x";
|
||||
}
|
||||
return `chrome://fileicon/${icon}?scale=${scale}`;
|
||||
};
|
||||
}
|
||||
else {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
iconForPathPlatform = function(icon: string, size: number) {
|
||||
return ICONS.get(icon) || "icon-file-generic";
|
||||
};
|
||||
}
|
||||
export const DEFAULT_ICON_SIZE = 16;
|
||||
|
||||
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
export function iconForPath(path: string, size = 16) {
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
export function iconForPath(path: string, size = DEFAULT_ICON_SIZE) {
|
||||
const web = /^https?:\/\//.test(path);
|
||||
let file = path.split(/[\\/]/).pop();
|
||||
if (file) {
|
||||
@ -152,7 +152,7 @@ export function iconForPath(path: string, size = 16) {
|
||||
file = "file";
|
||||
}
|
||||
}
|
||||
return iconForPathPlatform(file, size);
|
||||
return ICONS.get(file) || "icon-file-generic";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "DownThemAll!",
|
||||
"version": "4.0.5",
|
||||
"version": "4.0.12",
|
||||
|
||||
"description": "__MSG_extensionDescription__",
|
||||
"homepage_url": "https://downthemall.org/",
|
||||
@ -9,6 +9,8 @@
|
||||
|
||||
"default_locale": "en",
|
||||
|
||||
"content_security_policy": "script-src 'self'; style-src 'self' 'unsafe-inline'; img-src data: blob: 'self'; connect-src data: blob: http: https: 'self'; default-src 'self'",
|
||||
|
||||
"icons": {
|
||||
"16": "style/icon16.png",
|
||||
"32": "style/icon32.png",
|
||||
@ -22,14 +24,18 @@
|
||||
"permissions": [
|
||||
"<all_urls>",
|
||||
"contextMenus",
|
||||
"menus",
|
||||
"downloads",
|
||||
"downloads.open",
|
||||
"downloads.shelf",
|
||||
"history",
|
||||
"menus",
|
||||
"notifications",
|
||||
"sessions",
|
||||
"storage",
|
||||
"tabs",
|
||||
"webNavigation"
|
||||
"webNavigation",
|
||||
"webRequest",
|
||||
"webRequestBlocking"
|
||||
],
|
||||
|
||||
"background": {
|
||||
|
@ -33,7 +33,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/psl": "^1.1.0",
|
||||
"@types/whatwg-mimetype": "^2.1.0",
|
||||
"psl": "^1.3.0",
|
||||
"webextension-polyfill": "^0.4.0"
|
||||
"webextension-polyfill": "^0.4.0",
|
||||
"whatwg-mimetype": "^2.3.0"
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,8 @@ function urlToUsable(e: any, u: string) {
|
||||
}
|
||||
|
||||
class Gatherer {
|
||||
private: boolean;
|
||||
|
||||
textLinks: boolean;
|
||||
|
||||
selectionOnly: boolean;
|
||||
@ -88,6 +90,7 @@ class Gatherer {
|
||||
transferable: string[];
|
||||
|
||||
constructor(options: any) {
|
||||
this.private = !!options.private;
|
||||
this.textLinks = options.textLinks;
|
||||
this.selectionOnly = options.selectionOnly;
|
||||
this.selection = options.selectionOnly ? getSelection() : null;
|
||||
@ -255,6 +258,7 @@ class Gatherer {
|
||||
return {
|
||||
url: url.href,
|
||||
title,
|
||||
private: this.private
|
||||
};
|
||||
}
|
||||
catch (ex) {
|
||||
@ -295,7 +299,7 @@ class Gatherer {
|
||||
function gather(msg: any, sender: any, callback: Function) {
|
||||
try {
|
||||
if (!msg || msg.type !== "DTA:gather" || !callback) {
|
||||
return;
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
const gatherer = new Gatherer(msg);
|
||||
const result = {
|
||||
@ -313,10 +317,11 @@ function gather(msg: any, sender: any, callback: Function) {
|
||||
),
|
||||
};
|
||||
urlToUsable(result, result.baseURL);
|
||||
callback(result);
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
catch (ex) {
|
||||
console.error(ex.toString(), ex.stack, ex);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,12 +18,17 @@
|
||||
--folder-color: rgb(214, 165, 4);
|
||||
--maskbutton-color: rgb(236, 185, 16);
|
||||
--missing-color: rgb(0, 82, 204);
|
||||
--open-color: rgba(236, 185, 16, 0.8);
|
||||
}
|
||||
|
||||
html[data-platform="mac"] {
|
||||
--folder-color: rgb(4, 102, 214);
|
||||
}
|
||||
|
||||
html, body {
|
||||
font-size: 10pt !important;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'downthemall';
|
||||
src: url('downthemall.woff2?75791791') format('woff2');
|
||||
|
@ -108,11 +108,11 @@ body > * {
|
||||
}
|
||||
|
||||
#colURL {
|
||||
width: 38%;
|
||||
width: 42%;
|
||||
}
|
||||
|
||||
#colPercent {
|
||||
width: 3em;
|
||||
width: 4em;
|
||||
min-width: 3em;
|
||||
}
|
||||
|
||||
@ -121,11 +121,11 @@ body > * {
|
||||
}
|
||||
|
||||
#colSize {
|
||||
width: 15em;
|
||||
width: 14em;
|
||||
}
|
||||
|
||||
#colSpeed {
|
||||
width: 6em;
|
||||
width: 7em;
|
||||
}
|
||||
|
||||
#colDomain,
|
||||
@ -154,6 +154,14 @@ body > * {
|
||||
height: 26px;
|
||||
}
|
||||
|
||||
.virtualtable-row.opening {
|
||||
background: var(--open-color) !important;
|
||||
}
|
||||
|
||||
.virtualtable-progress-container {
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.virtualtable-progress-bar {
|
||||
height: 14px;
|
||||
}
|
||||
@ -262,6 +270,7 @@ body > * {
|
||||
}
|
||||
|
||||
.virtualtable-column-6,
|
||||
.virtualtable-column-4,
|
||||
.virtualtable-column-3 {
|
||||
text-align: right;
|
||||
}
|
||||
@ -430,6 +439,8 @@ body > * {
|
||||
justify-items: stretch;
|
||||
border-radius: 4px;
|
||||
box-shadow: 2px 2px 6px black;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
#tooltip-infos {
|
||||
@ -442,8 +453,13 @@ body > * {
|
||||
}
|
||||
|
||||
#tooltip-icon {
|
||||
font-size: 48px;
|
||||
line-height: 48px;
|
||||
height: 64px;
|
||||
width: 64px;
|
||||
background-size: 64px 64px;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center center;
|
||||
font-size: 64px;
|
||||
line-height: 64px;
|
||||
padding: 6px;
|
||||
text-align: center;
|
||||
grid-row: 1/-1;
|
||||
|
@ -232,3 +232,7 @@ body > * {
|
||||
#maskButton {
|
||||
justify-self: flex-start;
|
||||
}
|
||||
|
||||
#btnDownload {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ p.example {
|
||||
}
|
||||
|
||||
#options > * {
|
||||
margin: 0;
|
||||
margin: 2px;
|
||||
}
|
||||
|
||||
#options > input {
|
||||
@ -81,3 +81,7 @@ h3 {
|
||||
font-weight: normal;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
#btnDownload {
|
||||
font-weight: bold;
|
||||
}
|
289
tests/test_cdheaderparser.js
Normal file
289
tests/test_cdheaderparser.js
Normal file
@ -0,0 +1,289 @@
|
||||
/* eslint-disable max-len */
|
||||
/* eslint-env node */
|
||||
"use strict";
|
||||
// License: MPL-2
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const { CDHeaderParser } = require("../lib/cdheaderparser");
|
||||
|
||||
const parser = new CDHeaderParser();
|
||||
|
||||
function check(header, expected) {
|
||||
expect(parser.parse(header)).to.equal(expected);
|
||||
}
|
||||
|
||||
function nocheck(header, expected) {
|
||||
expect(parser.parse(header)).not.to.equal(expected);
|
||||
}
|
||||
|
||||
describe("CDHeaderParser", function() {
|
||||
it("parse wget", function() {
|
||||
// From wget, test_parse_content_disposition
|
||||
// http://git.savannah.gnu.org/cgit/wget.git/tree/src/http.c?id=8551ceccfedb4390fbfa82c12f0ff714dab1ac76#n5325
|
||||
check("filename=\"file.ext\"", "file.ext");
|
||||
check("attachment; filename=\"file.ext\"", "file.ext");
|
||||
check("attachment; filename=\"file.ext\"; dummy", "file.ext");
|
||||
check("attachment", ""); // wget uses NULL, we use "".
|
||||
check("attachement; filename*=UTF-8'en-US'hello.txt", "hello.txt");
|
||||
check("attachement; filename*0=\"hello\"; filename*1=\"world.txt\"",
|
||||
"helloworld.txt");
|
||||
check("attachment; filename=\"A.ext\"; filename*=\"B.ext\"", "B.ext");
|
||||
check("attachment; filename*=\"A.ext\"; filename*0=\"B\"; filename*1=\"B.ext\"",
|
||||
"A.ext");
|
||||
// This test is faulty - https://savannah.gnu.org/bugs/index.php?52531
|
||||
//check("filename**0=\"A\"; filename**1=\"A.ext\"; filename*0=\"B\";filename*1=\"B\"", "AA.ext");
|
||||
});
|
||||
|
||||
it("parse Firefox", function() {
|
||||
// From Firefox
|
||||
// https://searchfox.org/mozilla-central/rev/45a3df4e6b8f653b0103d18d97c34dd666706358/netwerk/test/unit/test_MIME_params.js
|
||||
// Changed as follows:
|
||||
// - Replace error codes with empty string (we never throw).
|
||||
|
||||
const BS = "\\";
|
||||
const DQUOTE = "\"";
|
||||
// No filename parameter: return nothing
|
||||
check("attachment;", "");
|
||||
// basic
|
||||
check("attachment; filename=basic", "basic");
|
||||
// extended
|
||||
check("attachment; filename*=UTF-8''extended", "extended");
|
||||
// prefer extended to basic (bug 588781)
|
||||
check("attachment; filename=basic; filename*=UTF-8''extended", "extended");
|
||||
// prefer extended to basic (bug 588781)
|
||||
check("attachment; filename*=UTF-8''extended; filename=basic", "extended");
|
||||
// use first basic value (invalid; error recovery)
|
||||
check("attachment; filename=first; filename=wrong", "first");
|
||||
// old school bad HTTP servers: missing 'attachment' or 'inline'
|
||||
// (invalid; error recovery)
|
||||
check("filename=old", "old");
|
||||
check("attachment; filename*=UTF-8''extended", "extended");
|
||||
// continuations not part of RFC 5987 (bug 610054)
|
||||
check("attachment; filename*0=foo; filename*1=bar", "foobar");
|
||||
// Return first continuation (invalid; error recovery)
|
||||
check("attachment; filename*0=first; filename*0=wrong; filename=basic", "first");
|
||||
// Only use correctly ordered continuations (invalid; error recovery)
|
||||
check("attachment; filename*0=first; filename*1=second; filename*0=wrong", "firstsecond");
|
||||
// prefer continuation to basic (unless RFC 5987)
|
||||
check("attachment; filename=basic; filename*0=foo; filename*1=bar", "foobar");
|
||||
// Prefer extended to basic and/or (broken or not) continuation
|
||||
// (invalid; error recovery)
|
||||
check("attachment; filename=basic; filename*0=first; filename*0=wrong; filename*=UTF-8''extended", "extended");
|
||||
// RFC 2231 not clear on correct outcome: we prefer non-continued extended
|
||||
// (invalid; error recovery)
|
||||
check("attachment; filename=basic; filename*=UTF-8''extended; filename*0=foo; filename*1=bar", "extended");
|
||||
// Gaps should result in returning only value until gap hit
|
||||
// (invalid; error recovery)
|
||||
check("attachment; filename*0=foo; filename*2=bar", "foo");
|
||||
// Don't allow leading 0's (*01) (invalid; error recovery)
|
||||
check("attachment; filename*0=foo; filename*01=bar", "foo");
|
||||
// continuations should prevail over non-extended (unless RFC 5987)
|
||||
check("attachment; filename=basic; filename*0*=UTF-8''multi;\r\n" +
|
||||
" filename*1=line;\r\n" +
|
||||
" filename*2*=%20extended",
|
||||
"multiline extended");
|
||||
// Gaps should result in returning only value until gap hit
|
||||
// (invalid; error recovery)
|
||||
check("attachment; filename=basic; filename*0*=UTF-8''multi;\r\n" +
|
||||
" filename*1=line;\r\n" +
|
||||
" filename*3*=%20extended",
|
||||
"multiline");
|
||||
// First series, only please, and don't slurp up higher elements (*2 in this
|
||||
// case) from later series into earlier one (invalid; error recovery)
|
||||
check("attachment; filename=basic; filename*0*=UTF-8''multi;\r\n" +
|
||||
" filename*1=line;\r\n" +
|
||||
" filename*0*=UTF-8''wrong;\r\n" +
|
||||
" filename*1=bad;\r\n" +
|
||||
" filename*2=evil",
|
||||
"multiline");
|
||||
// RFC 2231 not clear on correct outcome: we prefer non-continued extended
|
||||
// (invalid; error recovery)
|
||||
check("attachment; filename=basic; filename*0=UTF-8''multi\r\n;" +
|
||||
" filename*=UTF-8''extended;\r\n" +
|
||||
" filename*1=line;\r\n" +
|
||||
" filename*2*=%20extended",
|
||||
"extended");
|
||||
// sneaky: if unescaped, make sure we leave UTF-8'' in value
|
||||
check("attachment; filename*0=UTF-8''unescaped;\r\n" +
|
||||
" filename*1*=%20so%20includes%20UTF-8''%20in%20value",
|
||||
"UTF-8''unescaped so includes UTF-8'' in value");
|
||||
// sneaky: if unescaped, make sure we leave UTF-8'' in value
|
||||
check("attachment; filename=basic; filename*0=UTF-8''unescaped;\r\n" +
|
||||
" filename*1*=%20so%20includes%20UTF-8''%20in%20value",
|
||||
"UTF-8''unescaped so includes UTF-8'' in value");
|
||||
// Prefer basic over invalid continuation
|
||||
// (invalid; error recovery)
|
||||
check("attachment; filename=basic; filename*1=multi;\r\n" +
|
||||
" filename*2=line;\r\n" +
|
||||
" filename*3*=%20extended",
|
||||
"basic");
|
||||
// support digits over 10
|
||||
check("attachment; filename=basic; filename*0*=UTF-8''0;\r\n" +
|
||||
" filename*1=1; filename*2=2;filename*3=3;filename*4=4;filename*5=5;\r\n" +
|
||||
" filename*6=6; filename*7=7;filename*8=8;filename*9=9;filename*10=a;\r\n" +
|
||||
" filename*11=b; filename*12=c;filename*13=d;filename*14=e;filename*15=f\r\n",
|
||||
"0123456789abcdef");
|
||||
// support digits over 10 (detect gaps)
|
||||
check("attachment; filename=basic; filename*0*=UTF-8''0;\r\n" +
|
||||
" filename*1=1; filename*2=2;filename*3=3;filename*4=4;filename*5=5;\r\n" +
|
||||
" filename*6=6; filename*7=7;filename*8=8;filename*9=9;filename*10=a;\r\n" +
|
||||
" filename*11=b; filename*12=c;filename*14=e\r\n",
|
||||
"0123456789abc");
|
||||
// return nothing: invalid
|
||||
// (invalid; error recovery)
|
||||
check("attachment; filename*1=multi;\r\n" +
|
||||
" filename*2=line;\r\n" +
|
||||
" filename*3*=%20extended",
|
||||
"");
|
||||
// Bug 272541: Empty disposition type treated as "attachment"
|
||||
// sanity check
|
||||
check("attachment; filename=foo.html", "foo.html");
|
||||
// the actual bug
|
||||
check("; filename=foo.html", "foo.html");
|
||||
// regression check, but see bug 671204
|
||||
check("filename=foo.html", "foo.html");
|
||||
// Bug 384571: RFC 2231 parameters not decoded when appearing in reversed order
|
||||
// check ordering
|
||||
check("attachment; filename=basic; filename*0*=UTF-8''0;\r\n" +
|
||||
" filename*1=1; filename*2=2;filename*3=3;filename*4=4;filename*5=5;\r\n" +
|
||||
" filename*6=6; filename*7=7;filename*8=8;filename*9=9;filename*10=a;\r\n" +
|
||||
" filename*11=b; filename*12=c;filename*13=d;filename*15=f;filename*14=e;\r\n",
|
||||
"0123456789abcdef");
|
||||
// check non-digits in sequence numbers
|
||||
check("attachment; filename=basic; filename*0*=UTF-8''0;\r\n" +
|
||||
" filename*1a=1\r\n",
|
||||
"0");
|
||||
// check duplicate sequence numbers
|
||||
check("attachment; filename=basic; filename*0*=UTF-8''0;\r\n" +
|
||||
" filename*0=bad; filename*1=1;\r\n",
|
||||
"0");
|
||||
// check overflow
|
||||
check("attachment; filename=basic; filename*0*=UTF-8''0;\r\n" +
|
||||
" filename*11111111111111111111111111111111111111111111111111111111111=1",
|
||||
"0");
|
||||
// check underflow
|
||||
check("attachment; filename=basic; filename*0*=UTF-8''0;\r\n" +
|
||||
" filename*-1=1",
|
||||
"0");
|
||||
// check mixed token/quoted-string
|
||||
check("attachment; filename=basic; filename*0=\"0\";\r\n" +
|
||||
" filename*1=1;\r\n" +
|
||||
" filename*2*=%32",
|
||||
"012");
|
||||
// check empty sequence number
|
||||
check("attachment; filename=basic; filename**=UTF-8''0\r\n", "basic");
|
||||
// Bug 419157: ensure that a MIME parameter with no charset information
|
||||
// fallbacks to Latin-1
|
||||
check("attachment;filename=IT839\x04\xB5(m8)2.pdf;", "IT839\u0004\u00b5(m8)2.pdf");
|
||||
// Bug 588389: unescaping backslashes in quoted string parameters
|
||||
// '\"', should be parsed as '"'
|
||||
check(`attachment; filename=${DQUOTE}${BS + DQUOTE}${DQUOTE}`, DQUOTE);
|
||||
// 'a\"b', should be parsed as 'a"b'
|
||||
check(`attachment; filename=${DQUOTE}a${BS + DQUOTE}b${DQUOTE}`, `a${DQUOTE}b`);
|
||||
// '\x', should be parsed as 'x'
|
||||
check(`attachment; filename=${DQUOTE}${BS}x${DQUOTE}`, "x");
|
||||
// test empty param (quoted-string)
|
||||
check(`attachment; filename=${DQUOTE}${DQUOTE}`, "");
|
||||
// test empty param
|
||||
check("attachment; filename=", "");
|
||||
// Bug 601933: RFC 2047 does not apply to parameters (at least in HTTP)
|
||||
check("attachment; filename==?ISO-8859-1?Q?foo-=E4.html?=", "foo-\u00e4.html");
|
||||
check("attachment; filename=\"=?ISO-8859-1?Q?foo-=E4.html?=\"", "foo-\u00e4.html");
|
||||
// format sent by GMail as of 2012-07-23 (5987 overrides 2047)
|
||||
check("attachment; filename=\"=?ISO-8859-1?Q?foo-=E4.html?=\"; filename*=UTF-8''5987", "5987");
|
||||
// Bug 651185: double quotes around 2231/5987 encoded param
|
||||
// Change reverted to backwards compat issues with various web services,
|
||||
// such as OWA (Bug 703015), plus similar problems in Thunderbird. If this
|
||||
// is tried again in the future, email probably needs to be special-cased.
|
||||
// sanity check
|
||||
check("attachment; filename*=utf-8''%41", "A");
|
||||
// the actual bug
|
||||
check(`attachment; filename*=${DQUOTE}utf-8''%41${DQUOTE}`, "A");
|
||||
// Bug 670333: Content-Disposition parser does not require presence of "="
|
||||
// in params
|
||||
// sanity check
|
||||
check("attachment; filename*=UTF-8''foo-%41.html", "foo-A.html");
|
||||
// the actual bug
|
||||
check("attachment; filename *=UTF-8''foo-%41.html", "");
|
||||
// the actual bug, without 2231/5987 encoding
|
||||
check("attachment; filename X", "");
|
||||
// sanity check with WS on both sides
|
||||
check("attachment; filename = foo-A.html", "foo-A.html");
|
||||
// Bug 685192: in RFC2231/5987 encoding, a missing charset field should be
|
||||
// treated as error
|
||||
// the actual bug
|
||||
check("attachment; filename*=''foo", "foo");
|
||||
// sanity check
|
||||
check("attachment; filename*=a''foo", "foo");
|
||||
// Bug 692574: RFC2231/5987 decoding should not tolerate missing single
|
||||
// quotes
|
||||
// one missing
|
||||
check("attachment; filename*=UTF-8'foo-%41.html", "foo-A.html");
|
||||
// both missing
|
||||
check("attachment; filename*=foo-%41.html", "foo-A.html");
|
||||
// make sure fallback works
|
||||
check("attachment; filename*=UTF-8'foo-%41.html; filename=bar.html", "foo-A.html");
|
||||
// Bug 693806: RFC2231/5987 encoding: charset information should be treated
|
||||
// as authoritative
|
||||
// UTF-8 labeled ISO-8859-1
|
||||
check("attachment; filename*=ISO-8859-1''%c3%a4", "\u00c3\u00a4");
|
||||
// UTF-8 labeled ISO-8859-1, but with octets not allowed in ISO-8859-1
|
||||
// accepts x82, understands it as Win1252, maps it to Unicode \u20a1
|
||||
check("attachment; filename*=ISO-8859-1''%e2%82%ac", "\u00e2\u201a\u00ac");
|
||||
// defective UTF-8
|
||||
nocheck("attachment; filename*=UTF-8''A%e4B", "");
|
||||
// defective UTF-8, with fallback
|
||||
nocheck("attachment; filename*=UTF-8''A%e4B; filename=fallback", "fallback");
|
||||
// defective UTF-8 (continuations), with fallback
|
||||
nocheck("attachment; filename*0*=UTF-8''A%e4B; filename=fallback", "fallback");
|
||||
// check that charsets aren't mixed up
|
||||
check("attachment; filename*0*=ISO-8859-15''euro-sign%3d%a4; filename*=ISO-8859-1''currency-sign%3d%a4", "currency-sign=\u00a4");
|
||||
// same as above, except reversed
|
||||
check("attachment; filename*=ISO-8859-1''currency-sign%3d%a4; filename*0*=ISO-8859-15''euro-sign%3d%a4", "currency-sign=\u00a4");
|
||||
// Bug 704989: add workaround for broken Outlook Web App (OWA)
|
||||
// attachment handling
|
||||
check("attachment; filename*=\"a%20b\"", "a b");
|
||||
// Bug 717121: crash nsMIMEHeaderParamImpl::DoParameterInternal
|
||||
check("attachment; filename=\"", "");
|
||||
// We used to read past string if last param w/o = and ;
|
||||
// Note: was only detected on windows PGO builds
|
||||
check("attachment; filename=foo; trouble", "foo");
|
||||
// Same, followed by space, hits another case
|
||||
check("attachment; filename=foo; trouble ", "foo");
|
||||
check("attachment", "");
|
||||
// Bug 730574: quoted-string in RFC2231-continuations not handled
|
||||
check("attachment; filename=basic; filename*0=\"foo\"; filename*1=\"\\b\\a\\r.html\"", "foobar.html");
|
||||
// unmatched escape char
|
||||
check("attachment; filename=basic; filename*0=\"foo\"; filename*1=\"\\b\\a\\", "fooba\\");
|
||||
// Bug 732369: Content-Disposition parser does not require presence of ";" between params
|
||||
// optimally, this would not even return the disposition type "attachment"
|
||||
check("attachment; extension=bla filename=foo", "");
|
||||
check("attachment; filename=foo extension=bla", "foo");
|
||||
check("attachment filename=foo", "");
|
||||
// Bug 777687: handling of broken %escapes
|
||||
nocheck("attachment; filename*=UTF-8''f%oo; filename=bar", "bar");
|
||||
nocheck("attachment; filename*=UTF-8''foo%; filename=bar", "bar");
|
||||
// Bug 783502 - xpcshell test netwerk/test/unit/test_MIME_params.js fails on AddressSanitizer
|
||||
check("attachment; filename=\"\\b\\a\\", "ba\\");
|
||||
});
|
||||
|
||||
it("parse extra", function() {
|
||||
// Extra tests, not covered by above tests.
|
||||
check("inline; FILENAME=file.txt", "file.txt");
|
||||
check("INLINE; FILENAME= \"an example.html\"", "an example.html"); // RFC 6266, section 5.
|
||||
check("inline; filename= \"tl;dr.txt\"", "tl;dr.txt");
|
||||
check("INLINE; FILENAME*= \"an example.html\"", "an example.html");
|
||||
check("inline; filename*= \"tl;dr.txt\"", "tl;dr.txt");
|
||||
check("inline; filename*0=\"tl;dr and \"; filename*1=more.txt", "tl;dr and more.txt");
|
||||
});
|
||||
|
||||
it("parse issue 26", function() {
|
||||
// https://github.com/Rob--W/open-in-browser/issues/26
|
||||
check("attachment; filename=\xe5\x9c\x8b.pdf", "\u570b.pdf");
|
||||
});
|
||||
|
||||
it("parse issue 35", function() {
|
||||
// https://github.com/Rob--W/open-in-browser/issues/35
|
||||
check("attachment; filename=okre\x9clenia.rtf", "okreœlenia.rtf");
|
||||
});
|
||||
});
|
30
tests/test_mime.js
Normal file
30
tests/test_mime.js
Normal file
@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
// License: CC0 1.0
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const {MimeDB} = require("../lib/mime");
|
||||
|
||||
describe("MIME", function() {
|
||||
it("general", function() {
|
||||
expect(MimeDB.getMime("image/jpeg").major).to.equal("image");
|
||||
expect(MimeDB.getMime("image/jpeg").minor).to.equal("jpeg");
|
||||
expect(MimeDB.getMime("iMage/jPeg").major).to.equal("image");
|
||||
expect(MimeDB.getMime("imAge/jpEg").minor).to.equal("jpeg");
|
||||
});
|
||||
|
||||
it("exts", function() {
|
||||
expect(MimeDB.getMime("image/jpeg").primary).to.equal("jpg");
|
||||
expect(MimeDB.getMime("image/jpeg").primary).to.equal(
|
||||
MimeDB.getPrimary("image/jpeg"));
|
||||
expect(MimeDB.getMime("iMage/jPeg").primary).to.equal("jpg");
|
||||
expect(MimeDB.getMime("imAge/jpEg").primary).to.equal(
|
||||
MimeDB.getPrimary("image/jpeg"));
|
||||
expect(Array.from(MimeDB.getMime("imAge/jpEg").extensions)).to.deep.equal(
|
||||
["jpg", "jpeg", "jpe", "jfif"]);
|
||||
});
|
||||
|
||||
it("application/octet-stream should not yield results", function() {
|
||||
expect(MimeDB.getPrimary("application/octet-stream")).to.equal("");
|
||||
expect(MimeDB.getMime("application/octet-Stream")).to.be.undefined;
|
||||
});
|
||||
});
|
@ -19,7 +19,7 @@ const OPTS = {
|
||||
state: DownloadState.QUEUED,
|
||||
batch: 42,
|
||||
idx: 23,
|
||||
mask: "*name*.*ext",
|
||||
mask: "*name*.*ext*",
|
||||
description: "desc / ript.ion .",
|
||||
title: " *** TITLE *** ",
|
||||
};
|
||||
@ -57,6 +57,49 @@ describe("Renamer", function() {
|
||||
expect(dest.path).to.equal("");
|
||||
});
|
||||
|
||||
it("*name*.*ext* (mime override)", function() {
|
||||
const {dest} = new BaseDownload(
|
||||
Object.assign({}, OPTS, {
|
||||
mask: "*name* *batch*.*ext*",
|
||||
mime: "image/jpeg"
|
||||
}));
|
||||
expect(dest.full).to.equal("filenäme 042.jpg");
|
||||
expect(dest.name).to.equal("filenäme 042.jpg");
|
||||
expect(dest.base).to.equal("filenäme 042");
|
||||
expect(dest.ext).to.equal("jpg");
|
||||
expect(dest.path).to.equal("");
|
||||
});
|
||||
|
||||
it("*name*.*ext* (mime no override)", function() {
|
||||
const {dest} = new BaseDownload(
|
||||
Object.assign({}, OPTS, {
|
||||
mask: "*name* *batch*.*ext*",
|
||||
mime: "image/jpeg",
|
||||
url: "https://www.example.co.uk/filen%C3%A4me.JPe",
|
||||
usable: "https://www.example.co.uk/filenäme.JPe",
|
||||
}));
|
||||
expect(dest.full).to.equal("filenäme 042.JPe");
|
||||
expect(dest.name).to.equal("filenäme 042.JPe");
|
||||
expect(dest.base).to.equal("filenäme 042");
|
||||
expect(dest.ext).to.equal("JPe");
|
||||
expect(dest.path).to.equal("");
|
||||
});
|
||||
|
||||
it("*name*.*ext* (mime override; missing ext)", function() {
|
||||
const {dest} = new BaseDownload(
|
||||
Object.assign({}, OPTS, {
|
||||
mask: "*name* *batch*.*ext*",
|
||||
mime: "application/json",
|
||||
url: "https://www.example.co.uk/filen%C3%A4me",
|
||||
usable: "https://www.example.co.uk/filenäme",
|
||||
}));
|
||||
expect(dest.full).to.equal("filenäme 042.json");
|
||||
expect(dest.name).to.equal("filenäme 042.json");
|
||||
expect(dest.base).to.equal("filenäme 042");
|
||||
expect(dest.ext).to.equal("json");
|
||||
expect(dest.path).to.equal("");
|
||||
});
|
||||
|
||||
it("*text*", function() {
|
||||
const dest = makeOne("*text*");
|
||||
expect(dest.full).to.equal("desc/ript.ion");
|
||||
|
@ -12,6 +12,8 @@
|
||||
"noImplicitReturns": true,
|
||||
"noUnusedLocals": true,
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"importHelpers": true,
|
||||
"sourceMap": true
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: right;
|
||||
justify-content: flex-end;
|
||||
background: rgba(30, 30, 30, 0.2);
|
||||
margin-top: 2em;
|
||||
border-top: 1px solid rgba(30, 30, 30, 0.5);
|
||||
|
@ -15,16 +15,20 @@ export function addClass(elem: HTMLElement, ...cls: string[]) {
|
||||
|
||||
interface Timer {
|
||||
args: any[];
|
||||
id: number;
|
||||
}
|
||||
|
||||
export function debounce(fn: Function, to: number) {
|
||||
export function debounce(fn: Function, to: number, reset?: boolean) {
|
||||
let timer: Timer | null;
|
||||
return function(...args: any[]) {
|
||||
if (timer) {
|
||||
timer.args = args;
|
||||
return;
|
||||
if (!reset) {
|
||||
timer.args = args;
|
||||
return;
|
||||
}
|
||||
window.clearTimeout(timer.id);
|
||||
}
|
||||
setTimeout(function() {
|
||||
const id = window.setTimeout(function() {
|
||||
if (!timer) {
|
||||
return;
|
||||
}
|
||||
@ -37,7 +41,7 @@ export function debounce(fn: Function, to: number) {
|
||||
console.error(ex.toString(), ex);
|
||||
}
|
||||
}, to);
|
||||
timer = {args};
|
||||
timer = {args, id};
|
||||
};
|
||||
}
|
||||
|
||||
|
23
util/additional.types
Normal file
23
util/additional.types
Normal file
@ -0,0 +1,23 @@
|
||||
types {
|
||||
application/x-x509-ca-cert pem crt der;
|
||||
application/javascript js jsx;
|
||||
audio/x-matroska mka;
|
||||
image/bmp bmp;
|
||||
image/heic heic heif;
|
||||
image/heic heic heif;
|
||||
image/heif-sequence heic heif;
|
||||
image/heif-sequence heic heif;
|
||||
image/jpeg jpg jpeg jpe jfif;
|
||||
image/webp webp;
|
||||
text/html html htm shtml php;
|
||||
text/javascript js jsx;
|
||||
video/mpeg mpg mpe mpeg mpg;
|
||||
video/opus opus;
|
||||
video/x-matroska mkv mk3d mks;
|
||||
video/quicktime mov qt moov;
|
||||
application/x-compressed gz;
|
||||
application/x-gzip gz gzip;
|
||||
application/x-bzip2 bz2;
|
||||
application/x-tar tar;
|
||||
application/x-xz xz;
|
||||
}
|
@ -70,7 +70,7 @@ def main():
|
||||
if modified:
|
||||
try:
|
||||
with open("messages.json.tmp", "w", encoding="utf-8") as outp:
|
||||
json.dump(data, outp, sort_keys=True, indent=2)
|
||||
json.dump(data, outp, sort_keys=True, indent=2, ensure_ascii=False)
|
||||
os.rename("messages.json.tmp", "_locales/en/messages.json")
|
||||
finally:
|
||||
try:
|
||||
|
@ -26,7 +26,8 @@ UNCOMPRESSABLE = set((".png", ".jpg", ".zip", ".woff2"))
|
||||
LICENSED = set((".css", ".html", ".js", "*.ts"))
|
||||
IGNORED = set((".DS_Store", "Thumbs.db"))
|
||||
|
||||
PERM_IGNORED_FX = set(("downloads.shelf",))
|
||||
PERM_IGNORED_FX = set(("downloads.shelf", "webRequest", "webRequestBlocking"))
|
||||
PERM_IGNORED_CHROME = set(("menus", "sessions"))
|
||||
|
||||
SCRIPTS = [
|
||||
"yarn build:regexps",
|
||||
@ -90,8 +91,6 @@ def build_firefox(args):
|
||||
else:
|
||||
infos["browser_specific_settings"]["gecko"]["id"] = RELEASE_ID
|
||||
|
||||
|
||||
|
||||
infos["permissions"] = [p for p in infos.get("permissions") if not p in PERM_IGNORED_FX]
|
||||
out = Path("web-ext-artifacts") / f"dta-{version}-{args.mode}-fx.zip"
|
||||
if not out.parent.exists():
|
||||
@ -101,6 +100,33 @@ def build_firefox(args):
|
||||
print("Output", out)
|
||||
build(out, json.dumps(infos, indent=2).encode("utf-8"))
|
||||
|
||||
|
||||
def build_chrome(args):
|
||||
now = datetime.now().strftime("%Y%m%d%H%M%S")
|
||||
with open("manifest.json") as manip:
|
||||
infos = json.load(manip, object_pairs_hook=OrderedDict)
|
||||
|
||||
version = infos.get("version")
|
||||
if args.mode == "nightly":
|
||||
version = infos["version"] = f"{version}.{now}"
|
||||
|
||||
version = infos.get("version")
|
||||
|
||||
del infos["browser_specific_settings"]
|
||||
if args.mode != "release":
|
||||
infos["version_name"] = f"{version}-{args.mode}"
|
||||
infos["short_name"] = infos.get("name")
|
||||
infos["name"] = f"{infos.get('name')} {args.mode}"
|
||||
|
||||
infos["permissions"] = [p for p in infos.get("permissions") if not p in PERM_IGNORED_CHROME]
|
||||
out = Path("web-ext-artifacts") / f"dta-{version}-{args.mode}-crx.zip"
|
||||
if not out.parent.exists():
|
||||
out.parent.mkdir()
|
||||
if out.exists():
|
||||
out.unlink()
|
||||
print("Output", out)
|
||||
build(out, json.dumps(infos, indent=2).encode("utf-8"))
|
||||
|
||||
def main():
|
||||
from argparse import ArgumentParser
|
||||
args = ArgumentParser()
|
||||
@ -114,6 +140,7 @@ def main():
|
||||
else:
|
||||
run([script], shell=True)
|
||||
build_firefox(args)
|
||||
build_chrome(args)
|
||||
print("DONE.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
25
util/i18ntochrome.py
Executable file
25
util/i18ntochrome.py
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import re
|
||||
from collections import OrderedDict
|
||||
from pathlib import Path
|
||||
|
||||
re_valid = re.compile("[^A-Za-z0-9_]")
|
||||
|
||||
for file in Path("_locales/").glob("**/*.json"):
|
||||
with file.open("r") as filep:
|
||||
messages = json.load(filep, object_pairs_hook=OrderedDict)
|
||||
for x in list(messages):
|
||||
prev = x
|
||||
while True:
|
||||
y = re_valid.sub("_", x)
|
||||
if prev == y:
|
||||
break
|
||||
prev = y
|
||||
if x == y:
|
||||
continue
|
||||
messages[y] = messages[x]
|
||||
del messages[x]
|
||||
with file.open("w", encoding="utf-8") as filep:
|
||||
json.dump(messages, filep, ensure_ascii=False, indent=2)
|
16
util/makelocalelist.py
Executable file
16
util/makelocalelist.py
Executable file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
langs = sorted(Path("_locales").glob("**/messages.json"), key=lambda p: p.parent.name.casefold())
|
||||
all = {}
|
||||
for m in langs:
|
||||
loc = m.parent.name
|
||||
with m.open("r") as mp:
|
||||
lang = json.load(mp).get("language").get("message")
|
||||
if not lang:
|
||||
raise Exception(f"{m}: no language")
|
||||
lang = f"{lang} [{loc}]"
|
||||
all[loc] = lang
|
||||
with open("_locales/all.json", "wb") as op:
|
||||
op.write(json.dumps(all, indent=2, ensure_ascii=False).encode("utf-8"))
|
98
util/mime.types
Normal file
98
util/mime.types
Normal file
@ -0,0 +1,98 @@
|
||||
https://github.com/nginx/nginx/raw/master/conf/mime.types
|
||||
|
||||
types {
|
||||
text/html html htm shtml;
|
||||
text/css css;
|
||||
text/xml xml;
|
||||
image/gif gif;
|
||||
image/jpeg jpeg jpg;
|
||||
application/javascript js;
|
||||
application/atom+xml atom;
|
||||
application/rss+xml rss;
|
||||
|
||||
text/mathml mml;
|
||||
text/plain txt;
|
||||
text/vnd.sun.j2me.app-descriptor jad;
|
||||
text/vnd.wap.wml wml;
|
||||
text/x-component htc;
|
||||
|
||||
image/png png;
|
||||
image/svg+xml svg svgz;
|
||||
image/tiff tif tiff;
|
||||
image/vnd.wap.wbmp wbmp;
|
||||
image/webp webp;
|
||||
image/x-icon ico;
|
||||
image/x-jng jng;
|
||||
image/x-ms-bmp bmp;
|
||||
|
||||
font/woff woff;
|
||||
font/woff2 woff2;
|
||||
|
||||
application/java-archive jar war ear;
|
||||
application/json json;
|
||||
application/mac-binhex40 hqx;
|
||||
application/msword doc;
|
||||
application/pdf pdf;
|
||||
application/postscript ps eps ai;
|
||||
application/rtf rtf;
|
||||
application/vnd.apple.mpegurl m3u8;
|
||||
application/vnd.google-earth.kml+xml kml;
|
||||
application/vnd.google-earth.kmz kmz;
|
||||
application/vnd.ms-excel xls;
|
||||
application/vnd.ms-fontobject eot;
|
||||
application/vnd.ms-powerpoint ppt;
|
||||
application/vnd.oasis.opendocument.graphics odg;
|
||||
application/vnd.oasis.opendocument.presentation odp;
|
||||
application/vnd.oasis.opendocument.spreadsheet ods;
|
||||
application/vnd.oasis.opendocument.text odt;
|
||||
application/vnd.openxmlformats-officedocument.presentationml.presentation
|
||||
pptx;
|
||||
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
||||
xlsx;
|
||||
application/vnd.openxmlformats-officedocument.wordprocessingml.document
|
||||
docx;
|
||||
application/vnd.wap.wmlc wmlc;
|
||||
application/x-7z-compressed 7z;
|
||||
application/x-cocoa cco;
|
||||
application/x-java-archive-diff jardiff;
|
||||
application/x-java-jnlp-file jnlp;
|
||||
application/x-makeself run;
|
||||
application/x-perl pl pm;
|
||||
application/x-pilot prc pdb;
|
||||
application/x-rar-compressed rar;
|
||||
application/x-redhat-package-manager rpm;
|
||||
application/x-sea sea;
|
||||
application/x-shockwave-flash swf;
|
||||
application/x-stuffit sit;
|
||||
application/x-tcl tcl tk;
|
||||
application/x-x509-ca-cert der pem crt;
|
||||
application/x-xpinstall xpi;
|
||||
application/xhtml+xml xhtml;
|
||||
application/xspf+xml xspf;
|
||||
application/zip zip;
|
||||
|
||||
application/octet-stream bin exe dll;
|
||||
application/octet-stream deb;
|
||||
application/octet-stream dmg;
|
||||
application/octet-stream iso img;
|
||||
application/octet-stream msi msp msm;
|
||||
|
||||
audio/midi mid midi kar;
|
||||
audio/mpeg mp3;
|
||||
audio/ogg ogg;
|
||||
audio/x-m4a m4a;
|
||||
audio/x-realaudio ra;
|
||||
|
||||
video/3gpp 3gpp 3gp;
|
||||
video/mp2t ts;
|
||||
video/mp4 mp4;
|
||||
video/mpeg mpeg mpg;
|
||||
video/quicktime mov;
|
||||
video/webm webm;
|
||||
video/x-flv flv;
|
||||
video/x-m4v m4v;
|
||||
video/x-mng mng;
|
||||
video/x-ms-asf asx asf;
|
||||
video/x-ms-wmv wmv;
|
||||
video/x-msvideo avi;
|
||||
}
|
76
util/seed_mime.py
Executable file
76
util/seed_mime.py
Executable file
@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from collections import OrderedDict
|
||||
|
||||
def unique(seq):
|
||||
return list(OrderedDict([i, None] for i in seq if i))
|
||||
|
||||
def generate(major, minor, exts):
|
||||
exts = exts[:]
|
||||
yield f"{major}/{minor}", exts
|
||||
if (minor.startswith("x-")):
|
||||
yield f"{major}/{minor[2:]}", exts
|
||||
else:
|
||||
yield f"{major}/x-{minor}", exts
|
||||
for ext in exts:
|
||||
yield f"{major}/{ext}", exts
|
||||
yield f"{major}/x-{ext}", exts
|
||||
|
||||
|
||||
def make(text, final):
|
||||
lines = "".join([
|
||||
line.strip()
|
||||
for line in re.search(r"\{(.*)\}", text, re.S).group(1).split("\n")
|
||||
if line.strip() and not line.strip().startswith("#")
|
||||
]).split(";")
|
||||
|
||||
additional = []
|
||||
for line in lines:
|
||||
if not line:
|
||||
continue
|
||||
m = re.match(r"([a-z1-9]+)/([^\s]+)\s+(.+?)$", line)
|
||||
if not m:
|
||||
continue
|
||||
[major, minor, exts] = m.groups()
|
||||
exts = unique(e.lower().strip() for e in exts.split(" ") if e.strip())
|
||||
mime = f"{major}/{minor}"
|
||||
if mime == "application/octet-stream":
|
||||
continue
|
||||
if mime in final:
|
||||
final[mime] += exts
|
||||
continue
|
||||
final[mime] = exts
|
||||
additional += (major, minor, exts),
|
||||
|
||||
for [major, minor, exts] in additional:
|
||||
for [mime, exts] in generate(major, minor, exts):
|
||||
if mime in final:
|
||||
continue
|
||||
final[mime] = exts
|
||||
|
||||
final = OrderedDict()
|
||||
for file in sys.argv[1:]:
|
||||
with open(file, "r") as fp:
|
||||
make(fp.read(), final)
|
||||
|
||||
multi = dict()
|
||||
for [mime, exts] in list(final.items()):
|
||||
exts = unique(exts)
|
||||
prim = exts[0]
|
||||
final[mime] = prim
|
||||
if len(exts) == 1:
|
||||
continue
|
||||
exts = exts[1:]
|
||||
if len(exts) == 1:
|
||||
multi[prim] = exts[0]
|
||||
else:
|
||||
multi[prim] = exts
|
||||
|
||||
final = OrderedDict(sorted(final.items()))
|
||||
multi = OrderedDict(sorted(multi.items()))
|
||||
|
||||
print(json.dumps(dict(e=multi, m=final), indent=2))
|
||||
print("generated", len(final), "mimes", "with", len(multi), "multis", file=sys.stderr)
|
@ -32,7 +32,7 @@ module.exports = {
|
||||
if (request === "crypto") {
|
||||
return callback(null, "crypto");
|
||||
}
|
||||
if (request.includes("_locales")) {
|
||||
if (/_locales.*messages\.json/.test(request)) {
|
||||
return callback(null, "null");
|
||||
}
|
||||
return callback();
|
||||
@ -42,6 +42,11 @@ module.exports = {
|
||||
filename: "[name].js"
|
||||
},
|
||||
devtool: "source-map",
|
||||
stats: {
|
||||
hash: true,
|
||||
timings: true,
|
||||
maxModules: 2,
|
||||
},
|
||||
watchOptions: {
|
||||
ignored: /node_modules|bundles/
|
||||
},
|
||||
|
@ -19,7 +19,7 @@ export class Icons extends Map {
|
||||
}
|
||||
let cls = super.get(url);
|
||||
if (!cls) {
|
||||
cls = `icon-${++this.running}`;
|
||||
cls = `iconcache-${++this.running}`;
|
||||
const rule = `.${cls} { background-image: url(${url}); }`;
|
||||
this.sheet.insertRule(rule);
|
||||
super.set(url, cls);
|
||||
|
@ -128,8 +128,8 @@
|
||||
<template id="menufilter-template">
|
||||
<ul>
|
||||
<li id="ctx-menufilter-seperator">-</li>
|
||||
<li id="ctx-menufilter-invert" data-autoHide="false">Invert</li>
|
||||
<li id="ctx-menufilter-clear" data-autoHide="false">Clear</li>
|
||||
<li id="ctx-menufilter-invert" data-auto-hide="false">Invert</li>
|
||||
<li id="ctx-menufilter-clear" data-auto-hide="false">Clear</li>
|
||||
<li>-</li>
|
||||
<li id="ctx-menufilter-sort-ascending" data-icon="icon-sort-asc">Sort ascending</li>
|
||||
<li id="ctx-menufilter-sort-descending" data-icon="icon-sort-desc">Sort descending</li>
|
||||
|
@ -94,8 +94,10 @@ export class TextFilter extends ItemFilter {
|
||||
}
|
||||
|
||||
allow(item: DownloadItem) {
|
||||
return this.expr.test(
|
||||
[item.usable, item.description, item.finalName].join(" "));
|
||||
const {expr} = this;
|
||||
return expr.test(item.currentName) ||
|
||||
expr.test(item.usable) ||
|
||||
expr.test(item.description);
|
||||
}
|
||||
}
|
||||
|
||||
@ -340,14 +342,19 @@ export class UrlMenuFilter extends MenuFilter {
|
||||
async populate() {
|
||||
const filts = await filters();
|
||||
for (const i of filts.all.filter(e => e.id !== "deffilter-all")) {
|
||||
this.addItem(i.label, this.toggleRegularFilter.bind(this, i));
|
||||
this.addItem(
|
||||
i.label, this.toggleRegularFilter.bind(this, i), this.filters.has(i));
|
||||
}
|
||||
this.addItem("-");
|
||||
sort(
|
||||
const domains = sort(
|
||||
Array.from(new Set(this.collection.items.map(e => e.domain))),
|
||||
undefined,
|
||||
naturalCaseCompare
|
||||
).forEach(e => {
|
||||
);
|
||||
if (!domains.length) {
|
||||
return;
|
||||
}
|
||||
this.addItem("-");
|
||||
domains.forEach(e => {
|
||||
this.addItem(
|
||||
e, this.toggleDomainFilter.bind(this, e), this.domains.has(e));
|
||||
});
|
||||
@ -673,6 +680,11 @@ export class FilteredCollection extends EventEmitter {
|
||||
this.emit("sorted");
|
||||
}
|
||||
}
|
||||
|
||||
invalidateIcons() {
|
||||
this.items.forEach(item => item.clearFontIcons());
|
||||
this.recalculate();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -33,10 +33,11 @@ import { DownloadState, StateTexts, StateClasses, StateIcons } from "./state";
|
||||
import { Tooltip } from "./tooltip";
|
||||
import "../../lib/util";
|
||||
import { CellTypes } from "../../uikit/lib/constants";
|
||||
import { downloads } from "../../lib/browser";
|
||||
import { downloads, CHROME } from "../../lib/browser";
|
||||
import { $ } from "../winutil";
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import { TableConfig } from "../../uikit/lib/config";
|
||||
import { IconCache } from "../../lib/iconcache";
|
||||
|
||||
const TREE_CONFIG_VERSION = 2;
|
||||
const RUNNING_TIMEOUT = 1000;
|
||||
@ -52,7 +53,16 @@ const COL_SPEED = 6;
|
||||
const COL_MASK = 7;
|
||||
const COL_SEGS = 8;
|
||||
|
||||
const HIDPI = window.matchMedia &&
|
||||
window.matchMedia("(min-resolution: 2dppx)").matches;
|
||||
|
||||
const ICON_BASE_SIZE = 16;
|
||||
const ICON_REAL_SIZE = !CHROME && HIDPI ? ICON_BASE_SIZE * 2 : ICON_BASE_SIZE;
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
const LARGE_ICON_BASE_SIZE = CHROME ? 32 : 64;
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
const MAX_ICON_BASE_SIZE = CHROME ? 32 : 127;
|
||||
const LARGE_ICON_REAL_SIZE = HIDPI ? MAX_ICON_BASE_SIZE : LARGE_ICON_BASE_SIZE;
|
||||
|
||||
let TEXT_SIZE_UNKNOWM = "unknown";
|
||||
let REAL_STATE_TEXTS = Object.freeze(new Map<number, string>());
|
||||
@ -106,7 +116,9 @@ export class DownloadItem extends EventEmitter {
|
||||
|
||||
public error: string;
|
||||
|
||||
public finalName: string;
|
||||
public currentName: string;
|
||||
|
||||
public ext?: string;
|
||||
|
||||
public position: number;
|
||||
|
||||
@ -128,6 +140,12 @@ export class DownloadItem extends EventEmitter {
|
||||
|
||||
public mask: string;
|
||||
|
||||
private iconField?: string;
|
||||
|
||||
private largeIconField?: string;
|
||||
|
||||
public opening: boolean;
|
||||
|
||||
constructor(owner: DownloadTable, raw: any, stats?: Stats) {
|
||||
super();
|
||||
Object.assign(this, raw);
|
||||
@ -138,6 +156,42 @@ export class DownloadItem extends EventEmitter {
|
||||
this.lastWritten = 0;
|
||||
}
|
||||
|
||||
get icon() {
|
||||
if (this.iconField) {
|
||||
return this.iconField;
|
||||
}
|
||||
this.iconField = this.owner.icons.get(
|
||||
iconForPath(this.currentName, ICON_BASE_SIZE));
|
||||
if (this.ext) {
|
||||
IconCache.get(this.ext, ICON_REAL_SIZE).then(icon => {
|
||||
if (icon) {
|
||||
this.iconField = this.owner.icons.get(icon);
|
||||
if (typeof this.filteredPosition !== undefined) {
|
||||
this.owner.invalidateCell(this.filteredPosition, COL_URL);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return this.iconField || "";
|
||||
}
|
||||
|
||||
get largeIcon() {
|
||||
if (this.largeIconField) {
|
||||
return this.largeIconField;
|
||||
}
|
||||
this.largeIconField = this.owner.icons.get(
|
||||
iconForPath(this.currentName, LARGE_ICON_BASE_SIZE));
|
||||
if (this.ext) {
|
||||
IconCache.get(this.ext, LARGE_ICON_REAL_SIZE).then(icon => {
|
||||
if (icon) {
|
||||
this.largeIconField = this.owner.icons.get(icon);
|
||||
}
|
||||
this.emit("largeIcon");
|
||||
});
|
||||
}
|
||||
return this.largeIconField || "";
|
||||
}
|
||||
|
||||
get eta() {
|
||||
const {avg} = this.stats;
|
||||
if (!this.totalSize || !avg) {
|
||||
@ -165,7 +219,7 @@ export class DownloadItem extends EventEmitter {
|
||||
if (this.owner.showUrls.value) {
|
||||
return this.usable;
|
||||
}
|
||||
return this.finalName;
|
||||
return this.currentName;
|
||||
}
|
||||
|
||||
get fmtSize() {
|
||||
@ -215,6 +269,9 @@ export class DownloadItem extends EventEmitter {
|
||||
PORT.post("all");
|
||||
return;
|
||||
}
|
||||
if (("ext" in raw) && raw.ext !== this.ext) {
|
||||
this.clearIcons();
|
||||
}
|
||||
delete raw.position;
|
||||
delete raw.owner;
|
||||
const oldState = this.state;
|
||||
@ -297,6 +354,20 @@ export class DownloadItem extends EventEmitter {
|
||||
this.domain = this.uURL.domain;
|
||||
this.emit("url");
|
||||
}
|
||||
|
||||
clearIcons() {
|
||||
this.iconField = undefined;
|
||||
this.largeIconField = undefined;
|
||||
}
|
||||
|
||||
clearFontIcons() {
|
||||
if (this.iconField && this.iconField.startsWith("icon-")) {
|
||||
this.iconField = undefined;
|
||||
}
|
||||
if (this.largeIconField && this.largeIconField.startsWith("icon-")) {
|
||||
this.largeIconField = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -323,7 +394,7 @@ export class DownloadTable extends VirtualTable {
|
||||
|
||||
private readonly sids: Map<number, DownloadItem>;
|
||||
|
||||
private readonly icons: Icons;
|
||||
public readonly icons: Icons;
|
||||
|
||||
private readonly contextMenu: ContextMenu;
|
||||
|
||||
@ -357,6 +428,7 @@ export class DownloadTable extends VirtualTable {
|
||||
this.showUrls = new ShowUrlsWatcher(this);
|
||||
|
||||
this.updateCounts = debounce(this.updateCounts.bind(this), 100);
|
||||
this.onIconCached = debounce(this.onIconCached.bind(this), 1000);
|
||||
|
||||
this.downloads = new FilteredCollection(this);
|
||||
this.downloads.on("changed", () => this.updateCounts());
|
||||
@ -407,6 +479,8 @@ export class DownloadTable extends VirtualTable {
|
||||
col.iconElem.classList.remove("icon-filter");
|
||||
});
|
||||
|
||||
IconCache.on("cached", this.onIconCached.bind(this));
|
||||
|
||||
this.sids = new Map<number, DownloadItem>();
|
||||
this.icons = new Icons($("#icons"));
|
||||
|
||||
@ -450,8 +524,16 @@ export class DownloadTable extends VirtualTable {
|
||||
return true;
|
||||
});
|
||||
|
||||
Keys.on("SHIFT-Delete", (event: Event) => {
|
||||
const target = event.target as HTMLElement;
|
||||
if (target.localName === "input") {
|
||||
return false;
|
||||
}
|
||||
this.removeCompleteDownloads(false);
|
||||
return true;
|
||||
});
|
||||
|
||||
ctx.on("ctx-remove-all", () => this.removeAllDownloads());
|
||||
ctx.on("ctx-remove-complete", () => this.removeCompleteDownloads(false));
|
||||
ctx.on("ctx-remove-complete-all",
|
||||
() => this.removeCompleteDownloads(false));
|
||||
ctx.on("ctx-remove-complete-selected",
|
||||
@ -535,8 +617,12 @@ export class DownloadTable extends VirtualTable {
|
||||
this.selection.clear();
|
||||
|
||||
this.tooltip = null;
|
||||
this.on("hover", async info => {
|
||||
if (!(await Prefs.get("tooltip"))) {
|
||||
const tooltipWatcher = new PrefWatcher("tooltip", true);
|
||||
this.on("hover", info => {
|
||||
if (!document.hasFocus()) {
|
||||
return;
|
||||
}
|
||||
if (!tooltipWatcher.value) {
|
||||
return;
|
||||
}
|
||||
const item = this.downloads.filtered[info.rowid];
|
||||
@ -665,6 +751,7 @@ export class DownloadTable extends VirtualTable {
|
||||
}
|
||||
|
||||
selectionChanged() {
|
||||
this.dismissTooltip();
|
||||
const {empty} = this.selection;
|
||||
if (empty) {
|
||||
for (const d of this.disableSet) {
|
||||
@ -705,7 +792,8 @@ export class DownloadTable extends VirtualTable {
|
||||
}
|
||||
|
||||
resumeDownloads(forced = false) {
|
||||
const sids = this.getSelectedSids(DownloadState.RESUMABLE);
|
||||
const sids = this.getSelectedSids(
|
||||
forced ? DownloadState.FORCABLE : DownloadState.RESUMABLE);
|
||||
if (!sids.length) {
|
||||
return;
|
||||
}
|
||||
@ -729,20 +817,30 @@ export class DownloadTable extends VirtualTable {
|
||||
}
|
||||
|
||||
async openFile() {
|
||||
if (this.focusRow < 0) {
|
||||
this.dismissTooltip();
|
||||
const {focusRow} = this;
|
||||
if (focusRow < 0) {
|
||||
return;
|
||||
}
|
||||
const item = this.downloads.filtered[this.focusRow];
|
||||
const item = this.downloads.filtered[focusRow];
|
||||
if (!item || !item.manId || item.state !== DownloadState.DONE) {
|
||||
return;
|
||||
}
|
||||
item.opening = true;
|
||||
try {
|
||||
this.invalidateRow(focusRow);
|
||||
await downloads.open(item.manId);
|
||||
}
|
||||
catch (ex) {
|
||||
console.error(ex, ex.toString(), ex);
|
||||
PORT.post("missing", {sid: item.sessionId});
|
||||
}
|
||||
finally {
|
||||
setTimeout(() => {
|
||||
item.opening = false;
|
||||
this.invalidateRow(focusRow);
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
async openDirectory() {
|
||||
@ -993,10 +1091,16 @@ export class DownloadTable extends VirtualTable {
|
||||
this.updateSizes();
|
||||
$("#statusSpeedContainer").classList.remove("hidden");
|
||||
}
|
||||
if (item.manId && item.ext) {
|
||||
IconCache.set(item.ext, item.manId).catch(console.error);
|
||||
}
|
||||
break;
|
||||
|
||||
case DownloadState.DONE:
|
||||
this.finished++;
|
||||
if (item.manId && item.ext) {
|
||||
IconCache.set(item.ext, item.manId).catch(console.error);
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.selectionChanged();
|
||||
@ -1033,7 +1137,16 @@ export class DownloadTable extends VirtualTable {
|
||||
if (!item) {
|
||||
return null;
|
||||
}
|
||||
if (item.opening) {
|
||||
return ["opening"];
|
||||
}
|
||||
const cls = StateClasses.get(item.state);
|
||||
if (cls && item.opening) {
|
||||
return [cls, "opening"];
|
||||
}
|
||||
if (item.opening) {
|
||||
return ["opening"];
|
||||
}
|
||||
return cls && [cls] || null;
|
||||
}
|
||||
|
||||
@ -1043,10 +1156,10 @@ export class DownloadTable extends VirtualTable {
|
||||
}
|
||||
const item = this.downloads.filtered[rowid];
|
||||
if (colid === COL_URL) {
|
||||
return this.icons.get(iconForPath(item.finalName, ICON_BASE_SIZE));
|
||||
return item.icon;
|
||||
}
|
||||
if (colid === COL_PROGRESS) {
|
||||
return StateIcons.get(item.state);
|
||||
return StateIcons.get(item.state) || null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -1119,4 +1232,8 @@ export class DownloadTable extends VirtualTable {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
onIconCached() {
|
||||
this.downloads.invalidateIcons();
|
||||
}
|
||||
}
|
||||
|
@ -146,6 +146,8 @@ export class Tooltip {
|
||||
constructor(item: DownloadItem, pos: number) {
|
||||
this.update = this.update.bind(this);
|
||||
this.item = item;
|
||||
this.item.on("largeIcon", this.update);
|
||||
|
||||
const tmpl = (
|
||||
document.querySelector<HTMLTemplateElement>("#tooltip-template"));
|
||||
if (!tmpl) {
|
||||
@ -178,7 +180,7 @@ export class Tooltip {
|
||||
this.dismiss();
|
||||
return;
|
||||
}
|
||||
const icon = item.owner.getCellIcon(item.filteredPosition, 0);
|
||||
const icon = item.largeIcon;
|
||||
this.icon.className = icon;
|
||||
this.name.textContent = item.destFull;
|
||||
this.from.textContent = item.usable;
|
||||
@ -318,5 +320,6 @@ export class Tooltip {
|
||||
}
|
||||
this.item.off("stats", this.update);
|
||||
this.item.off("update", this.update);
|
||||
this.item.off("largeIcon", this.update);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,12 @@
|
||||
box-sizing: content-box !important;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: auto !important;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
ul {
|
||||
margin: 1.5ex;
|
||||
margin-right: 2ex;
|
||||
@ -25,6 +31,8 @@
|
||||
vertical-align: center;
|
||||
align-items: center;
|
||||
border-radius: 4px;
|
||||
cursor: default;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
li.sep {
|
||||
|
@ -6,7 +6,9 @@ import { localize } from "../lib/i18n";
|
||||
declare let browser: any;
|
||||
declare let chrome: any;
|
||||
|
||||
const runtime = browser !== "undefined" ? browser.runtime : chrome.runtime;
|
||||
const runtime = typeof browser !== "undefined" ?
|
||||
browser.runtime :
|
||||
chrome.runtime;
|
||||
|
||||
function handler(e: Event) {
|
||||
e.preventDefault();
|
||||
|
@ -72,6 +72,12 @@
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Translations</legend>
|
||||
<label>Language:
|
||||
<select id="languages">
|
||||
<option value="default">Browser default</option>
|
||||
</select>
|
||||
</label>
|
||||
<hr>
|
||||
<div>
|
||||
<button id="loadCustomLocale">Load custom translation</button>
|
||||
<button id="clearCustomLocale">Clear custom translation</button>
|
||||
|
@ -1,7 +1,13 @@
|
||||
"use strict";
|
||||
// License: MIT
|
||||
|
||||
import { _, localize, saveCustomLocale } from "../lib/i18n";
|
||||
import {
|
||||
ALL_LANGS,
|
||||
_,
|
||||
getCurrentLanguage,
|
||||
localize,
|
||||
saveCustomLocale,
|
||||
} from "../lib/i18n";
|
||||
import { Prefs, PrefWatcher } from "../lib/prefs";
|
||||
import { hostToDomain } from "../lib/util";
|
||||
import { filters } from "../lib/filters";
|
||||
@ -13,7 +19,7 @@ import { iconForPath, visible } from "../lib/windowutils";
|
||||
import { VirtualTable } from "../uikit/lib/table";
|
||||
import { Icons } from "./icons";
|
||||
import { $ } from "./winutil";
|
||||
import { runtime } from "../lib/browser";
|
||||
import { runtime, storage } from "../lib/browser";
|
||||
|
||||
const ICON_BASE_SIZE = 16;
|
||||
|
||||
@ -544,8 +550,8 @@ class LimitsUI extends VirtualTable {
|
||||
}
|
||||
|
||||
|
||||
addEventListener("DOMContentLoaded", () => {
|
||||
localize(document.documentElement);
|
||||
addEventListener("DOMContentLoaded", async () => {
|
||||
await localize(document.documentElement);
|
||||
|
||||
// General
|
||||
new BoolPref("pref-global-turbo", "global-turbo");
|
||||
@ -557,7 +563,7 @@ addEventListener("DOMContentLoaded", () => {
|
||||
new BoolPref("pref-text-links", "text-links");
|
||||
new BoolPref("pref-add-paused", "add-paused");
|
||||
new BoolPref("pref-show-urls", "show-urls");
|
||||
new BoolPref("pref-remove-missing-on-init", "show-urls");
|
||||
new BoolPref("pref-remove-missing-on-init", "remove-missing-on-init");
|
||||
new OptionPref("pref-conflict-action", "conflict-action");
|
||||
|
||||
$("#reset-confirmations").addEventListener("click", async () => {
|
||||
@ -587,6 +593,29 @@ addEventListener("DOMContentLoaded", () => {
|
||||
_("information.title"), _("reset-layouts.done"), _("ok"));
|
||||
});
|
||||
|
||||
|
||||
const langs = $<HTMLSelectElement>("#languages");
|
||||
const currentLang = getCurrentLanguage();
|
||||
for (const [code, lang] of ALL_LANGS.entries()) {
|
||||
const langEl = document.createElement("option");
|
||||
langEl.textContent = lang;
|
||||
langEl.value = code;
|
||||
if (code === currentLang) {
|
||||
langEl.selected = true;
|
||||
}
|
||||
langs.appendChild(langEl);
|
||||
}
|
||||
langs.addEventListener("change", async () => {
|
||||
await storage.sync.set({language: langs.value});
|
||||
if (langs.value === currentLang) {
|
||||
return;
|
||||
}
|
||||
// eslint-disable-next-line max-len
|
||||
if (confirm("Changing the selected translation requires restarting the extension.\nDo you want to restart the extension now?")) {
|
||||
runtime.reload();
|
||||
}
|
||||
});
|
||||
|
||||
// Filters
|
||||
visible("#filters").then(() => new FiltersUI());
|
||||
|
||||
@ -621,7 +650,7 @@ addEventListener("DOMContentLoaded", () => {
|
||||
reader.readAsText(file);
|
||||
});
|
||||
saveCustomLocale(text);
|
||||
if (confirm("Imported your file.\nWant to realod the extension now?")) {
|
||||
if (confirm("Imported your file.\nWant to relaod the extension now?")) {
|
||||
runtime.reload();
|
||||
}
|
||||
}
|
||||
|
@ -428,17 +428,42 @@ class SelectionTable extends VirtualTable {
|
||||
}
|
||||
|
||||
openSelection() {
|
||||
const items = this.items.filter((i, idx) => this.selection.contains(idx));
|
||||
if (!items.length) {
|
||||
const privates: BaseMatchedItem[] = [];
|
||||
const items = this.items.filter((i, idx) => this.selection.contains(idx)).
|
||||
filter(i => {
|
||||
if (i.private) {
|
||||
privates.push(i);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (!items.length && !privates.length) {
|
||||
if (this.focusRow < 0) {
|
||||
return;
|
||||
}
|
||||
items.push(this.items.at(this.focusRow));
|
||||
const item = this.items.at(this.focusRow);
|
||||
if (item.private) {
|
||||
privates.push(item);
|
||||
}
|
||||
else {
|
||||
items.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (items.length) {
|
||||
PORT.postMessage({
|
||||
msg: "openUrls",
|
||||
urls: items.map(e => e.url),
|
||||
incognito: false,
|
||||
});
|
||||
}
|
||||
if (privates.length) {
|
||||
PORT.postMessage({
|
||||
msg: "openUrls",
|
||||
urls: privates.map(e => e.url),
|
||||
incognito: true,
|
||||
});
|
||||
}
|
||||
PORT.postMessage({
|
||||
msg: "openUrls",
|
||||
urls: items.map(e => e.url)
|
||||
});
|
||||
}
|
||||
|
||||
applyDeltaTo(delta: ItemDelta[], items: ItemCollection) {
|
||||
|
10
yarn.lock
10
yarn.lock
@ -46,6 +46,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/psl/-/psl-1.1.0.tgz#390c5df1613b166ce3c3eb9fda4d93dc3eeec7b5"
|
||||
integrity sha512-HhZnoLAvI2koev3czVPzBNRYvdrzJGLjQbWZhqFmS9Q6a0yumc5qtfSahBGb5g+6qWvA8iiQktqGkwoIXa/BNQ==
|
||||
|
||||
"@types/whatwg-mimetype@^2.1.0":
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/whatwg-mimetype/-/whatwg-mimetype-2.1.0.tgz#f981bbdf1813a75820a6ec3a7fdfa0d452552cc7"
|
||||
integrity sha512-bJ/bZ+pA69lm+Ll8JJRoAD9saH7unIMfxPQQpl7bxa00qNqvUXSyk3xvoRMea1uCpAOxweI7CzjWx48ysX6yug==
|
||||
|
||||
"@typescript-eslint/eslint-plugin@^2.0.0":
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.0.0.tgz#609a5d7b00ce21a6f94d7ef282eba9da57ca1e42"
|
||||
@ -3718,6 +3723,11 @@ webpack@^4.39.3:
|
||||
watchpack "^1.6.0"
|
||||
webpack-sources "^1.4.1"
|
||||
|
||||
whatwg-mimetype@^2.3.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
|
||||
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==
|
||||
|
||||
which-module@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"
|
||||
|
Reference in New Issue
Block a user