Browse Source

Use HTML5 download instead of extension API

Benefits:
- Cross browser solution (however only for relatively new browsers)
- Doesn't need extra permission in Chrome

If the browser doesn't suppor the download attribute, then a new tab will
be opened with the exported data.

Other changes:
- Start the download only if the data is not empty (previously the
  download started anyway)
- Reorder code in vapi-client.js for Safari, so unnecessary code doesn't
  run on extension pages
pull/2/head
Deathamns 10 years ago
committed by gorhill
parent
commit
da0e62dff6
  1. 27
      src/js/vapi-common.js

27
src/js/vapi-common.js

@ -1,10 +1,35 @@
// only for background and other extension pages
// could be used for background and other extension pages
(function() {
'use strict';
window.vAPI = window.vAPI || {};
vAPI.download = function(details) {
if (!details.url) {
return;
}
var a = document.createElement('a');
if ('download' in a) {
a.href = details.url;
a.setAttribute('download', details.filename || '');
a.dispatchEvent(new MouseEvent('click'));
}
else {
var messager = vAPI.messaging.channel('download');
messager.send({
what: 'gotoURL',
details: {
url: a.target.href,
index: -1
}
});
messager.close();
}
};
if (window.chrome) {
var chrome = window.chrome;

Loading…
Cancel
Save