mirror of
https://github.com/gorhill/uMatrix.git
synced 2024-09-30 00:56:32 +13: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:
parent
25caa9241c
commit
da0e62dff6
1 changed files with 26 additions and 1 deletions
|
@ -1,10 +1,35 @@
|
||||||
// only for background and other extension pages
|
// could be used for background and other extension pages
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
window.vAPI = window.vAPI || {};
|
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) {
|
if (window.chrome) {
|
||||||
var chrome = window.chrome;
|
var chrome = window.chrome;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue