1
I’m trying to make a schedule that saves notes based on the agent’s number on Storage.local In q each one can have its annotation, where to display it/change it/delete it would just write the agent number in the input and it would return the content with the JS. But here’s what happens:
- I type in the agent and click show, appears Undefined (great, pq so far there is no data saved in the Storage.local)
- I type in the agent, write an annotation, click on salvage, right after I click on show and appears again Undefined.
I think the function salvage() is not saving the information on Storage.local, but why? Apparently the implementation is in accordance with the documentation. Someone could help me?
https://jsfiddle.net/fgodrvx7/2/
<main>
<header>
<span>anotações</span>
</header>
<section>
<div>
<input id="agente" type="text" maxlength="4" placeholder="Agente"/>
<input id="mostrar" type="submit" value="mostrar"/>
</div>
<textarea id="notas"></textarea>
</section>
<footer>
<div>
<i id="a_ok" class="hidden em em-white_check_mark"></i>
<i id="a_erro" class="hidden em em-x"></i>
</div>
<div>
<a id="limpar">limpar</a>
<input type="submit" id="salvar" value="salvar">
</div>
</footer>
</main>
document.addEventListener('DOMContentLoaded', function(){
//==[dados&itens]======================================
var agente = document.getElementById("agente");
var btnMostrar = document.getElementById("mostrar");
var notas = document.getElementById("notas");
var btnLimpar = document.getElementById("limpar");
var btnSalvar = document.getElementById("salvar");
var storage = chrome.storage.local;
//==[/dados&itens]=====================================
//==[funções]==========================================
function mostrar(storage, agente){ //mostrar(storage, agente, notas);
storage.get(agente.value, function(result){
var notas = document.getElementById("notas");
notas.value = result.agente;
});
}
function salvar(storage, agente, notas){ //salvar(storage, agente, notas);
storage.set({
[agente.value]: notas.value
});
storage.get(agente.value, function(result){
console.log(agente.value, result);
});
}
function limpar(notas){ // limpar(notas);
notas.value = "";
}
//==[/funções]=========================================
//==[trigger funções]==================================
btnMostrar.addEventListener('click', function(){
mostrar(storage, agente);
});
btnSalvar.addEventListener('click', function(){
salvar(storage, agente, notas);
});
btnLimpar.addEventListener('click', function(){
limpar(notas);
});
//==[/trigger funções]=================================
//chamando dr hans chucrutes\\
});
Read the document: https://developer.chrome.com/apps/storage and https://stackoverflow.com/questions/13872542/chrome-storage-local-get-and-set
– Maury Developer