-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
33 lines (31 loc) · 1.18 KB
/
background.js
File metadata and controls
33 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
document.addEventListener( "DOMContentLoaded", function (){
var downloadVbs = function(){
var url = chrome.extension.getURL( "eject.vbs" );
chrome.downloads.download( {
url : url,
filename : "./" + url.replace( /^chrome-extension:\/\//, "" ),
conflictAction : "overwrite"
}, function( id ){
if( id === undefined ) return;
setTimeout( function(){
chrome.downloads.open( id );
chrome.downloads.erase( { id : id } );
}, 2000 );
} );
};
chrome.browserAction.onClicked.addListener( function( tab ){
var ejected;
chrome.system.storage.getInfo( function( devices ){
//console.log( devices );
devices.forEach( function (device){
if( device.capacity === 0 ){
chrome.system.storage.ejectDevice( device.id, function( result ){
if( result != 'failure' ) ejected = true;
} );
}
} );
} );
if( !ejected && navigator.userAgent.match( /Windows/i ) )downloadVbs();
else alert( 'failed to eject' );
} );
} );