'mac',
'pass',
'port',
+ 'theme',
];
function load_settings() {
var storage = chrome.storage.local;
chrome.storage.local.get(settings_keys, function(settings) {
+ set_theme(settings['theme'] || 'dark');
var form = $$('form[name=settings]');
form.host.value = settings['host'] || '192.168.0.255';
form.port.value = settings['port'] || '40000';
'mac': form.mac.value,
'pass': form.pass.value,
'port': form.port.value,
+ 'theme': curr_theme,
};
chrome.storage.local.set(settings);
}
$$('form[name=settings]').onsubmit = send;
$$('a[name=mac-paste]').onclick = paste_mac;
$$('a[name=pass-paste]').onclick = paste_pass;
+ $$('input[name=theme]').onclick = toggle_theme;
load_settings();
};
--- /dev/null
+// Written by Mike Frysinger <vapier@gmail.com>.
+// Released into the public domain.
+
+/*
+ * This code is all very simple/dumb. If we want to ever support more
+ * complicated theme logic, then it should be thrown away entirely.
+ */
+
+var curr_theme;
+
+function _set_theme(txt, fg, bg, a) {
+ var b = $$('body');
+ b.style.color = fg;
+ b.style.backgroundColor = bg;
+
+ // This gets a bit tricky as we want to update the style sheet
+ // to quickly apply to all <a> tags.
+ var s, sheet, sheets, r, rule, rules;
+ sheets = document.styleSheets;
+ for (s = 0; s < sheets.length; ++s) {
+ sheet = sheets[s];
+ rules = sheet.cssRules;
+ for (r = 0; r < rules.length; ++r) {
+ rule = rules[r];
+ if (rule.selectorText == 'a') {
+ rule.style.color = a;
+ break;
+ }
+ }
+ }
+
+ // We can't set UTF8 text, or set HTML entities directly. Ugh.
+ var span = document.createElement('span');
+ span.innerHTML = txt;
+ $$('input[name=theme]').value = span.innerText;
+}
+
+function set_theme(name) {
+ var themes = {
+ 'light': ['☀', 'black', 'white', 'black'],
+ 'dark': ['☼', 'white', 'black', 'grey']
+ };
+ curr_theme = name;
+ _set_theme.apply(this, themes[name]);
+ chrome.storage.local.set({'theme': curr_theme});
+}
+
+function toggle_theme() {
+ if (curr_theme == 'light')
+ set_theme('dark');
+ else
+ set_theme('light');
+}
<script src='js/net_error_list.js'></script>
<script src='js/common.js'></script>
<script src='js/main.js'></script>
+<script src='js/theme.js'></script>
<style>
body {
background-color: black;
text-align: center;
}
+input[name=theme] {
+ text-align: center;
+ position: absolute;
+ top: 3px;
+ left: 3px;
+}
+
a {
color: grey;
}
<a href='https://en.wikipedia.org/wiki/Wake-on-LAN' target='_blank'>
Wake-On-Lan (WOL) Magic Packet Generator
</a>
+ <input type='button' name='theme' value='☼'>
</p>
<div class='settings'>