Skip to content

Commit

Permalink
Add option to prefer links over sources (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyng committed Jul 14, 2018
1 parent 68aa37b commit 886e835
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/option.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
5 changes: 5 additions & 0 deletions src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ <h3>__MSG_o_sBehavior__</h3>

<label>
<input type="checkbox" id="links" />__MSG_o_cSaveLinks__
<div class="caption caption-line">
<label>
<input type="checkbox" id="preferLinks" />__MSG_o_cPreferLinks__
</label>
</div>
</label>

<label>
Expand Down
2 changes: 1 addition & 1 deletion test/mockserver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const routes = {
ctx.body = `<html>
<a href="cd">Content-Disposition</a>
<br>
<img src="origami.jpg" />
<a href="cd"><img src="origami.jpg" /></a>
<hr>
Example tests
<br>
Expand Down

0 comments on commit 886e835

Please sign in to comment.