I am following a youtube tutorial for making chrome extensions.
This is the Manifest file:
{
"manifest_version":2,
"name":"Budget Manager",
"version":"1.0",
"description":"This extension tracks your overall spendings.",
"icons":{
"128":"icon128.png",
"48":"icon48.png",
"16":"icon16.png"
},
"browser_action":{
"default_icon":"icon16.png",
"default_popup":"popup.html"
},
"permissions": [
"storage"
]
}
popup.html
<!DOCTYPE html>
<html>
<head>
<title>Budget Manager</title>
<script src="jquery-3.2.1.min.js">
</script>
<script src="popup.js">
</script>
</head>
<body>
<h1>Budget Manager</h1>
<h2>Total Spend: <span id="total">0</span></h2>
<h2>Limit: <span id="limit"></span></h2>
<h3>Enter Amount</h3>
<input type="text" id="amount"/>
<input type="submit" id="spendAmount" value="Spend">
</body>
</html>
popup.js
$(function() {
chrome.storage.sync.get('total', function (budget) {
$('#total').text(budget.total);
});
$('#spendAmount').click(function() {
chrome.storage.sync.get('total', function (budget) {
var newTotal = 0;
if (budget.total) {
newTotal += parseInt(budget.total);
}
var amount = $('amount').val();
if(amount) {
newTotal += parseInt(amount);
}
chrome.storage.sync.set({'total': newTotal});
$('#total').text(newTotal);
$('#amount').val('');
});
});
});
I am getting errors like:
'chrome' was used before it was defined --> chrome.storage.sync.get('total', function (budget) {
Missing 'use strict' statement --> chrome.storage.sync.get('total', function (budget) {
'$' was used before it was defined --> $(function){
Also another beginner question. Why are we using chrome.storage anyways? I mean if we don't have to sync. Why can't I just use normal variables to store the data.