working, still needs fixes tho

This commit is contained in:
Neale Pickett 2013-11-02 15:47:46 +00:00
parent d6438fe2c2
commit 562ae7042f
4 changed files with 93 additions and 129 deletions

View File

@ -4,6 +4,7 @@
"version": "5.2", "version": "5.2",
"manifest_version": 2, "manifest_version": 2,
"permissions": [ "storage" ], "permissions": [ "storage" ],
"offline_enabled": true,
"icons": { "icons": {
"128": "res/icon.png" "128": "res/icon.png"
}, },

View File

@ -1,5 +1,5 @@
chrome.app.runtime.onLaunched.addListener(function() { chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('../scoreboard.html', { chrome.app.window.create('../scoreboard.html', {
'state': 'fullscreen' //'state': 'fullscreen'
}) })
}) })

View File

@ -42,7 +42,7 @@ var state = SETUP;
var timer_updates = []; var timer_updates = [];
function update() { function update() {
for (i in timer_updates) { for (var i in timer_updates) {
var u = timer_updates[i]; var u = timer_updates[i];
u(); u();
@ -149,7 +149,7 @@ function transition(newstate) {
var jtext = e("jamtext"); var jtext = e("jamtext");
var jno = e("jamno"); var jno = e("jamno");
if ((newstate == undefined) || (newstate == state)) { if ((newstate === undefined) || (newstate == state)) {
return; return;
} }
@ -264,29 +264,10 @@ function handle(event) {
var newstate; var newstate;
switch (tgt.id) { switch (tgt.id) {
case "name-a":
case "name-b":
if (state == SETUP) {
var tn = prompt("Enter team " + team + " name", tgt.innerHTML);
if (tn) {
tgt.innerHTML = tn;
}
if (window.penalties) {
penalties_setTeamName(team, tn);
}
}
break;
case "logo-a": case "logo-a":
case "logo-b": case "logo-b":
if (state == SETUP) { if (state == SETUP) {
if (mod) { if (true) {
var u = prompt("Enter URL to team " + team + " logo");
if (u) {
tgt.src = u;
}
} else {
var t, name; var t, name;
logo[team] = (teams.length + logo[team] + adj) % teams.length; logo[team] = (teams.length + logo[team] + adj) % teams.length;
@ -324,24 +305,8 @@ function handle(event) {
break; break;
case "period": case "period":
if ((state == SETUP) || (state == TIMEOUT)) { if ((state == SETUP) || (state == TIMEOUT)) {
var r = prompt("Enter new time for period clock", tgt.innerHTML); // Nothin'
if (! r) return; } else {
var t = r.split(":");
var sec = 0;
if (t.length > 3) {
tgt.innerHTML = "What?";
return;
}
for (var i in t) {
var v = t[i];
sec = (sec * 60) + Number(v);
}
tgt.set(sec*1000);
} else {
newstate = TIMEOUT; newstate = TIMEOUT;
} }
break; break;
@ -392,10 +357,36 @@ function handle(event) {
function key(event) { function key(event) {
var e = event || window.event; var e = event || window.event;
var c = String.fromCharCode(e.which || e.keyCode || 0); var c;
var newstate; var newstate;
switch (e.keyCode) {
case 38:
c = "up";
break;
case 40:
c = "down";
break;
default:
c = String.fromCharCode(e.which || e.keyCode || 0);
break;
}
switch (c) { switch (c) {
case "up":
if ((state == TIMEOUT) || (state == SETUP)) {
var pt = document.getElementById("period");
var rem = pt.remaining();
pt.set(rem + 1000);
}
break;
case "down":
if ((state == TIMEOUT) || (state == SETUP)) {
var pt = document.getElementById("period");
var rem = pt.remaining();
pt.set(rem - 1000);
}
break;
case " ": case " ":
if (state == JAM) { if (state == JAM) {
newstate = LINEUP; newstate = LINEUP;
@ -446,57 +437,23 @@ function key(event) {
transition(newstate); transition(newstate);
} }
function get(k, d) {
var storage;
if (chrome) {
storage = chrome.storage.local
} else {
storage = window.localStorage;
}
if (! storage) {
return d;
}
var v = storage["rdsb_" + k];
if (v == undefined) {
return d;
}
return v;
}
function store(k, v) {
var storage;
if (chrome) {
storage = chrome.storage.local
} else {
storage = window.localStorage;
}
if ((v == undefined) || ! storage) {
return;
} else {
storage["rdsb_" + k] = v;
}
}
function save() { function save() {
if (window.penalties_save) { chrome.storage.sync.set(
penalties_save(); {
} "period_clock": e("period").remaining(),
store("period_clock", e("period").remaining()); "name_a": e("name-a").innerHTML,
store("name_a", e("name-a").innerHTML); "name_b": e("name-b").innerHTML,
store("name_b", e("name-b").innerHTML); "logo_a": e("logo-a").src,
store("logo_a", e("logo-a").src); "logo_b": e("logo-b").src,
store("logo_b", e("logo-b").src); "score_a": e("score-a").innerHTML,
store("score_a", e("score-a").innerHTML); "score_b": e("score-b").innerHTML,
store("score_b", e("score-b").innerHTML); "timeout_a": e("timeouts-a").innerHTML,
store("timeout_a", e("timeouts-a").innerHTML); "timeout_b": e("timeouts-b").innerHTML,
store("timeout_b", e("timeouts-b").innerHTML); "jamno": jamno,
store("jamno", jamno); "period": period,
store("period", period); }
);
} }
function iecheck() { function iecheck() {
@ -515,7 +472,13 @@ function iecheck() {
} }
} }
function ei(name) {
el = e(name);
if (el.addEventListener) {
el.addEventListener("click", handle, false);
}
return el;
}
function start() { function start() {
resize(); resize();
@ -525,34 +488,34 @@ function start() {
var j = document.getElementById("jam"); var j = document.getElementById("jam");
var c; var c;
// XXX: I think, instead of null, you can pass in a dictionary of defaults
function load(state) {
ei("name-a").innerHTML = state.name_a || "Home";
ei("name-b").innerHTML = state.name_b || "Vis";
ei("logo-a").src = state.logo_a || "logos/black.png";
ei("logo-b").src = state.logo_b || "logos/white.png";
ei("score-a").innerHTML = state.score_a || 0;
ei("score-b").innerHTML = state.score_b || 0;
ei("timeouts-a").innerHTML = state.timeout_a || 3;
ei("timeouts-b").innerHTML = state.timeout_b || 3;
period = state.period || 0;
jamno = state.jamno || 0;
// IE8 doesn't have localStorage for file:// URLs :< var c = state.period_clock || 1800000;
e("name-a").innerHTML = get("name_a", "Home"); startTimer(p);
e("name-b").innerHTML = get("name_b", "Vis"); p.set(c);
e("logo-a").src = get("logo_a", "logos/black.png"); }
e("logo-b").src = get("logo_b", "logos/white.png"); chrome.storage.sync.get(null, load);
e("score-a").innerHTML = get("score_a", 0);
e("score-b").innerHTML = get("score_b", 0);
e("timeouts-a").innerHTML = get("timeout_a", 3);
e("timeouts-b").innerHTML = get("timeout_b", 3);
period = Number(get("period", 0));
jamno = Number(get("jamno", 0));
save_itimer = setInterval(save, 1000); ei("jammer-a");
ei("jammer-b");
ei("period");
ei("jam");
if (window.penalties) { ei("periodtext").innerHTML = periodtext[period];
penalties_init(); ei("jamtext").innerHTML = jamtext[3];
}
e("periodtext").innerHTML = periodtext[period];
e("jamtext").innerHTML = jamtext[3];
transition(); transition();
c = Number(get("period_clock", 1800000));
startTimer(p);
p.set(c);
var j = document.getElementById("jam");
startTimer(j, window.tenths); startTimer(j, window.tenths);
j.set(120000); j.set(120000);
@ -590,5 +553,5 @@ function resize() {
} }
window.onload = start; window.onload = start;
document.onkeypress = key; // IE requires document, not window document.onkeydown = key; // IE requires document, not window
window.onresize = resize; window.onresize = resize;

View File

@ -31,24 +31,24 @@
--> -->
<div id="scoreboard"> <div id="scoreboard">
<p class="left"> <p class="left">
<img class="logo" id="logo-a" src="" alt="A" onclick="handle(event);"> <img class="logo" id="logo-a" src="" alt="A">
<span class="timeouts" id="timeouts-a" onclick="handle(event);">0</span> <span class="timeouts" id="timeouts-a">0</span>
<span class="jammer" id="jammer-a" onclick="handle(event);"></span> <span class="jammer" id="jammer-a"></span>
<span class="score" id="score-a" onclick="handle(event);">-</span> <span class="score" id="score-a">-</span>
</p> </p>
<p class="center"> <p class="center">
<span id="period" onclick="handle(event);">--:--</span> <span id="period">--:--</span>
<span id="periodtext" onclick="handle(event);"></span> <span id="periodtext"></span>
<span id="jam" onclick="handle(event);">-:--.-</span> <span id="jam">-:--.-</span>
<span id="jamtext" onclick="handle(event);"></span> <span id="jamtext"></span>
</p> </p>
<p class="right"> <p class="right">
<img class="logo" id="logo-b" src="" alt="B" onclick="handle(event);"> <img class="logo" id="logo-b" src="" alt="B">
<span class="timeouts" id="timeouts-b" onclick="handle(event);">0</span> <span class="timeouts" id="timeouts-b">0</span>
<span class="jammer" id="jammer-b" onclick="handle(event);"></span> <span class="jammer" id="jammer-b"></span>
<span class="score" id="score-b" onclick="handle(event);">-</span> <span class="score" id="score-b">-</span>
</p> </p>
</div> </div>