Skip to content

Commit

Permalink
Optional logging and no more speedlimits
Browse files Browse the repository at this point in the history
  • Loading branch information
Schwab Lukas committed Aug 16, 2019
1 parent 4722976 commit 2c6d23d
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 28 deletions.
3 changes: 3 additions & 0 deletions jquery.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"48": "icon48.png",
"128": "icon128.png"
},
"permissions": ["activeTab", "https://ajax.googleapis.com/"],
"permissions": ["activeTab", "https://ajax.googleapis.com/", "storage"],
"background": {
"scripts": ["background.js"]
},
Expand Down
6 changes: 6 additions & 0 deletions materialize.min.js

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,31 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css" />
<style>
html,
body {
width: 200px;
height: 200px;
}
#container {
width: 200px;
height: 200px;
}
#toggleLogging {
width: 160px;
height: 36px;
margin: 82px 20px;
user-select: none;
}
</style>
</head>
<body>
<div id="container">
<button id="toggleLogging">Logging is <span id="onoff"></span></button>
<div id="container" class="white">
<a id="toggleLogging" class="btn black white-text tooltipped hoverable center-align" data-position="top" data-tooltip="Click to toggle!">Logging is <span id="onoff"></span></a>
</div>
<script src="jquery.min.js"></script>
<script src="materialize.min.js"></script>
<script src="popup.js"></script>
</body>
</html>
47 changes: 30 additions & 17 deletions popup.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
const getLoggingState = () => localStorage.getItem('logging');
const setLoggingState = state => localStorage.setItem('logging', state);
const getLoggingState = () => {
return new Promise((resolve, reject) => {
chrome.storage.local.get(['logging'], result => {
resolve(result);
});
});
};

const toggleLoggingState = () => {
let state = getLoggingState();
if (!state || state === '') {
setLoggingState('off');
} else {
state === 'off' ? setLoggingState('on') : setLoggingState('off');
}
const setLoggingState = state => {
chrome.storage.local.set({ logging: state }, () => {
console.log(`chrome.storage API -> logging was turned ${state}`);
});
};

const updateSpan = () => {
let state = getLoggingState();
if (!state || state === '') {
setLoggingState('off');
}
document.getElementById('onoff').innerText = state;
const toggleLoggingState = () => {
getLoggingState().then(result => {
if (result.logging === 'off') {
setLoggingState('on');
} else {
setLoggingState('off');
}
updateSpan();
});
};

document.addEventListener('DOMContentLoaded', updateSpan);
document.getElementById('toggleLogging').addEventListener('click', toggleLoggingState);
const updateSpan = () => getLoggingState().then(result => $('#onoff').text(result.logging));

$(document).ready(function() {
$('#toggleLogging').click(() => {
toggleLoggingState();
});

updateSpan();
$('.tooltipped').tooltip();
});
22 changes: 14 additions & 8 deletions script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added settings.js
Empty file.

0 comments on commit 2c6d23d

Please sign in to comment.