Skip to content

Commit

Permalink
file saver added
Browse files Browse the repository at this point in the history
  • Loading branch information
Yashgabani845 committed Jun 4, 2024
1 parent 956b651 commit 771efe1
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
14 changes: 14 additions & 0 deletions File Saver Extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"manifest_version": 3,
"name": "File Saver",
"version": "1.0",
"description": "Save files in local storage and download them later.",
"permissions": [
"storage"
],
"action": {
"default_popup": "popup.html"

}
}

24 changes: 24 additions & 0 deletions File Saver Extension/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Saver</title>
<link rel="stylesheet" href="styles.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-3" style="width: 450px; height: fit-content;padding: 30px;">
<h1 class="text-center">File Saver</h1>
<div class="form-group">
<input type="file" class="form-control-file" id="fileInput">
</div>
<button class="btn btn-primary btn-block" id="saveFile">Save File</button>
<div class="form-group mt-3">
<select class="form-control" id="fileList"></select>
</div>
<button class="btn btn-success btn-block" id="downloadFile">Download File</button>
</div>
<script src="popup.js"></script>
</body>
</html>
48 changes: 48 additions & 0 deletions File Saver Extension/popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
document.addEventListener('DOMContentLoaded', function() {
const fileInput = document.getElementById('fileInput');
const saveFileButton = document.getElementById('saveFile');
const fileList = document.getElementById('fileList');
const downloadFileButton = document.getElementById('downloadFile');

saveFileButton.addEventListener('click', () => {
const file = fileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const content = e.target.result;
chrome.storage.local.set({[file.name]: content}, function() {
updateFileList();
});
};
reader.readAsDataURL(file);
}
});

downloadFileButton.addEventListener('click', () => {
const selectedFile = fileList.value;
if (selectedFile) {
chrome.storage.local.get(selectedFile, function(result) {
const content = result[selectedFile];
const link = document.createElement('a');
link.href = content;
link.download = selectedFile;
link.click();
});
}
});

function updateFileList() {
chrome.storage.local.get(null, function(items) {
fileList.innerHTML = '';
for (let key in items) {
const option = document.createElement('option');
option.value = key;
option.textContent = key;
fileList.appendChild(option);
}
});
}

updateFileList();
});

14 changes: 14 additions & 0 deletions File Saver Extension/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body {
font-family: Arial, sans-serif;
padding: 10px;
}

h1 {
font-size: 18px;
}

input, button, select {
margin-top: 10px;
display: block;
}

0 comments on commit 771efe1

Please sign in to comment.