Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. var $ = window.$
  2. var alert = window.alert
  3. var getCookie = window.getCookie
  4.  
  5. function totalPoints () {
  6. getAllBoards(function (boards) {
  7. // message({
  8. // numberOfBoards: boards.length,
  9. // totalPossible: totalPossiblePoints(boards),
  10. // totalPoints: sumBoardPoints(boards),
  11. // boards: boards.map(getBoard)
  12. // })
  13.  
  14. // var = '<div style="position: fixed;top: 0;left: 5px;">X</div>'
  15. message(sumBoardPoints(boards) + '/' + totalPossiblePoints(boards))
  16. })
  17. }
  18.  
  19. function getAllBoards (cb) {
  20. $.get('cgi-bin/getBoards.py', {}, function (res) {
  21. cb(eval('(' + res + ')')['boards'])
  22. })
  23. }
  24.  
  25. function getBoard (id) {
  26. var data = getCookie('boardState' + id)
  27. if (data !== '') {
  28. return JSON.parse(data)
  29. } else {
  30. return [[], []]
  31. }
  32. }
  33.  
  34. function sumBoardPoints (boards) {
  35. return boards.map(getBoard).reduce(function (sum, boardState) {
  36. // NOTE: 1. solvedWithConnection = 2 points; 2. onlyGrouped = 1 point]
  37. return sum + (boardState[0].length * 2) + (boardState[1].length)
  38. }, 0)
  39. }
  40.  
  41. function totalPossiblePoints (allBoards) {
  42. return allBoards.length * 8
  43. }
  44.  
  45. function message (obj) { alert(JSON.stringify(obj, 0, 2)) }
  46.  
  47. //
  48.  
  49. totalPoints()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement