1
0
Fork 0
mirror of https://github.com/gorhill/uMatrix.git synced 2024-06-28 11:00:38 +12:00

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
This commit is contained in:
Deathamns 2014-10-20 19:05:12 +02:00 committed by gorhill
parent 25caa9241c
commit da0e62dff6

View file

@ -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;