WhichFaceIsReal Score Keeper

Test your human identification skills! This script keeps score for you on whichfaceisreal.com since they don't have that built in

  1. // ==UserScript==
  2. // @name WhichFaceIsReal Score Keeper
  3. // @namespace Violentmonkey Scripts
  4. // @namespace2 https://github.com/deltabravozulu/usefulUserScripts
  5. // @match *://www.whichfaceisreal.com/*
  6. // @grant none
  7. // @version 4.20.69
  8. // @author DeltaBravoZulu
  9. // @description Test your human identification skills! This script keeps score for you on whichfaceisreal.com since they don't have that built in
  10. // @description 2/18/2022, 1:23:53 PM
  11. // @run-at document-idle
  12. // @license PayMe
  13. // ==/UserScript==
  14.  
  15. // Make sure page loads before starting
  16. new MutationObserver(check).observe(document, {
  17. childList: true,
  18. subtree: true
  19. })
  20.  
  21. function check (changes, observer) {
  22. if (
  23. document.querySelector('#bs-example-navbar-collapse-1 > ul > li:nth-child(6)')
  24. ) {
  25. observer.disconnect()
  26. doIt()
  27. }
  28. }
  29.  
  30. function doIt () {
  31. let cor = 0
  32. let incor = 0
  33. let correct; let corElement = document.querySelector('html>body>div>div>div>p')
  34. if (corElement != null) {
  35. correct = document.querySelector('html>body>div>div>div>p').textContent.includes('You are correct')
  36. } else {
  37. correct === false
  38. }
  39. let incorrect; let incorElement = document.querySelector('html>body>div>div>div>p')
  40. if (incorElement != null) {
  41. incorrect = document.querySelector('html>body>div>div>div>p').textContent.includes('You are incorrect')
  42. } else {
  43. incorrect === false
  44. }
  45.  
  46. function corScore () {
  47. // Get Item from LocalStorage or correctCount === 0
  48. let correctCount = parseInt(localStorage.getItem('correctCount'), 10) || parseInt(0, 10)
  49.  
  50. if (typeof correct !== 'undefined') {
  51. if (correct === true) {
  52. cor += 1
  53. }
  54. }
  55. if (cor > 0) {
  56. // Set the score to the users' current points
  57. correctCount = parseInt(correctCount, 10) + parseInt(cor, 10)
  58. // Store the score
  59. localStorage.setItem('correctCount', parseInt(correctCount, 10))
  60. }
  61.  
  62. // Return the high score
  63. return correctCount
  64. }
  65.  
  66. function incorScore () {
  67. // Get Item from LocalStorage or incorrectCount === 0
  68. let incorrectCount = parseInt(localStorage.getItem('incorrectCount'), 10) || parseInt(0, 10)
  69.  
  70. if (incorrect === true) { incor += 1 }
  71. if (incor > 0) {
  72. // Set the score to the users' current points
  73. incorrectCount = parseInt(incorrectCount, 10) + parseInt(incor, 10)
  74. // Store the score
  75. localStorage.setItem('incorrectCount', parseInt(incorrectCount, 10))
  76. }
  77.  
  78. // Return the high score
  79. return incorrectCount
  80. }
  81.  
  82. function getScore () {
  83. let currentCorScore = parseInt(localStorage.getItem('correctCount'), 10)
  84. let currentInCorScore = parseInt(localStorage.getItem('incorrectCount'), 10)
  85.  
  86. function nukeScore () {
  87. localStorage.setItem('correctCount', 0)
  88. localStorage.setItem('incorrectCount', 0)
  89. document.querySelector('#inject').remove()
  90. getScore()
  91. }
  92. console.log('Correct: ' + currentCorScore)
  93. console.log('Incorrect: ' + currentInCorScore)
  94. htmlInject = '<div id="inject"></div>'
  95. document.querySelector('body > nav').insertAdjacentHTML('afterend', htmlInject)
  96. scoreInject = '<div id="score"><center><span class="correct" id="correct" style="color:#137333">&nbsp;&nbsp;Correct: <strong>' + currentCorScore + '</strong></span><span>&nbsp;&#09;&nbsp;&#09;&nbsp;</span><span class="incorrect" id="incorrect" style="color:#B31412"> Incorrect: <strong>' + currentInCorScore + '</strong></span></center></div>'
  97. document.querySelector('#inject').insertAdjacentHTML('afterbegin', scoreInject)
  98. buttonInject = '<div><center><button id="resetter" style="font-size:.5em">Reset?</button></center></div>'
  99. document.querySelector('#score').insertAdjacentHTML('afterend', buttonInject)
  100. document.getElementById('resetter').addEventListener('click', nukeScore)
  101. }
  102. corScore()
  103. incorScore()
  104. getScore()
  105. }