Contexto Hack

This is a Contexto Hack that Gives you the word of the day for everyday.

当前为 2023-06-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Contexto Hack
  3. // @namespace your-namespace-here
  4. // @version 1.0
  5. // @author longkidkoolstar
  6. // @description This is a Contexto Hack that Gives you the word of the day for everyday.
  7. // @icon https://th.bing.com/th/id/R.7b926e0e3ff4e38bba110ae354e71ef8?rik=ssJbNW18rrXCuw&pid=ImgRaw&r=0
  8. // @match https://contexto.me/*
  9. // @license CC BY-NC-ND 4.0
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to check if a string contains the number 1 by itself
  18. function containsOne(str) {
  19. return /^\D*1\D*$/.test(str);
  20. }
  21.  
  22. // Retrieve saved words and game numbers from Tampermonkey storage
  23. let savedWords = GM_getValue('savedWords', {});
  24. let gameNumbers = GM_getValue('gameNumbers', {});
  25.  
  26. // Function to search for words and game numbers to save on the page
  27. let currentGameNumber = '';
  28.  
  29. function searchForWordsAndGameNumbers() {
  30. // Find the game number element on the page
  31. const gameNumberElement = document.querySelector('.info-bar span:nth-child(2)');
  32. currentGameNumber = gameNumberElement ? gameNumberElement.textContent.trim().replace('#', '') : '';
  33.  
  34. // Find all the div elements with class "row" on the page
  35. const rows = document.querySelectorAll('.row');
  36. for (let i = 0; i < rows.length; i++) {
  37. const row = rows[i];
  38. // Find all the span elements within the row
  39. const spans = row.querySelectorAll('span');
  40. let hasOne = false;
  41. let word = '';
  42. for (let j = 0; j < spans.length; j++) {
  43. const span = spans[j];
  44. if (containsOne(span.innerHTML)) {
  45. hasOne = true;
  46. } else {
  47. word = span.innerHTML;
  48. }
  49. }
  50. // Save the word and game number to the objects if the word has the number 1 by itself and it's not already saved
  51. if (hasOne && word && !savedWords[word]) {
  52. savedWords[word] = true;
  53. gameNumbers[word] = currentGameNumber; // Save the current game number instead of searching for it again
  54. // Log the game number for the saved word
  55. console.log(`Game number for ${word}: ${currentGameNumber}`);
  56. }
  57. }
  58.  
  59. // Save the updated objects to Tampermonkey storage
  60. GM_setValue('savedWords', savedWords);
  61. GM_setValue('gameNumbers', gameNumbers);
  62.  
  63. // Update the GUI with the saved words and game numbers
  64. updateSavedWordsGUI();
  65. }
  66.  
  67. // Function to reveal the word for the current game number
  68. function revealWordForCurrentGameNumber() {
  69. // Find the saved word for the current game number
  70. const savedWordsForCurrentGameNumber = Object.keys(savedWords).filter((word) => {
  71. return gameNumbers[word] === currentGameNumber;
  72. });
  73.  
  74. // Display the saved word in an alert box
  75. if (savedWordsForCurrentGameNumber.length > 0) {
  76. alert(`The word for game number ${currentGameNumber} is: ${savedWordsForCurrentGameNumber[0]}`);
  77. } else {
  78. alert(`No saved words for game number ${currentGameNumber}`);
  79. }
  80. }
  81.  
  82. // Create a button to reveal the word for the current game number
  83. const revealButton = document.createElement('button');
  84. revealButton.textContent = 'Reveal Word';
  85. revealButton.addEventListener('click', revealWordForCurrentGameNumber);
  86. document.body.appendChild(revealButton);
  87.  
  88. // Create a div element to hold the saved words GUI
  89. const savedWordsGUI = document.createElement('div');
  90. savedWordsGUI.id = 'saved-words-list';
  91. document.body.appendChild(savedWordsGUI);
  92.  
  93. // Create a button to show the saved words GUI
  94. const showSavedWordsButton = document.createElement('button');
  95. showSavedWordsButton.textContent = 'Saved Words';
  96. showSavedWordsButton.addEventListener('click', () => {
  97. savedWordsGUI.classList.add('open');
  98. });
  99. document.body.appendChild(showSavedWordsButton);
  100.  
  101. // Create a button to minimize the saved words GUI
  102. const minimizeSavedWordsButton = document.createElement('button');
  103. minimizeSavedWordsButton.innerHTML = '<img src="https://th.bing.com/th/id/R.6a6eda3ee63c80ebc02dc830b395324e?rik=t2E%2fYYP3IGbSsQ&pid=ImgRaw&r=0" alt="Close">';
  104. minimizeSavedWordsButton.addEventListener('click', () => {
  105. savedWordsGUI.classList.remove('open');
  106. });
  107. savedWordsGUI.appendChild(minimizeSavedWordsButton);
  108.  
  109.  
  110. // Create a list element to display the saved words
  111. const savedWordsList = document.createElement('ul');
  112. savedWordsGUI.appendChild(savedWordsList);
  113.  
  114. // Function to update the saved words GUI with the saved words and game numbers
  115. function updateSavedWordsGUI() {
  116. // Clear the current saved words list
  117. savedWordsList.innerHTML = '';
  118.  
  119. // Get all saved words sorted by game number
  120. const savedWordsSorted = Object.keys(gameNumbers).sort((a, b) => {
  121. return gameNumbers[a] - gameNumbers[b];
  122. });
  123.  
  124. // Add each saved word to the list
  125. for (let i = 0; i < savedWordsSorted.length; i++) {
  126. const word = savedWordsSorted[i];
  127. const gameNumber = gameNumbers[word];
  128. const listItem = document.createElement('li');
  129. listItem.textContent = `${word} (Game ${gameNumber})`;
  130. savedWordsList.appendChild(listItem);
  131. }
  132. }
  133.  
  134. // Update the saved words GUI with the saved words and game numbers
  135. updateSavedWordsGUI();
  136.  
  137. // Function to clear the saved words and game numbers from Tampermonkey storage
  138. function clearSavedWords() {
  139. savedWords = {};
  140. gameNumbers = {};
  141. GM_setValue('savedWords', savedWords);
  142. GM_setValue('gameNumbers', gameNumbers);
  143. updateSavedWordsGUI();
  144. alert('Saved words cleared');
  145. }
  146.  
  147. // Create a button to clear the saved words and game numbers
  148. const clearSavedWordsButton = document.createElement('button');
  149. clearSavedWordsButton.textContent = 'Clear Saved Words';
  150. clearSavedWordsButton.addEventListener('click', clearSavedWords);
  151. savedWordsGUI.appendChild(clearSavedWordsButton);
  152.  
  153. // Function to export the saved words and game numbers as JSON
  154. function exportSavedWords() {
  155. const savedWordsData = {
  156. savedWords: savedWords,
  157. gameNumbers: gameNumbers
  158. };
  159. const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(savedWordsData));
  160. const downloadAnchorNode = document.createElement('a');
  161. downloadAnchorNode.setAttribute('href', dataStr);
  162. downloadAnchorNode.setAttribute('download', 'contexto_saved_words.json');
  163. document.body.appendChild(downloadAnchorNode); // required for firefox
  164. downloadAnchorNode.click();
  165. downloadAnchorNode.remove();
  166. }
  167.  
  168. // Create a button to export the saved words and game numbers
  169. const exportSavedWordsButton = document.createElement('button');
  170. exportSavedWordsButton.textContent = 'Export Saved Words';
  171. exportSavedWordsButton.addEventListener('click', exportSavedWords);
  172. savedWordsGUI.appendChild(exportSavedWordsButton);
  173.  
  174. // Function to import saved words and game numbers from JSON
  175. function importSavedWords() {
  176. const fileInput = document.createElement('input');
  177. fileInput.type = 'file';
  178. fileInput.accept = '.json';
  179. fileInput.addEventListener('change', () => {
  180. const file = fileInput.files[0];
  181. const reader = new FileReader();
  182. reader.onload = (e) => {
  183. try {
  184. const savedWordsData = JSON.parse(e.target.result);
  185. savedWords = savedWordsData.savedWords;
  186. gameNumbers = savedWordsData.gameNumbers;
  187. GM_setValue('savedWords', savedWords);
  188. GM_setValue('gameNumbers', gameNumbers);
  189. updateSavedWordsGUI();
  190. alert('Saved words imported');
  191. } catch (err) {
  192. alert('Error importing saved words');
  193. }
  194. };
  195. reader.readAsText(file);
  196. });
  197. fileInput.click();
  198. }
  199.  
  200. // Create a button to import saved words and game numbers
  201. const importSavedWordsButton = document.createElement('button');
  202. importSavedWordsButton.textContent = 'Import Saved Words';
  203. importSavedWordsButton.addEventListener('click', importSavedWords);
  204. savedWordsGUI.appendChild(importSavedWordsButton);
  205.  
  206. // Define CSS styles for the saved words GUI
  207. const css = `
  208. #saved-words-list {
  209. position: fixed;
  210. bottom: 0;
  211. right: 0;
  212. background-color: white;
  213. border: 2px solid black;
  214. border-radius: 5px 0 0 0;
  215. padding: 10px;
  216. max-height: 300px;
  217. overflow-y: auto;
  218. display: none;
  219. }
  220. #saved-words-list.open {
  221. display: block;
  222. }
  223. #saved-words-list button {
  224. margin: 5px;
  225. padding: 0;
  226. background: none;
  227. border: none;
  228. cursor: pointer;
  229. }
  230. #saved-words-list img {
  231. width: 20px;
  232. height: 20px;
  233. }
  234. `;
  235.  
  236. // Add the CSS styles to the page
  237. const style = document.createElement('style');
  238. style.appendChild(document.createTextNode(css));
  239. document.head.appendChild(style);
  240.  
  241. // Call the searchForWordsAndGameNumbers function every 5 seconds to continuously search for new words and game numbers on the page
  242. setInterval(searchForWordsAndGameNumbers, 5000);
  243. })();