Vocabulary.com Answer Bot

The more questions you answer the smarter it will get. Features: spelling-assistance & auto - complete, definitions and examples, actively learning bot.

安装此脚本
作者推荐脚本

您可能也喜欢Quillbot Premium Unlocker

安装此脚本
  1. // ==UserScript==
  2. // @name Vocabulary.com Answer Bot
  3. // @namespace http://tampermonkey.net/
  4. // @version 3.01
  5. // @description The more questions you answer the smarter it will get. Features: spelling-assistance & auto - complete, definitions and examples, actively learning bot.
  6. // @author longkidkoolstar
  7. // @match https://www.vocabulary.com/*
  8. // @icon https://cdn1.iconfinder.com/data/icons/network-and-comminications-flat-square-rounded-sha/120/content__blog__media__articles__news__management__edit-512.png
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. let url = window.location.href,list=url.split("/")[4],words_defs,lists,learned=[],incorrect=[],inProgress=false;
  14. if(localStorage.getItem("lists")!==null){lists = JSON.parse(localStorage.getItem("lists"))}
  15. else{lists = []}if(localStorage.getItem("words&defs")!==null){words_defs = JSON.parse(localStorage.getItem("words&defs"))}
  16. else{words_defs = []}if(localStorage.getItem("learned")!==null){learned = JSON.parse(localStorage.getItem("learned"))}
  17. if(localStorage.getItem("wrong")!==null){incorrect = JSON.parse(localStorage.getItem("wrong"))}
  18. let dictionary = "https://api.dictionaryapi.dev/api/v2/entries/en/";
  19.  
  20. //console.log(list,lists,partsOfList(list,"words"),partsOfList(list,"defs"))
  21.  
  22. if(!url.includes("/practice")){
  23. setInterval(function(){
  24. if(document.getElementsByClassName("activity practice")[0]!==undefined){
  25. let practice = document.getElementsByClassName("activity practice")[0];
  26. if(!lists.includes(list)){
  27. practice.addEventListener("click",function(){
  28. let enteries = document.getElementsByClassName("entry");
  29. for(let i=0;i<enteries.length;i++){
  30. let word = enteries[i].children[0].innerText.trim();
  31. let def = enteries[i].children[1].innerText.trim();
  32. words_defs.push({"word":word,"def":def,"list":list});
  33. if(enteries.length-1==i){
  34. localStorage.setItem("words&defs",JSON.stringify(words_defs));
  35. lists.push(list);
  36. localStorage.setItem("lists",JSON.stringify(lists));
  37. }
  38. }
  39. })
  40. }
  41. if(list.trim().length>0){
  42. practice.click();
  43. }
  44. }
  45. },1000)
  46. }
  47. else if(url.includes("/practice")){
  48. setTimeout(function(){
  49. if(!lists.includes(list)){
  50. location.href=url.split("/practice")[0];
  51. }
  52. else{
  53. bot()
  54. }
  55. },250)
  56. }
  57.  
  58. if(url.includes("/play/")){
  59. bot();
  60. }
  61.  
  62. function bot(){
  63. let bot = setInterval(function(){
  64. if(document.getElementsByClassName("challenge-history")[0].children[1].children!==undefined&&inProgress!==true){
  65. let arr = document.getElementsByClassName("challenge-history")[0].children[1].children;
  66. let currQuest = getQuest(arr);
  67. if(currQuest!==false){
  68. let questIndx = Number(currQuest.innerText-1)
  69. let questBox = document.getElementsByClassName("question")[questIndx];
  70. let quest_Type = questType(questBox);
  71. let nxt = document.getElementsByClassName("next")[0];
  72. if(quest_Type!==false){
  73. inProgress = true;
  74. if(quest_Type=="spell"){
  75. answerSpelling(questBox,questIndx);
  76. }
  77. if(quest_Type=="choice1"){
  78. answerMultChoice(questBox);
  79. }
  80. if(quest_Type=="choice2"){
  81. answerMultChoice(questBox,2);
  82. }
  83. }
  84. else{
  85. console.log("Question type doesn't exist 🤨");
  86. inProgress=false;
  87. }
  88. nxt.addEventListener("click",function(){
  89. inProgress=false;
  90. //console.log("inProgress = false!")
  91. })
  92. }
  93. }
  94. },500)
  95. }
  96.  
  97. setInterval(()=>{
  98. makeRoom();
  99. if(document.getElementsByClassName("next active")[0]!==undefined){
  100. document.getElementsByClassName("next active")[0].click();
  101. }
  102. },250)
  103.  
  104. function makeRoom(){
  105. if(document.getElementsByClassName("vcom-challenge resizable large started")[0]!==undefined){
  106. document.getElementsByClassName("vcom-challenge resizable large started")[0].style.minHeight="2500px";
  107. }
  108. }
  109.  
  110. function questType(quest){
  111. let type=false;
  112. let children = quest.children;
  113. for(let i=0;i<children.length;i++){
  114. if(children[i].className=="spelltheword"){
  115. type = "spell"
  116. }
  117. if(children[i].className=="choices"){
  118. if(children[1].childElementCount>0){
  119. type= "choice1";
  120. }
  121. else if(children[1].childElementCount==0){
  122. type="choice2";
  123. }
  124. }
  125. }
  126. console.log(type)
  127. return type;
  128. }
  129.  
  130. function getQuest(arr){
  131. let result=false;
  132. for(let i=0;i<arr.length;i++){
  133. if(arr[i].classList[0]=="enabled"&&arr[i].classList[1]=="selected"&&arr[i].classList.value=="enabled selected"){
  134. result = arr[i];
  135. }
  136. }
  137. return result;
  138. }
  139.  
  140.  
  141. function partsOfList(listId,part){
  142. let words = [];
  143. let defs = [];
  144. let examples = [];
  145. for(let i=0;i<words_defs.length;i++){
  146. if(words_defs[i].list==listId){
  147. if(!words.includes(words_defs[i].word)){
  148. words.push(words_defs[i].word)
  149. }
  150. defs.push(words_defs[i].def);
  151. if(!examples.includes(words_defs[i].example)){
  152. examples.push(words_defs[i].example)
  153. }
  154. }
  155. if(words_defs.length-1==i){
  156. if(part=="words"){
  157. return words;
  158. }
  159. if(part=="defs"){
  160. return defs;
  161. }
  162. if(part=="examples"){
  163. return examples;
  164. }
  165. }
  166. }
  167. }
  168.  
  169. function getChoices(arr){
  170. let temp=[];
  171. for(let i=0;i<arr.length;i++){
  172. temp.push(arr[i].innerText);
  173. }
  174. return temp;
  175. }
  176.  
  177. function learn(word,choice,def){
  178. let present=false;
  179. for(let i=0;i<learned.length;i++){
  180. if(learned[i].word==word&&learned[i].choice==choice){
  181. present=true;
  182. console.log(`${word} is known 💡`)
  183. }
  184. }
  185. if(!present){
  186. learned.push({"word":word,"choice":choice});
  187. if(choice.split(" ").length==1){
  188. learned.push({"word":choice,"choice":def});
  189. }
  190. localStorage.setItem("learned",JSON.stringify(learned))
  191. console.log(`Learned ${word} 🧠`)
  192. }
  193. inProgress=false;
  194. }
  195.  
  196. function getDef(word){
  197. let def = false;
  198. let words = partsOfList(list,"words");
  199. let defs = partsOfList(list,"defs");
  200. for(let i=0;i<words.length;i++){
  201. if(words[i].includes(word)||word.includes(words[i])){
  202. def = defs[i];
  203. }
  204. }
  205. return def;
  206. }
  207.  
  208. function defineChoices(word,arr){
  209. for(let i=0;i<arr.length;i++){
  210. if(arr[i].innerText.split(" ").length==1){
  211. let def = getDef(arr[i].innerText);
  212. if(def!==false){
  213. arr[i].innerText += `: ${getDef(arr[i].innerText)} - (answer?)`;
  214. arr[i].style.color = "orange";
  215. arr[i].innerText+=" 🧠"
  216. clean(word,arr)
  217. }
  218. }
  219. }
  220. }
  221.  
  222. function answerMultChoice(questBox,clause){
  223. let word,choiceBox,choices;
  224. if(clause==2){
  225. let chil = questBox.children[2].children;
  226. if(chil.length>1){
  227. for(let i=0;i<chil.length;i++){
  228. if(chil[i].tagName=="STRONG"){
  229. word = chil[i].innerText
  230. }
  231. }
  232. }
  233. else{
  234. word = questBox.children[2].children[0].innerText;
  235. }
  236. }
  237. else if(clause==undefined){
  238. word = questBox.children[1].children[0].children[0].innerText;
  239. }
  240. choiceBox = questBox.children[3].children;
  241. choices = getChoices(choiceBox);
  242. defineChoices(word,choiceBox)
  243. let instruct = questBox.children[2];
  244. let words = partsOfList(list,"words");
  245. let defs = partsOfList(list,"defs");
  246. let def=false;
  247. deepSearch(word,questBox);
  248. //deepDef(word,choices,choiceBox);
  249. def = getDef(word);
  250. defAllChoices(choices,choiceBox,def)
  251. maybe(choices,choiceBox)
  252. if(def!==false){
  253. let answr = false;
  254. for(let i=0;i<choices.length;i++){
  255. if(choices[i].includes(def)||def.includes(choices[i])){
  256. answr = i;
  257. }
  258. }
  259. if(answr!==false){
  260. choiceBox[answr].style.color="springgreen";
  261. choiceBox[answr].innerText+=" 🧠"
  262. clean(word,choiceBox)
  263. }
  264. else{
  265. answr=false;
  266. if(learned.length>0){
  267. for(let i=0;i<learned.length;i++){
  268. for(let j=0;j<choiceBox.length;j++){
  269. if(learned[i].word.includes(word)||choiceBox[j].innerText.includes(learned[i].choice)||learned[i].choice.includes(choiceBox[j].innerText)||word.includes(learned[i].word)){
  270. answr = learned[i].choice;
  271. }
  272. }
  273. }
  274. }
  275. if(answr!==false){
  276. for(let i=0;i<choices.length;i++){
  277. if(choices[i].includes(answr)||answr.includes(choices[i])){
  278. choiceBox[i].style.color="springgreen";
  279. choiceBox[i].innerText+=" 🧠"
  280. clean(word,choiceBox)
  281. }
  282. }
  283. }
  284. else{
  285. //console.log("No answer found - normal way");
  286. }
  287. }
  288. }
  289. for(let i=0;i<choiceBox.length;i++){
  290. choiceBox[i].addEventListener("click",function(){
  291. setTimeout(function(){
  292. grabChoice(word,choiceBox,def);
  293. },250)
  294. })
  295. }
  296. }
  297.  
  298.  
  299. function grabChoice(word,choices,def){
  300. let correct = false;
  301. for(let i=0;i<choices.length;i++){
  302. if(choices[i].className=="correct"){
  303. learn(word,choices[i].innerText,def);
  304. correct = true;
  305. }
  306. if(correct){
  307. if(choices[i].className!=="correct"){
  308. wrong(word,choices[i].innerText)
  309. }
  310. }
  311. else{
  312. if(choices[i].className=="incorrect"){
  313. wrong(word,choices[i].innerText);
  314. }
  315. }
  316. }
  317. }
  318.  
  319.  
  320. function clean(word,choices){
  321. for(let j=0;j<choices.length;j++){
  322. for(let i=0;i<incorrect.length;i++){
  323. if(incorrect[i].word==word&&incorrect[i].choice==choices[j].innerText){
  324. choices[j].style.color="red";
  325. }
  326. }
  327. }
  328. }
  329.  
  330. function wrong(word,choice){
  331. let present=false;
  332. for(let i=0;i<incorrect.length;i++){
  333. if(incorrect[i].word==word&&incorrect[i].choice==choice){
  334. present=true;
  335. console.log(`${word}'s choice is known as incorrect ❌`);
  336. }
  337. }
  338. if(!present){
  339. incorrect.push({"word":word,"choice":choice});
  340. localStorage.setItem("wrong",JSON.stringify(incorrect))
  341. console.log(`Learned ${word}'s incorrect choice 🧠`)
  342. }
  343. inProgress=false;
  344. }
  345.  
  346. async function deepSearch(word,questBox){
  347. try{
  348. let api=`https://vocabulary.now.sh/words/${word}`;
  349. let api2=`https://vocabulary.now.sh/word/${word}`;
  350. let result=await fetch(api).then(data => data.json()).then(data => data.data[0]);
  351. let example=await fetch(api2).then(data => data.json()).then(data => data.data);
  352. let def = await result.description;
  353. let choiceBox = questBox.children[3].children;
  354. let choices = getChoices(questBox.children[3].children);
  355. let instruct = questBox.children[2];
  356. let content = questBox.children[1];
  357. let answr=false;
  358. for(let i=0;i<choices.length;i++){
  359. if(choices[i].includes(example)||choices[i].includes(def)||def.includes(choices[i])||example.includes(choices[i])){
  360. answr=i;
  361. }
  362. }
  363. if(answr!==false){
  364. choiceBox[answr].style.color="springgreen";
  365. choiceBox[answr].innerText+=" 🧠"
  366. }
  367. else{
  368. //console.log("DeepSearch failed. Will add correct answer to dataSet when answered. 🤔");
  369. }
  370. if(getDef(word)!==false){
  371. let set = false;
  372. let rep = false;
  373. if(content.children.length>0){
  374. rep = content;
  375. }
  376. if(instruct.children.length>0){
  377. rep = instruct;
  378. }
  379. if(rep!==false){
  380. if(!set){
  381. set = true;
  382. rep.style.overflowY="auto";
  383. rep.style.height="fit-content";
  384. rep.innerHTML+=`<hr><div style="margin-top:50px;"><b style="color:black;">${word}</b> means: ${getDef(word)} 🧠 <br><br> <span style="font-size:18px; margin-bottom:10px;"><b style="color:black;">Example:</b> ${example}</span></div><br>`;
  385. questBox.style.marginTop="-45px";
  386.  
  387. }
  388. }
  389. }
  390. for(let i=0;i<choices.length;i++){
  391. if(similarity(choices[i],def)||similarity(choices[i],example)/*||similar(def,choices[i])||similar(example,choices[i])*/){
  392. choiceBox[i].style.color="springgreen";
  393. choiceBox[i].innerText+=" 🧠"
  394. }
  395. }
  396. }
  397. catch(e){
  398. return false;
  399. }
  400. }
  401.  
  402. function maybe(choices,choiceBox){
  403. for(let i=0;i<choices.length;i++){
  404. for(let j=0;j<learned.length;j++){
  405. if(choices[i].toLowerCase().includes(learned[j].word.toLowerCase())||learned[j].word.toLowerCase().includes(choices[i].toLowerCase())){
  406. if(!choiceBox[i].innerText.includes(" - maybe this...")){
  407. choiceBox[i].innerText+=" - maybe this...";
  408. choiceBox[i].style.color="orange";
  409. }
  410. }
  411. }
  412. }
  413. }
  414.  
  415. function cleanUp(choices){
  416. for(let i=0;i<choices.length;i++){
  417. choices[i].style.color="#36588e";
  418. }
  419. }
  420.  
  421. function answerSpelling(questBox,indx){
  422. let inp = questBox.children[1].children[1].children[1];
  423. let submit = questBox.children[1].children[2].children[0];
  424. let surrender = questBox.children[1].children[2].children[1];
  425. let status = document.getElementsByClassName("status")[indx];
  426. let speak = questBox.children[1].children[1].children[0];
  427. let label = questBox.children[1].children[0];
  428. let words = partsOfList(list,"words");
  429. speak.click();
  430. function auto(matches){
  431. inp.value=matches[0];
  432. inp.blur();
  433. setTimeout(function(){
  434. submit.click();
  435. inProgress = false;
  436. },350)
  437. }
  438. inp.addEventListener("keyup",function(evt){
  439. if(inp.value.trim().length>0){
  440. label.innerText = "Spell the word:";
  441. let input = inp.value;
  442. let matches=[];
  443. for(let i=0;i<words.length;i++){
  444. if(words[i].toLowerCase().includes(input.toLowerCase())||input.toLowerCase().includes(words[i].toLowerCase())){
  445. matches.push(words[i]);
  446. }
  447. }
  448. if(matches.length>0){
  449. label.innerText = "Matches 😉:"
  450. let newLabel = document.createElement("div");
  451. label.append(newLabel);
  452. let max = 5;
  453. if(matches.length<5){
  454. max = matches.length;
  455. }
  456. for(let i=0;i<max;i++){
  457. newLabel.style="width:100%;height:fit-content;display:flex;align-items:center;justify-content:center;flex-direction:row;overflow:hidden;"
  458. newLabel.innerHTML+=` <p style="cursor:pointer;margin:5px;" class = "spellGuess">${matches[i]}</p>`;
  459. let guesses = document.getElementsByClassName("spellGuess");
  460. for(let i=0;i<guesses.length;i++){
  461. guesses[i].addEventListener("click",()=>{
  462. inp.value = guesses[i].innerText;
  463. setTimeout(()=>{
  464. submit.click();
  465. inProgress = false;
  466. },350)
  467. })
  468. }
  469. }
  470. if(matches.length==1){
  471. let auto_do = true;
  472. if(status.children.length>0){
  473. if(status.children[0].innerText.includes("again")){
  474. auto_do = false;
  475. }
  476. }
  477. if(auto_do){
  478. auto(matches);
  479. }
  480. }
  481. }
  482. else{
  483. label.innerText = "No matches 😟";
  484. }
  485. }
  486. else{
  487. label.innerText = "Spell the word:";
  488. }
  489. })
  490. inp.addEventListener("keydown",function(evt){
  491. if(evt.keyCode==13){
  492. if(inp.value.trim().length>0){
  493. inProgress=false;
  494. }
  495. }
  496. })
  497. submit.addEventListener("click",function(){
  498. inProgress=false;
  499. })
  500. }
  501.  
  502.  
  503.  
  504. function similarity(s1, s2) {
  505. var longer = s1;
  506. var shorter = s2;
  507. if (s1.length < s2.length) {
  508. longer = s2;
  509. shorter = s1;
  510. }
  511. var longerLength = longer.length;
  512. if (longerLength == 0) {
  513. return 1.0;
  514. }
  515. if((longerLength - editDistance(longer, shorter)) / parseFloat(longerLength)>0.5){
  516. return true;
  517. }
  518. }
  519. function editDistance(s1, s2) {
  520. s1 = s1.toLowerCase();
  521. s2 = s2.toLowerCase();
  522.  
  523. var costs = new Array();
  524. for (var i = 0; i <= s1.length; i++) {
  525. var lastValue = i;
  526. for (var j = 0; j <= s2.length; j++) {
  527. if (i == 0)
  528. costs[j] = j;
  529. else {
  530. if (j > 0) {
  531. var newValue = costs[j - 1];
  532. if (s1.charAt(i - 1) != s2.charAt(j - 1))
  533. newValue = Math.min(Math.min(newValue, lastValue),
  534. costs[j]) + 1;
  535. costs[j - 1] = lastValue;
  536. lastValue = newValue;
  537. }
  538. }
  539. }
  540. if (i > 0)
  541. costs[s2.length] = lastValue;
  542. }
  543. return costs[s2.length];
  544. }
  545.  
  546. function similar(phrase,choice){
  547. let simScore1 = 0;
  548. let simScore2 = 0;
  549. phrase = cleanPunc(phrase).split(" ");
  550. choice = cleanPunc(choice).split(" ");
  551. for(let i=0;i<phrase.length;i++){
  552. for(let j=0;j<choice.length;j++){
  553. if(phrase[i].includes(choice[j])||choice[j].includes(phrase[i])){
  554. return true;
  555. }
  556. }
  557. }
  558. return false;
  559. }
  560.  
  561. function cleanPunc(string){
  562. return string.replace(/[^A-Za-z0-9\s]/g,"").replace(/\s{2,}/g, " ");
  563. }
  564.  
  565. /*
  566. async function deepDef(word,choices,choiceBox){
  567. try{
  568. let api = dictionary+word;
  569. let dets = await fetch(api).then(data => data.json()).then(data=>data[0].meanings[0].definitions[0]);
  570. let synms = dets.synonyms;
  571. let antms = dets.antonyms;
  572. let def = dets.definition;
  573. for(let i=0;i<choices.length;i++){
  574. for(let j=0;j<synms.length;j++){
  575. if(choices[i].includes(synms[j])||synms[j].includes(choices[i])){
  576. choiceBox[i].style.color="springgreen";
  577. choiceBox[i].innerText+=" 🧠"
  578. }
  579. }
  580. }
  581. }
  582. catch(error){
  583. console.log("Can't find synonyms for this one. Not a big problem, I have other ways of dealing with this 😊")
  584. }
  585. }
  586. */
  587.  
  588. async function defAllChoices(choices,choiceBox,def){
  589. for(let i=0;i<choices.length;i++){
  590. if(choices[i].split(" ").length==1){
  591. let api = dictionary+choices[i];
  592. let defs = await fetch(api).then(data => data.json()).then(data=>data[0].meanings[0].definitions);
  593. let temp=[];
  594. for(let j=0;j<defs.length;j++){
  595. if(defs[j]!==undefined){
  596. temp.push(defs[j].definition);
  597. }
  598. }
  599. for(let x=0;x<temp.length;x++){
  600. choiceBox[i].innerText+=` - ${temp[x]}`;
  601. }
  602. }
  603. }
  604. }
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.