diff --git a/src/js/vapi-common.js b/src/js/vapi-common.js index 5d22bb0..5cd1449 100644 --- a/src/js/vapi-common.js +++ b/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;