From 886e8356e6a90e6be65c64de5d496638aae012c1 Mon Sep 17 00:00:00 2001 From: Ng Guoyou Date: Sat, 14 Jul 2018 18:12:28 +0800 Subject: [PATCH] Add option to prefer links over sources (#75) --- CHANGELOG.md | 3 ++- _locales/en/messages.json | 4 ++++ manifest.json | 2 +- package.json | 2 +- src/index.js | 9 ++++++++- src/option.js | 1 + src/options/options.html | 5 +++++ test/mockserver/index.js | 2 +- 8 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc30a67..ebccc5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ -# 2.6.3 +# 2.7.0 +* Add option to prefer links over media (#75) * Use @Rob--W's Content-Disposition parser (#73) (source: Rob--W/open-in-browser)[https://github.com/Rob--W/open-in-browser/blob/master/extension/content-disposition.js] * Add localisation hooks to most things diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 6b31552..e6ba3bd 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -322,6 +322,10 @@ "message": "Enable saving of links. Prefers sources if available" }, + "o_cPreferLinks": { + "message": "Prefer links over sources instead" + }, + "o_cSaveText": { "message": "Enable saving of selected text with a \".selection.txt\" extension" diff --git a/manifest.json b/manifest.json index 85bb903..ba330f9 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "__MSG_extensionName__", "description": "__MSG_extensionDescription__", - "version": "2.6.3", + "version": "2.7.0", "default_locale": "en", "applications": { diff --git a/package.json b/package.json index 818f101..e605ba7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "save-in", - "version": "2.6.3", + "version": "2.7.0", "license": "MIT", "scripts": { "build": "env -u WEB_EXT_API_KEY -u WEB_EXT_API_SECRET web-ext build --overwrite-dest -i test docs yarn.lock yarn-error.log", diff --git a/src/index.js b/src/index.js index 25bf031..af0e005 100644 --- a/src/index.js +++ b/src/index.js @@ -195,10 +195,17 @@ browser.contextMenus.onClicked.addListener(info => { let suggestedFilename = null; let downloadType = DOWNLOAD_TYPES.UNKNOWN; + const hasLink = options.links && info.linkUrl; + if (MEDIA_TYPES.includes(info.mediaType)) { downloadType = DOWNLOAD_TYPES.MEDIA; url = info.srcUrl; - } else if (options.links && info.linkUrl) { + + if (hasLink && options.preferLinks) { + downloadType = DOWNLOAD_TYPES.LINK; + url = info.linkUrl; + } + } else if (hasLink) { downloadType = DOWNLOAD_TYPES.LINK; url = info.linkUrl; } else if (options.selection && info.selectionText) { diff --git a/src/option.js b/src/option.js index a6ee0c6..613d3dc 100644 --- a/src/option.js +++ b/src/option.js @@ -31,6 +31,7 @@ const OptionsManagement = { { name: "keyLastUsed", type: T.VALUE, default: "a" }, { name: "keyRoot", type: T.VALUE, default: "a" }, { name: "links", type: T.BOOL, default: true }, + { name: "preferLinks", type: T.BOOL, default: false }, { name: "notifyDuration", type: T.VALUE, default: 7000 }, { name: "notifyOnFailure", type: T.BOOL, default: true }, { name: "notifyOnRuleMatch", type: T.BOOL, default: true }, diff --git a/src/options/options.html b/src/options/options.html index 6baa083..0ad7588 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -129,6 +129,11 @@

__MSG_o_sBehavior__