Created
April 25, 2024 13:49
-
-
Save ramsunvtech/bd672d12e7ea2cc5849c1a0fac536f63 to your computer and use it in GitHub Desktop.
Chrome Installation React Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const ExtensionInstaller = () => { | |
const handleDrop = (event) => { | |
event.preventDefault(); | |
const file = event.dataTransfer.files[0]; | |
if (file.name.endsWith('.crx') || file.name.endsWith('.zip')) { | |
const reader = new FileReader(); | |
reader.onload = (event) => { | |
const url = event.target.result; | |
chrome.runtime.sendMessage({ | |
type: 'install', | |
url: url | |
}); | |
window.close(); | |
}; | |
reader.readAsDataURL(file); | |
} else { | |
alert('Please drop a .crx or .zip file.'); | |
} | |
}; | |
const handleDragOver = (event) => { | |
event.preventDefault(); | |
}; | |
return ( | |
<div> | |
<h1>Drag and Drop Extension Here</h1> | |
<div | |
onDrop={handleDrop} | |
onDragOver={handleDragOver} | |
style={{ width: '100%', height: '200px', border: '2px dashed #ccc', borderRadius: '5px', textAlign: 'center', lineHeight: '200px' }} | |
> | |
Drop Here | |
</div> | |
</div> | |
); | |
}; | |
export default ExtensionInstaller; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment