OptionsUI: add 2 global options + simplify

* [x] show badge with active styles count
* [x] styles on top in the popup
* Simplify since we use a persistent background page so it's always there for us
This commit is contained in:
tophf 2017-03-28 13:05:58 +03:00
parent 4dd8066ca4
commit 7d9a6b5a3f
4 changed files with 139 additions and 50 deletions

View File

@ -488,7 +488,7 @@
"message": "Automatically check for and install all available userstyle updates (in hrs)" "message": "Automatically check for and install all available userstyle updates (in hrs)"
}, },
"optionsUpdateIntervalNote": { "optionsUpdateIntervalNote": {
"message": "To disable the automatic userstyle update checks, set interval to zero" "message": "To disable the automatic userstyle update checks, set interval to 0"
}, },
"optionsCustomize": { "optionsCustomize": {
"message": "UI Customizations" "message": "UI Customizations"

View File

@ -7,7 +7,11 @@ body {
} }
body > * { body > * {
padding: 1em 1rem 1em 44px; padding: .5rem 1.5rem 1em 48px;
}
body > *:first-child {
padding-top: .75rem;
} }
table { table {
@ -23,21 +27,24 @@ td:last-child {
text-align: right; text-align: right;
} }
button,
td:last-child,
input[type=number],
input[type="color"],
.onoffswitch,
#update-counter {
width: 80px;
}
a { a {
text-decoration-skip: ink; text-decoration-skip: ink;
} }
button { button {
text-align: center; text-align: center;
width: 80px;
}
h1:not(:first-child) {
margin-top: 0;
} }
input[type=number] { input[type=number] {
width: 80px;
text-align: right; text-align: right;
padding-right: 1em; padding-right: 1em;
} }
@ -66,7 +73,7 @@ input[type=number] {
#notes { #notes {
background-color: #f4f4f4; background-color: #f4f4f4;
margin-top: .5em; margin-top: .75rem;
font-size: 90%; font-size: 90%;
color: #999; color: #999;
} }
@ -81,7 +88,6 @@ input[type=number] {
} }
input[type="color"] { input[type="color"] {
width: 80px;
box-sizing: border-box; box-sizing: border-box;
height: 2em; height: 2em;
} }
@ -94,9 +100,73 @@ input[type="color"] {
color: black; color: black;
} }
#update-counter {
margin-top: .5ex;
position: absolute;
text-align: center;
}
@keyframes fadeinout { @keyframes fadeinout {
0% { opacity: 0 } 0% { opacity: 0 }
10% { opacity: 1 } 10% { opacity: 1 }
25% { opacity: 1 } 25% { opacity: 1 }
100% { opacity: 0 } 100% { opacity: 0 }
} }
/* On/Off FlipSwitch https://proto.io/freebies/onoff/ */
.onoffswitch {
position: relative;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
height: 12px;
padding: 0;
line-height: 12px;
border: 0 solid #E3E3E3;
border-radius: 12px;
background-color: #E0E0E0;
box-shadow: inset 2px 2px 4px rgba(0,0,0,0.1);
}
.onoffswitch-label:before {
content: "";
display: block;
width: 18px;
margin: -3px;
background: #efefef;
position: absolute;
top: 0;
bottom: 0;
right: 56px;
border-radius: 18px;
box-shadow: 0 3px 13px 0 rgba(0, 0, 0, 0.4);
}
.onoffswitch-checkbox:checked + .onoffswitch-label {
background-color: #CAEBE3;
}
.onoffswitch-checkbox:checked + .onoffswitch-label, .onoffswitch-checkbox:checked + .onoffswitch-label:before {
border-color: #CAEBE3;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label:before {
right: 0;
background-color: #04BA9F;
box-shadow: 3px 6px 18px 0 rgba(0, 0, 0, 0.2);
}

View File

@ -5,6 +5,7 @@
<link rel="stylesheet" href="index.css"> <link rel="stylesheet" href="index.css">
<script src="/localization.js"></script> <script src="/localization.js"></script>
<script src="/apply.js"></script> <script src="/apply.js"></script>
<script src="/storage.js"></script>
<script src="/messaging.js"></script> <script src="/messaging.js"></script>
<script src="/dom.js"></script> <script src="/dom.js"></script>
</head> </head>
@ -13,6 +14,24 @@
<div id="ui"> <div id="ui">
<h1 i18n-text="optionsCustomize"></h1> <h1 i18n-text="optionsCustomize"></h1>
<table> <table>
<tr>
<td i18n-text="prefShowBadge"></td>
<td>
<div class="onoffswitch">
<input type="checkbox" class="onoffswitch-checkbox" id="show-badge">
<label class="onoffswitch-label" for="show-badge"></label>
</div>
</td>
</tr>
<tr>
<td i18n-text="popupStylesFirst"></td>
<td>
<div class="onoffswitch">
<input type="checkbox" class="onoffswitch-checkbox" id="popup.stylesFirst">
<label class="onoffswitch-label" for="popup.stylesFirst"></label>
</div>
</td>
</tr>
<tr> <tr>
<td i18n-text="optionsBadgeNormal"></td> <td i18n-text="optionsBadgeNormal"></td>
<td><input type="color" id="badgeNormal"></td> <td><input type="color" id="badgeNormal"></td>
@ -46,8 +65,8 @@
<tr> <tr>
<td i18n-text="optionsCheckUpdate"></td> <td i18n-text="optionsCheckUpdate"></td>
<td> <td>
<span id="update-counter"></span>
<button type="button" data-cmd="check-updates" i18n-text="optionsCheck"></button> <button type="button" data-cmd="check-updates" i18n-text="optionsCheck"></button>
<div id="update-counter"></div>
</td> </td>
</tr> </tr>
</table> </table>

View File

@ -1,28 +1,30 @@
/* global update */
'use strict'; 'use strict';
function restore() { function restore() {
chrome.runtime.getBackgroundPage(bg => { setupLivePrefs([
$('#badgeDisabled').value = bg.prefs.get('badgeDisabled'); 'show-badge',
$('#badgeNormal').value = bg.prefs.get('badgeNormal'); 'popup.stylesFirst'
$('#popupWidth').value = localStorage.getItem('popupWidth') || '246'; ]);
$('#updateInterval').value = bg.prefs.get('updateInterval'); //$('#show-badge').value = bg.prefs.get('show-badge');
enforceValueRange('popupWidth'); $('#badgeDisabled').value = prefs.get('badgeDisabled');
}); $('#badgeNormal').value = prefs.get('badgeNormal');
$('#popupWidth').value = localStorage.getItem('popupWidth') || '246';
$('#updateInterval').value = prefs.get('updateInterval');
enforceValueRange('popupWidth');
} }
function save() { function save() {
chrome.runtime.getBackgroundPage(bg => { prefs.set('badgeDisabled', $('#badgeDisabled').value);
bg.prefs.set('badgeDisabled', $('#badgeDisabled').value); prefs.set('badgeNormal', $('#badgeNormal').value);
bg.prefs.set('badgeNormal', $('#badgeNormal').value); localStorage.setItem('popupWidth', enforceValueRange('popupWidth'));
localStorage.setItem('popupWidth', enforceValueRange('popupWidth')); prefs.set(
bg.prefs.set( 'updateInterval',
'updateInterval', Math.max(0, Number($('#updateInterval').value))
Math.max(0, Number($('#updateInterval').value)) );
); animateElement($('#save-status'), {className: 'fadeinout'});
animateElement($('#save-status'), {className: 'fadeinout'});
});
} }
@ -40,7 +42,7 @@ function enforceValueRange(id) {
} }
onDOMready().then(restore); restore();
$('#save').onclick = save; $('#save').onclick = save;
// overwrite the default URL if browser is Opera // overwrite the default URL if browser is Opera
@ -52,8 +54,8 @@ document.onclick = e => {
let total = 0; let total = 0;
let updated = 0; let updated = 0;
function update() { function showProgress() {
$('#update-counter').textContent = `${updated}/${total}`; $('#update-counter').textContent = `${updated} / ${total}`;
} }
function done(target) { function done(target) {
@ -64,25 +66,23 @@ document.onclick = e => {
} }
function check() { function check() {
chrome.runtime.getBackgroundPage(bg => { chrome.extension.getBackgroundPage().update.perform((cmd, value) => {
bg.update.perform((cmd, value) => { switch (cmd) {
switch (cmd) { case 'count':
case 'count': total = value;
total = value; if (!total) {
if (!total) { done(e.target);
done(e.target); }
} break;
break; case 'single-updated':
case 'single-updated': case 'single-skipped':
case 'single-skipped': updated++;
updated++; if (total && updated === total) {
if (total && updated === total) { done(e.target);
done(e.target); }
} break;
break; }
} showProgress();
update();
});
}); });
// notify the automatic updater to reset the next automatic update accordingly // notify the automatic updater to reset the next automatic update accordingly
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({