-
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.
Refactored adding profiles so that it saves as JSON
- Loading branch information
Delia
committed
Aug 21, 2020
1 parent
a8720f7
commit 62b6b94
Showing
7 changed files
with
173 additions
and
65 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,57 +1,101 @@ | ||
|
||
let n = 4; | ||
|
||
// Saves options to chrome.storage | ||
function save_options() { | ||
var bio = document.getElementById('bio').value; | ||
var sec = document.getElementById('sec').value; | ||
var next = document.getElementById('next').value; | ||
var arr=["test"]; | ||
|
||
chrome.storage.sync.set({ | ||
bio: bio, | ||
sec: sec, | ||
next: next, | ||
}, function() { | ||
// Update status to let user know options were saved. | ||
var status = document.getElementById('status'); | ||
status.textContent = 'Options saved.'; | ||
setTimeout(function() { | ||
status.textContent = ''; | ||
}, 750); | ||
}); | ||
} | ||
// Restores select box and checkbox state using the preferences | ||
// stored in chrome.storage. | ||
function restore_options() { | ||
chrome.storage.sync.get({ | ||
bio: '', | ||
sec: '', | ||
next: '' | ||
}, function(items) { | ||
document.getElementById('bio').value = items.bio; | ||
document.getElementById('sec').value = items.sec; | ||
document.getElementById('next').value = items.next; | ||
console.log("restoring values " + items.sec, items.bio); | ||
}); | ||
var profiles = document.getElementsByClassName("category") | ||
for (var i = 0; i < profiles.length; i++) { | ||
var profile = $(`#profile${i}`).text(); | ||
var bio = $(`#bio${i}`).val(); | ||
var obj = { id: i , name: profile, bio: bio }; | ||
arr.push(obj); | ||
} | ||
|
||
function add_profile(){ | ||
let n = 4 | ||
let profile = "Graphics" | ||
let element = `<legend><span class="number">${n}</span> ${profile} </legend> <label >Cover Letter:</label><textarea name="user_bio"></textarea>`; | ||
const position = 'beforeend' | ||
document.getElementById('data').insertAdjacentHTML(position, element); | ||
chrome.storage.sync.set({ | ||
bio: '', | ||
list: arr | ||
}, function () { | ||
// Update status to let user know options were saved. | ||
var status = document.getElementById('status'); | ||
status.textContent = 'Options saved.'; | ||
setTimeout(function () { | ||
status.textContent = ''; | ||
}, 750); | ||
}); | ||
} | ||
|
||
function restore_options() { | ||
console.log("restoring options") | ||
chrome.storage.sync.get({ | ||
bio: 'test', | ||
list: arr }, | ||
function (data) { | ||
console.log("in options") | ||
console.log(data.list); | ||
console.log(data.bio) | ||
// update(data.list); //storing the storage value in a variable and passing to update function | ||
// function (items) { | ||
// console.log("this is it" + arr); | ||
// items.forEach((item, i) => { | ||
// console.log(item) | ||
// // document.getElementById(`bio${i}`).value = item.bio; | ||
// add_profile(item.bio) | ||
// }) | ||
}); | ||
|
||
function update(array) { | ||
// | ||
// obj = JSON.parse(text); | ||
// document.getElementById("demo").innerHTML += add_element(obj.profile[1], obj.desc[1]) | ||
// | ||
array.push("testAdd"); | ||
//then call the set to update with modified value | ||
chrome.storage.sync.set({ | ||
[items]: "" | ||
}, function(list) { | ||
console.log("restoring values " + list[items]); | ||
document.getElementById('coverLetter').value = list[items] | ||
list: array | ||
}, function () { | ||
console.log("added to list with new values"); | ||
}); | ||
} | ||
} | ||
|
||
// | ||
// function add_element(profile, n) { | ||
// let element = ` <div class="category"> | ||
// <legend><span class="number">${n}</span>${profile}</legend> | ||
// <div class="info_option"> | ||
// <label for="bio${n}">Cover Letter:</label> | ||
// <textarea id="bio${n}" name="user_bio"></textarea> | ||
// </div> | ||
// </div>`; | ||
// const position = 'beforeend' | ||
// document.getElementById('data').insertAdjacentHTML(element); | ||
// } | ||
|
||
function create_new_profile() { | ||
var n = document.getElementsByClassName("category").length + 1; | ||
console.log(n); | ||
var inputValue = document.getElementById("myInput").value; | ||
let element = ` <div class="category"> | ||
<legend> | ||
<span class="number">${n}</span> | ||
<label id="profile${n}" class="profile">${inputValue}</label> | ||
</legend> | ||
<div class="info_option"> | ||
<label class="profile" for="bio${n}">Cover Letter:</label> | ||
<textarea id="bio${n}" name="user_bio"></textarea> | ||
</div> | ||
</div>`; | ||
document.getElementById('data').insertAdjacentHTML('beforeend', element); | ||
document.getElementById("myInput").value = ""; | ||
save_options() | ||
} | ||
|
||
$(document).ready(function(){ | ||
document.addEventListener('DOMContentLoaded', restore_options); | ||
document.getElementById('save').addEventListener('click', | ||
save_options); | ||
document.getElementById('add_item').addEventListener('click', | ||
add_profile); | ||
save_options); | ||
document.getElementById('add_new_profile').addEventListener('click', create_new_profile); | ||
}) | ||
|
||
|
||
|
||
|
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
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
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