Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var $ = window.$
- var alert = window.alert
- var getCookie = window.getCookie
- function totalPoints () {
- getAllBoards(function (boards) {
- // message({
- // numberOfBoards: boards.length,
- // totalPossible: totalPossiblePoints(boards),
- // totalPoints: sumBoardPoints(boards),
- // boards: boards.map(getBoard)
- // })
- // var = '<div style="position: fixed;top: 0;left: 5px;">X</div>'
- message(sumBoardPoints(boards) + '/' + totalPossiblePoints(boards))
- })
- }
- function getAllBoards (cb) {
- $.get('cgi-bin/getBoards.py', {}, function (res) {
- cb(eval('(' + res + ')')['boards'])
- })
- }
- function getBoard (id) {
- var data = getCookie('boardState' + id)
- if (data !== '') {
- return JSON.parse(data)
- } else {
- return [[], []]
- }
- }
- function sumBoardPoints (boards) {
- return boards.map(getBoard).reduce(function (sum, boardState) {
- // NOTE: 1. solvedWithConnection = 2 points; 2. onlyGrouped = 1 point]
- return sum + (boardState[0].length * 2) + (boardState[1].length)
- }, 0)
- }
- function totalPossiblePoints (allBoards) {
- return allBoards.length * 8
- }
- function message (obj) { alert(JSON.stringify(obj, 0, 2)) }
- //
- totalPoints()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement