Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added upload file feature #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/ui/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ div, span {
float: left;
}

.uploadBtnContainer {
float: left;
}

.fileNameContainer {
float: left;
margin-right: 10px;
}

#domainDefs {
margin-top: 30px;
}
Expand Down Expand Up @@ -418,6 +427,12 @@ div, span {
text-align: center;
}

.uploadedFileName {
flex: 0 0 55px;
text-align: center;
padding-top: 10px;
}

.ruleContainer .fileType {
flex: 0 0 75px;
padding-top: 8px;
Expand Down
12 changes: 10 additions & 2 deletions src/ui/devtoolstab.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,16 @@
<div class="arrow">
To:
</div>
<div class="edit">
<button class="btn edit-btn">Edit File</button>
<div class="upload">
<div class="fileNameContainer">
<div class="uploadedFileName">
No File Selected
</div>
</div>
<div class="uploadBtnContainer">
<input style="display:none" class="file-btn" type="file" id="file" name="filename">
<button class="btn upload-btn">Upload File</button>
</div>
</div>
<div class="switch"></div>
<div class="delete">
Expand Down
4 changes: 4 additions & 0 deletions src/ui/devtoolstab.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
app.requestHeadersSuggest = app.suggest();
app.responseHeadersSuggest = app.suggest();
app.files = {};
app.fileNames = {};

app.skipNextSync = false;

function renderData() {
app.files = {};
app.fileNames = {};

ui.domainDefs.children().remove();
chrome.runtime.sendMessage({action: "getDomains"}, function(domains) {
if (domains.length) {
Expand Down
25 changes: 21 additions & 4 deletions src/ui/fileRule.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function() {
(function () {
"use strict";

/* globals $ */
Expand All @@ -13,9 +13,11 @@

const override = util.instanceTemplate(ui.fileOverrideTemplate);
const matchInput = override.find(".matchInput");
const editBtn = override.find(".edit-btn");
const ruleOnOff = override.find(".onoffswitch");
const deleteBtn = override.find(".sym-btn");
const uploadBtn = override.find(".upload-btn");
const fileBtn = override.find(".file-btn");
const fileName = override.find(".uploadedFileName");

matchInput.val(savedData.match || "");
util.makeFieldRequired(matchInput);
Expand All @@ -25,8 +27,22 @@
override.addClass("disabled");
}

editBtn.on("click", function() {
app.editor.open(override[0].id, matchInput.val(), false, saveFunc);
uploadBtn.on("click", function () {
document.getElementById('file').click();
});


fileBtn.on("change", function () {
const selectedFile = document.getElementById('file').files[0];

var reader = new FileReader();
reader.onload = function (event) {
app.files[override[0].id] = event.target.result;
app.fileNames[override[0].id] = selectedFile.name;
saveFunc();
fileName.text(selectedFile.name);
};
reader.readAsText(selectedFile);
});

deleteBtn.on("click", function() {
Expand Down Expand Up @@ -61,6 +77,7 @@

if (savedData.file) {
app.files[id] = savedData.file;
fileName.text(savedData.fileName);
}

return override;
Expand Down
1 change: 1 addition & 0 deletions src/ui/tabGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
type: "fileOverride",
match: $el.find(".matchInput").val(),
file: app.files[el.id] || "",
fileName: app.fileNames[el.id] || "No File Selected",
fileId: el.id,
on: $el.find(".onoffswitch")[0].isOn
});
Expand Down