Greasy Fork is available in English.

SolverDuo

It solves practice lessons automatically or manually, to increase xp use DuoSolverGrinder tool (https://duosolver.is-great.net).

  1. // ==UserScript==
  2. // @name SolverDuo
  3. // @name:es SolverDuo
  4. // @name:es-419 SolverDuo
  5. // @name:fr SolverDuo
  6. // @name:vi SolverDuo
  7. // @name:fr-CA SolverDuo
  8. // @namespace Violentmonkey Scripts
  9. // @match https://*.duolingo.com/*
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @grant GM_addStyle
  13. // @require https://cdn.tailwindcss.com
  14. // @version 1.1.0
  15. // @author DuoSolverGrinder, has as base DuoPower modified totally.
  16. // @description It solves practice lessons automatically or manually, to increase xp use DuoSolverGrinder tool (https://duosolver.is-great.net).
  17. // @description:es Soluciona lecciones de práctica automáticamente o manualmente, para incrementar xp usa la herramienta DuoSolverGrinder (https://duosolver.is-great.net).
  18. // @description:es-419 Soluciona lecciones de práctica automáticamente o manualmente, para incrementar xp usa la herramienta DuoSolverGrinder (https://duosolver.is-great.net).
  19. // @description:fr Résolvez les leçons pratiques automatiquement ou manuellement, pour augmenter l'XP, utilisez l'outil DuoSolverGrinder (https://duosolver.is-great.net).
  20. // @description:fr-CA Résolvez les leçons pratiques automatiquement ou manuellement, pour augmenter l'XP, utilisez l'outil DuoSolverGrinder (https://duosolver.is-great.net).
  21. // @description:vi Giải bài thực hành tự động hoặc thủ công, để tăng xp hãy sử dụng công cụ DuoSolverGrinder (https://duosolver.is-great.net).
  22. // ==/UserScript==
  23.  
  24. let solveTimerId;
  25. let isAutoMode = GM_getValue('isAutoMode', false);
  26. let isPanelShow = GM_getValue('isPanelShow', true);
  27. let solveSpeedList = {'speedSlow': 2000, 'speedMedium': 1000, 'speedFast': 500, 'speedFastest': 0 }
  28. let solveSpeed = GM_getValue('solveSpeed', 'speedMedium');
  29.  
  30. const version = '1.1.0';
  31. const mainLessonFormClass = "[id='root'] > div > div > div > div > div:first-child._3v4ux";
  32.  
  33. let panelHtml = `
  34. <div id="panelShowBttns" class="flex flex-col gap-y-2 z-[111] fixed xl:bottom-4 right-5 bottom-48 hidden">
  35. <button id="panelShowBttn" class="font-bold text-gray-800 shadow-lg rounded-full px-2 bg-indigo-200 border border-2" >+</button>
  36. <a target="_blank"class="px-1" href="https://duosolver.is-great.net/">
  37. <img class="rounded-md w-7 h-7" src="https://duosolvergrinder.github.io/DuoSolverGrinder/dsg.png" >
  38. </a>
  39. </div>
  40. <div id="panelDuoSolver" class="inline-flex flex-col gap-y-4 justify-end rounded-xl fixed xl:bottom-4 right-5 bottom-28 z-[111] border border-1 p-4 bg-indigo-400 dark:bg-gray-900">
  41. <button id="panelHideBttn" title="hide" class="w-6 self-center rounded-lg bg-gray-600 text-gray-200">-</button>
  42. <button id="startBttn" class="px-4 py-2 rounded-md border border-2 bg-blue-600 text-gray-200 dark:bg-gray-300 dark:text-gray-800">Start</button>
  43. <section class="inline-flex rounded-md shadow-sm" role="group">
  44. <button id="speedSlow" type="button" class="speedSelector px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-s-lg dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:focus:ring-blue-500 dark:focus:text-white">
  45. Slow
  46. </button>
  47. <button id="speedMedium" type="button" class="speedSelector px-4 py-2 text-sm font-medium text-gray-900 bg-white border-t border-b border-gray-200 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:focus:ring-blue-500 dark:focus:text-white">
  48. Medium
  49. </button>
  50. <button id="speedFast" type="button" class="speedSelector px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:focus:ring-blue-500 dark:focus:text-white">
  51. Fast
  52. </button>
  53. <button id="speedFastest" type="button" class="speedSelector px-4 py-2 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-e-lg dark:bg-gray-800 dark:border-gray-700 dark:text-white dark:focus:ring-blue-500 dark:focus:text-white">
  54. Fastest
  55. </button>
  56. </section>
  57. <p class="dark:text-gray-200">To grind higher xp, use next link:</p>
  58. <div class="flex justify-center gap-x-2">
  59. <a target="_blank" href="https://github.com/DuoSolverGrinder/DuoSolverGrinder/">
  60. <svg class="dark:hidden text-red-500 w-8 h-8" fill="none" viewBox="0 0 120 120"
  61. stroke="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#24292f"/>
  62. </svg>
  63. <svg class="hidden dark:block w-8 h-8" fill="none" viewBox="0 0 120 120" stroke="currentColor" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#fff"/>
  64. </svg>
  65. </a>
  66. <a target="_blank" href="https://duosolver.is-great.net/">
  67. <img class="rounded-md w-7 h-7" src="https://duosolvergrinder.github.io/DuoSolverGrinder/dsg.png" >
  68. </a>
  69. </div>
  70. <div class="flex justify-center">
  71. <span class="dark:text-gray-200">v${version}</span>
  72. </div>
  73. </div>
  74. `;
  75.  
  76.  
  77. let solvesBttnHtml = `
  78. <button id="solveBttn" style="--web-ui_button-background-color: rgb(var(--color-gold)); --web-ui_button-border-color: rgb(var(--color-gold))" class="_1rcV8 _1VYyp _1ursp _7jW2t _3DbUj _38g3s lg:block hidden">Solve</button>
  79. <button id="solveAllBttn" class="_1rcV8 _1VYyp _1ursp _7jW2t _3DbUj _38g3s _2oGJR">Solve All</button>
  80. `;
  81.  
  82. function insertPanelAndBttns()
  83. {
  84. let panel = document.getElementById('panelDuoSolver');
  85. if(!panel) {
  86. document.body.insertAdjacentHTML('beforeend', panelHtml);
  87. let bttn = document.getElementById('startBttn');
  88. bttn.addEventListener('click', startStopMain );
  89. const showBttn = document.getElementById('panelShowBttn');
  90. const hideBttn = document.getElementById('panelHideBttn');
  91. showBttn.addEventListener('click', toggleShowHidePanel );
  92. hideBttn.addEventListener('click', toggleShowHidePanel );
  93. document.querySelectorAll('.speedSelector').forEach((element)=> element.addEventListener('click', speedSolveChange));
  94. updatePanelDisplay();
  95. updateSpeedBttnsActive();
  96. }
  97. if (window.location.pathname === '/lesson' || window.location.pathname === '/practice') {
  98. addButtons();
  99. panel ? panel.children[1].style.display = 'none' : null;
  100. return;
  101. }
  102. panel ? panel.children[1].style.display = '': null;
  103. }
  104.  
  105. window.onload = (event) => {
  106. GM_addStyle('img { max-width: none}');
  107. }
  108.  
  109. setInterval(insertPanelAndBttns, 1000);
  110.  
  111.  
  112. function speedSolveChange()
  113. {
  114. solveSpeed = this.id;
  115. GM_setValue('solveSpeed', solveSpeed);
  116. updateSpeedBttnsActive();
  117. }
  118.  
  119. function updateSpeedBttnsActive()
  120. {
  121. const speedBttns = document.querySelectorAll('.speedSelector');
  122. speedBttns.forEach((element)=> {
  123. if(element.id == solveSpeed) {
  124. element.classList.remove('bg-white', 'text-gray-900', 'font-semibold', 'dark:bg-gray-800');
  125. element.classList.add('bg-gray-900', 'text-white', 'font-bold', 'dark:bg-black');
  126. return;
  127. }
  128. element.classList.add('bg-white', 'text-gray-900', 'font-semibold', 'dark:bg-gray-800');
  129. element.classList.remove('bg-gray-900', 'text-white', 'font-bold', 'dark:bg-black');
  130. });
  131.  
  132. }
  133.  
  134. function updatePanelDisplay(display)
  135. {
  136. const panelShowBttns = document.getElementById('panelShowBttns');
  137. const panel = document.getElementById('panelDuoSolver');
  138. if(isPanelShow) {
  139. panel.classList.remove('collapse');
  140. panelShowBttns.classList.add('hidden');
  141. return;
  142. }
  143. GM_setValue('isPanelShow', false);
  144. panel.classList.add('collapse');
  145. panelShowBttns.classList.remove('hidden');
  146. return;
  147.  
  148. }
  149.  
  150. function toggleShowHidePanel()
  151. {
  152. isPanelShow = !GM_getValue('isPanelShow');
  153. GM_setValue('isPanelShow', isPanelShow )
  154. updatePanelDisplay();
  155. }
  156.  
  157. function setAutoMode(state)
  158. {
  159. isAutoMode = state;
  160. GM_setValue('isAutoMode', state);
  161. }
  162.  
  163. function startStopMain()
  164. {
  165. setAutoMode(!isAutoMode);
  166. updateBttnsCaptions();
  167. if(isAutoMode) {
  168. window.location.assign('/practice');
  169. }
  170.  
  171. }
  172.  
  173.  
  174. function addButtons()
  175. {
  176. const checkBttn = document.querySelectorAll('[data-test="player-next"]')[0];
  177. if(!checkBttn) {
  178. return;
  179. }
  180. let solveAllBttn = document.getElementById("solveAllBttn");
  181. if (solveAllBttn !== null) {
  182. return;
  183. }
  184. checkBttn.parentElement.classList.add('flex', 'gap-x-8');
  185. checkBttn.parentElement.insertAdjacentHTML('beforeend',solvesBttnHtml);
  186.  
  187. const solveBttn = document.getElementById("solveBttn");
  188. solveAllBttn = document.getElementById("solveAllBttn");
  189. solveBttn.addEventListener('click', solveOne);
  190. solveAllBttn.addEventListener('click', solvingAll);
  191.  
  192. updateBttnsCaptions();
  193. resetTimerAutoMode();
  194. }
  195.  
  196.  
  197.  
  198. function updateBttnsCaptions()
  199. {
  200. const solveAllBttn = document.getElementById("solveAllBttn");
  201. const startBttn = document.getElementById("startBttn");
  202. if (isAutoMode) {
  203. solveAllBttn ? solveAllBttn.innerText = "PAUSE ALL" : null;
  204. startBttn ? startBttn.innerText = "Stop" : null;
  205. } else {
  206. solveAllBttn ? solveAllBttn.innerText = "SOLVE ALL" : null;
  207. startBttn ? startBttn.innerText = "Start" : null;
  208. }
  209. }
  210.  
  211.  
  212. function solvingAll()
  213. {
  214. setAutoMode(!isAutoMode);
  215. updateBttnsCaptions();
  216. resetTimerAutoMode();
  217. }
  218.  
  219. function solveOne()
  220. {
  221. const practiceAgain = document.querySelector('[data-test="player-practice-again"]');
  222. if (practiceAgain !== null && isAutoMode) {
  223. practiceAgain.click();
  224. return;
  225. }
  226. if(document.querySelector('[data-test="session-complete-slide"]') && isAutoMode && !practiceAgain && window.innerWidth <= 768 && window.location.pathname === '/practice') {
  227. window.location.assign('/practice');
  228. return;
  229. }
  230.  
  231. let subType = "";
  232. try {
  233. window.sol = findReact(document.querySelectorAll(mainLessonFormClass)[0]).props.currentChallenge;
  234. subType = window.sol.challengeGeneratorIdentifier.specificType;
  235. } catch {
  236. let next = document.querySelector('[data-test="player-next"]');
  237. if (next) {
  238. next.click();
  239. }
  240. resetTimerAutoMode();
  241. return;
  242. }
  243. if (!window.sol) {
  244. resetTimerAutoMode();
  245. return;
  246. }
  247.  
  248. let nextButton = document.querySelector('[data-test="player-next"]');
  249. if (!nextButton) {
  250. resetTimerAutoMode();
  251. return;
  252. }
  253.  
  254.  
  255. switch(window.sol.type) {
  256. case "listenMatch":
  257. case "listenIsolation":
  258. case "listenTap":
  259. case "speak":
  260. const buttonSkip = document.querySelector('button[data-test="player-skip"]');
  261. if (buttonSkip) {
  262. buttonSkip.click();
  263. }
  264. break;
  265. case "translate":
  266. switch(subType)
  267. {
  268. case "reverse_translate":
  269. const elm = document.querySelector('textarea[data-test="challenge-translate-input"]');
  270. if(elm) {
  271. const nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
  272. nativeInputValueSetter.call(elm, window.sol.correctSolutions ? window.sol.correctSolutions[0] : window.sol.prompt);
  273. let inputEvent = new Event('input', {
  274. bubbles: true
  275. });
  276. elm.dispatchEvent(inputEvent);
  277. }
  278. break;
  279. case "tap":
  280. case "reverse_tap":
  281. translateTapReverseTapSolve();
  282. break;
  283. default:
  284. null;
  285. }
  286. break;
  287. case "assist":
  288. case "gapFill":
  289. document.querySelectorAll('[data-test="challenge-choice"]')[window.sol.correctIndex]?.click();
  290. break;
  291. case "name":
  292. let textInput = document.querySelector('[data-test="challenge-text-input"]');
  293. if(textInput) {
  294. if(window.sol.correctSolutions) {
  295. let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
  296. nativeInputValueSetter.call(textInput, window.sol.correctSolutions[0]);
  297. let inputEvent = new Event('input', {
  298. bubbles: true
  299. });
  300. textInput.dispatchEvent(inputEvent);
  301. }
  302. }
  303. break;
  304. case "partialReverseTranslate":
  305. let elm = document.querySelector('[data-test*="challenge-partialReverseTranslate"]')?.querySelector("span[contenteditable]");
  306. if(elm) {
  307. let nativeInputNodeTextSetter = Object.getOwnPropertyDescriptor(Node.prototype, "textContent").set;
  308. nativeInputNodeTextSetter.call(elm, window.sol?.displayTokens?.filter(t => t.isBlank)?.map(t => t.text)?.join()?.replaceAll(',', '') );
  309. let inputEvent = new Event('input', {
  310. bubbles: true
  311. });
  312. elm.dispatchEvent(inputEvent);
  313. }
  314. break;
  315. default:
  316. null;
  317. }
  318.  
  319. nextButton.click();
  320. resetTimerAutoMode();
  321. }
  322.  
  323. function translateTapReverseTapSolve() {
  324. const all_tokens = document.querySelectorAll('[data-test$="challenge-tap-token"]');
  325. const correct_tokens = window.sol.correctTokens;
  326. const clicked_tokens = [];
  327. correct_tokens.forEach(correct_token => {
  328. const matching_elements = Array.from(all_tokens).filter(element => element.textContent.trim() === correct_token.trim());
  329. if (matching_elements.length > 0) {
  330. const match_index = clicked_tokens.filter(token => token.textContent.trim() === correct_token.trim()).length;
  331. if (match_index < matching_elements.length) {
  332. matching_elements[match_index].click();
  333. clicked_tokens.push(matching_elements[match_index]);
  334. } else {
  335. clicked_tokens.push(matching_elements[0]);
  336. }
  337. }
  338. });
  339. }
  340.  
  341. function resetTimerAutoMode()
  342. {
  343. if(isAutoMode) {
  344. clearTimeout(solveTimerId);
  345. solveTimerId = setTimeout(solveOne, solveSpeedList[solveSpeed]);
  346. }
  347. }
  348.  
  349. function findReact(dom) {
  350. let reactProps = Object.keys(dom.parentElement).find((key) => key.startsWith("__reactProps$"));
  351. let child = dom?.parentElement?.[reactProps]?.children;
  352. return child?.props?.children?._owner?.stateNode ?? child?._owner?.stateNode;
  353. }