forked from Sulagna-Dutta-Roy/GGExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
956b651
commit 771efe1
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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" | ||
|
||
} | ||
} | ||
|
This file contains 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
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> |
This file contains 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
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(); | ||
}); | ||
|
This file contains 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
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; | ||
} | ||
|