PWNEDuo (based on DuoHacker).

Duolingo automation auto answer script. Include skill leveling up (13.01.2023 update)

  1. // ==UserScript==
  2. // @name PWNEDuo (based on DuoHacker).
  3. // @description Duolingo automation auto answer script. Include skill leveling up (13.01.2023 update)
  4. // @namespace Violentmonkey Scripts
  5. // @match https://*.duolingo.com/*
  6. // @grant none
  7. // @version 1.0.4
  8. // @author hprnv
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. var intervalId;
  13. var isAutoMode = false;
  14. function addButtons() {
  15. /*
  16. if(window.location.pathname == '/learn'){
  17. let button = document.querySelector('a[data-test="global-practice"]');
  18. if(button){
  19. button.click();
  20. return;
  21. }
  22. }
  23. */
  24. if (document.getElementById("solveAllButton") !== null) {
  25. return;
  26. }
  27.  
  28. let original = document.querySelectorAll('[data-test="player-next"]')[0];
  29. let wrapper = document.getElementsByClassName('_10vOG')[0];
  30. if (original == undefined) {
  31. let startButton = document.querySelector('[data-test="start-button"]');
  32. if (startButton == undefined) {
  33. return;
  34. }
  35. let wrapper = startButton.parentNode;
  36. let autoComplete = document.createElement('a');
  37. autoComplete.className = startButton.className;
  38. autoComplete.id = "solveAllButton";
  39. autoComplete.innerText = "COMPLETE SKILL";
  40. autoComplete.removeAttribute('href');
  41. autoComplete.onclick = function () {
  42. startSolving();
  43. setInterval(function () {
  44. let startButton = document.querySelector('[data-test="start-button"]');
  45. if (startButton && startButton.innerText.startsWith("START")) {
  46. startButton.click();
  47. }
  48. }, 3000);
  49. startButton.click();
  50. };
  51. wrapper.appendChild(autoComplete);
  52. } else {
  53.  
  54. wrapper.style.display = "flex";
  55.  
  56. let solveCopy = document.createElement('button');
  57. let pauseCopy = document.createElement('button');
  58.  
  59. solveCopy.id = 'solveAllButton';
  60. if (intervalId) {
  61. solveCopy.innerHTML = 'PAUSE SOLVE';
  62. } else {
  63. solveCopy.innerHTML = 'SOLVE ALL';
  64. }
  65. solveCopy.disabled = false;
  66. pauseCopy.innerHTML = 'SOLVE';
  67.  
  68. const buttonStyle = `
  69. min-width: 150px;
  70. font-size: 17px;
  71. border:none;
  72. border-bottom: 4px solid #58a700;
  73. border-radius: 18px;
  74. padding: 13px 16px;
  75. transform: translateZ(0);
  76. transition: filter .2s;
  77. font-weight: 700;
  78. letter-spacing: .8px;
  79. background: #55CD2E;
  80. color:#fff;
  81. margin-left:20px;
  82. cursor:pointer;
  83. `;
  84.  
  85. solveCopy.style.cssText = buttonStyle;
  86. pauseCopy.style.cssText = buttonStyle;
  87.  
  88. //Hover effect for buttons
  89.  
  90. function mouseOver(x) {
  91. x.style.filter = "brightness(1.1)";
  92. }
  93.  
  94. function mouseLeave(x) {
  95. x.style.filter = "none";
  96. }
  97.  
  98. let buttons = [solveCopy, pauseCopy]
  99.  
  100. buttons.forEach(button => {
  101. button.addEventListener("mousemove", () => {
  102. mouseOver(button);
  103. });
  104. });
  105.  
  106. buttons.forEach(button => {
  107. button.addEventListener("mouseleave", () => {
  108. mouseLeave(button);
  109. });
  110. });
  111.  
  112.  
  113.  
  114. original.parentElement.appendChild(pauseCopy);
  115. original.parentElement.appendChild(solveCopy);
  116.  
  117.  
  118. solveCopy.addEventListener('click', solving);
  119. pauseCopy.addEventListener('click', solve);
  120. }
  121. }
  122.  
  123. setInterval(addButtons, 3000);
  124.  
  125. function solving() {
  126. if (intervalId) {
  127. pauseSolving();
  128. } else {
  129. startSolving();
  130. }
  131. }
  132.  
  133. function startSolving() {
  134. if (intervalId) {
  135. return;
  136. }
  137. document.getElementById("solveAllButton").innerText = "PAUSE SOLVE";
  138. isAutoMode = true;
  139. intervalId = setInterval(solve, 500);
  140. }
  141.  
  142. function pauseSolving() {
  143. if (!intervalId) {
  144. return;
  145. }
  146. document.getElementById("solveAllButton").innerText = "SOLVE ALL";
  147. isAutoMode = false;
  148. clearInterval(intervalId);
  149. intervalId = undefined;
  150. }
  151.  
  152. function solve() {
  153. let selAgain = document.querySelectorAll('[data-test="player-practice-again"]');
  154. if (selAgain.length === 1 && isAutoMode) {
  155. // Make sure it's the `practice again` button
  156. //if (selAgain[0].innerHTML.toLowerCase() === 'practice again') {
  157. // Click the `practice again` button
  158. selAgain[0].click();
  159. // Terminate
  160. return;
  161. //}
  162. }
  163. try {
  164. window.sol = FindReact(document.getElementsByClassName('_3FiYg')[0]).props.currentChallenge;
  165. } catch {
  166. let next = document.querySelector('[data-test="player-next"]');
  167. if (next) {
  168. next.click();
  169. }
  170. return;
  171. }
  172. if (!window.sol) {
  173. return;
  174. }
  175. let btn = null;
  176.  
  177. let selNext = document.querySelectorAll('[data-test="player-next"]');
  178.  
  179. if (selNext.length === 1) {
  180. // Save the button element
  181. btn = selNext[0];
  182. if(document.querySelectorAll('[data-test*="challenge-speak"]').length > 0){
  183. let buttonSkip = document.querySelector('button[data-test="player-skip"]');
  184. if(buttonSkip){
  185. buttonSkip.click();
  186. }
  187. }
  188.  
  189. if (document.querySelectorAll('[data-test="challenge-choice"]').length > 0) {
  190. if (window.sol.correctIndices) {
  191. window.sol.correctIndices?.forEach(index => {
  192. document.querySelectorAll('[data-test="challenge-choice"]')[index].children[0].click();
  193. });
  194. // Click the first element
  195. } else if (window.sol.articles) {
  196. var article = '';
  197. for (var i = 0; i < window.sol.articles.length; i++) {
  198. if (window.sol.correctSolutions[0].startsWith(window.sol.articles[i])) {
  199. Array.from(document.querySelectorAll('[data-test="challenge-choice"]'))
  200. .find((elm) =>
  201. elm.querySelector('[data-test="challenge-judge-text"]').innerText == window.sol.articles[i]
  202. ).click();
  203. article = window.sol.articles[i];
  204. break;
  205. }
  206. }
  207. let elm = document.querySelectorAll('[data-test="challenge-text-input"]')[0];
  208. let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
  209. nativeInputValueSetter.call(elm, window.sol.correctSolutions ? window.sol.correctSolutions[0].replace(article + ' ', '') : (window.sol.displayTokens ? window.sol.displayTokens.find(t => t.isBlank).text : window.sol.prompt));
  210. let inputEvent = new Event('input', {
  211. bubbles: true
  212. });
  213.  
  214. elm.dispatchEvent(inputEvent);
  215. } else {
  216. document.querySelectorAll('[data-test="challenge-choice"]')[window.sol.correctIndex].click();
  217. }
  218. // Click the solve button
  219. btn.click();
  220. }
  221.  
  222. if (document.querySelectorAll('[data-test="challenge-choice-card"]').length > 0) {
  223. // Click the first element
  224. if (window.sol.correctIndices) {
  225. window.sol.correctIndices?.forEach(index => {
  226. document.querySelectorAll('[data-test="challenge-choice-card"]')[index].children[0].click();
  227. });
  228. } else {
  229. document.querySelectorAll('[data-test="challenge-choice-card"]')[window.sol.correctIndex].click();
  230. }
  231. // Click the solve button
  232. btn.click();
  233. }
  234.  
  235. if (window.sol.type == 'listenMatch') {
  236. let nl = document.querySelectorAll('[data-test="challenge-tap-token"]');
  237. window.sol.pairs?.forEach((pair) => {
  238. for (let i = 0; i < nl.length; i++) {
  239. let nlInnerText;
  240. if (nl[i].querySelectorAll('[data-test="challenge-tap-token-text"]').length > 1) {
  241. nlInnerText = nl[i].querySelector('[data-test="challenge-tap-token-text"]').innerText.toLowerCase().trim();
  242. } else {
  243. nlInnerText = FindSubReact(nl[i]).text.toLowerCase().trim();
  244. }
  245. if (
  246. (
  247. nlInnerText == pair.learningWord.toLowerCase().trim() ||
  248. nlInnerText == pair.translation.toLowerCase().trim()
  249. ) &&
  250. !nl[i].disabled
  251. ) {
  252. nl[i].click();
  253. }
  254. }
  255. });
  256. }
  257.  
  258. if (window.sol.type == 'listenSpell') {
  259. let tokens = window.sol.displayTokens.filter(x => x.damageStart !== undefined);
  260. let elms = document.querySelectorAll('._2cjP3._2IKiF');
  261. let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
  262.  
  263. var solutionCharacters = [];
  264. for (let tok of tokens) {
  265. for (let i = tok.damageStart; i < tok.damageEnd; i++) {
  266. solutionCharacters.push(tok.text[i]);
  267. }
  268. }
  269.  
  270. for (var elmIndex = 0; elmIndex < elms.length; elmIndex++) {
  271. nativeInputValueSetter.call(elms[elmIndex], solutionCharacters[elmIndex]);
  272.  
  273. let inputEvent = new Event('input', {
  274. bubbles: true
  275. });
  276.  
  277. elms[elmIndex].dispatchEvent(inputEvent);
  278. }
  279. }
  280.  
  281. if (document.querySelectorAll('[data-test="challenge-tap-token"]').length > 0) {
  282. // Click the first element
  283. if (window.sol.pairs) {
  284. let nl = document.querySelectorAll('[data-test="challenge-tap-token"]');
  285. if (document.querySelectorAll('[data-test="challenge-tap-token-text"]').length == document.querySelectorAll('[data-test="challenge-tap-token"]').length) {
  286. window.sol.pairs?.forEach((pair) => {
  287. for (let i = 0; i < nl.length; i++) {
  288. const nlInnerText = nl[i].querySelector('[data-test="challenge-tap-token-text"]').innerText.toLowerCase().trim();
  289. if (
  290. (
  291. nlInnerText == pair.learningToken.toLowerCase().trim() ||
  292. nlInnerText == pair.fromToken.toLowerCase().trim()
  293. ) &&
  294. !nl[i].disabled
  295. ) {
  296. nl[i].click();
  297. }
  298. }
  299. });
  300. }
  301. } else if(!window.sol.correctTokens){
  302. let clicked = {}
  303. let nl = document.querySelectorAll('[data-test="challenge-tap-token"]');
  304. window.sol.correctIndices?.forEach(index => {
  305. let correctAnswer = window.sol.choices[index];
  306. for (let i = 0; i < nl.length; i++) {
  307. if ((nl[i].innerText).toLowerCase().trim() == correctAnswer.text.toLowerCase().trim() && !nl[i].disabled && !clicked[i]) {
  308. clicked[i] = 1;
  309. nl[i].click();
  310. break;
  311. }
  312. }
  313. });
  314. } else {
  315. let clicked = {}
  316. let nl = document.querySelectorAll('[data-test="challenge-tap-token"]');
  317. window.sol.correctIndices?.forEach(index => {
  318. let correctAnswer = window.sol.correctTokens[index];
  319. for (let i = 0; i < nl.length; i++) {
  320. if ((nl[i].innerText).toLowerCase().trim() == correctAnswer.toLowerCase().trim() && !nl[i].disabled && !clicked[i]) {
  321. clicked[i] = 1;
  322. nl[i].click();
  323. break;
  324. }
  325. }
  326. });
  327. }
  328. // Click the solve button
  329. btn.click();
  330. }
  331.  
  332. if (document.querySelectorAll('[data-test="challenge-text-input"]').length > 0) {
  333.  
  334. let elm = document.querySelectorAll('[data-test="challenge-text-input"]')[0];
  335. let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
  336. nativeInputValueSetter.call(elm, window.sol.correctSolutions ? window.sol.correctSolutions[0] : (window.sol.displayTokens ? window.sol.displayTokens.find(t => t.isBlank).text : window.sol.prompt));
  337. let inputEvent = new Event('input', {
  338. bubbles: true
  339. });
  340.  
  341. elm.dispatchEvent(inputEvent);
  342. }
  343.  
  344.  
  345. if (document.querySelectorAll('[data-test*="challenge-partialReverseTranslate"]').length > 0) {
  346. let elm = document.querySelector('[data-test*="challenge-partialReverseTranslate"]')?.querySelector("span[contenteditable]");
  347. let nativeInputNodeTextSetter = Object.getOwnPropertyDescriptor(Node.prototype, "textContent").set
  348. nativeInputNodeTextSetter.call(elm, '"' + window.sol?.displayTokens?.filter(t => t.isBlank)?.map(t=>t.text)?.join()?.replaceAll(',', '') + '"');
  349. let inputEvent = new Event('input', {
  350. bubbles: true
  351. });
  352.  
  353. elm.dispatchEvent(inputEvent);
  354. }
  355.  
  356. if (document.getElementsByTagName('textarea').length > 0) {
  357. let elm = document.getElementsByTagName('textarea')[0]
  358.  
  359. let nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype, "value").set;
  360. nativeInputValueSetter.call(elm, window.sol.correctSolutions ? window.sol.correctSolutions[0] : window.sol.prompt);
  361.  
  362. let inputEvent = new Event('input', {
  363. bubbles: true
  364. });
  365.  
  366. elm.dispatchEvent(inputEvent);
  367. }
  368.  
  369. // Continue
  370. btn.click();
  371. }
  372. }
  373.  
  374. function FindSubReact(dom, traverseUp = 0) {
  375. const key = Object.keys(dom).find(key => key.startsWith("__reactProps$"));
  376. return dom.parentElement[key].children.props;
  377. }
  378.  
  379. function FindReact(dom, traverseUp = 0) {
  380. const key = Object.keys(dom.parentElement).find(key => key.startsWith("__reactProps$"));
  381. return dom.parentElement[key].children[0]._owner.stateNode;
  382. }
  383.  
  384. window.findReact = FindReact;
  385.  
  386. window.ss = startSolving;

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址