Wordle regex solver by Sketch Engine

Helps you solve a Wordle puzzle by generating a regular expression. To look up possible solutions in a word list, Sketch Engine subscription is required (30-day free trial available, no card required).

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Wordle regex solver by Sketch Engine
// @namespace    https://www.sketchengine.eu/
// @version      0.9
// @description  Helps you solve a Wordle puzzle by generating a regular expression. To look up possible solutions in a word list, Sketch Engine subscription is required (30-day free trial available, no card required).
// @author       Marek Blahuš of Lexical Computing
// @match        https://www.nytimes.com/games/wordle/index.html
// @icon         https://www.nytimes.com/games/wordle/images/NYT-Wordle-Icon-32.png
// @grant        none
// ==/UserScript==

/* jshint esversion: 6 */

var board = document.getElementsByTagName('game-app')[0].shadowRoot.getElementById('board');
board.innerHTML += '<div style="text-align: center"><a href="#" id="wordle-regex-ske-link">need help?</a></div>';
board.getElementById('wordle-regex-ske-link').addEventListener('click', wordle_regex_ske);

function wordle_regex_ske(){
  var absents='', presents='', incorrects=Array(5).fill(''), corrects=Array(5).fill('.');
  for(var d of Array.from(Array(6), (_, i) => document.querySelectorAll('game-app')[0].boardState[i] ? Array.from(Array(5), (_, j) => [document.querySelectorAll('game-app')[0].boardState[i][j], document.querySelectorAll('game-app')[0].evaluations[i][j], j]) : []).flat()) {
    switch(d[1]) {
      case "absent": if(!absents.includes(d[0])) absents += d[0]; break;
      case "present": if(!corrects.includes(d[0])) { if(!presents.includes(d[0])) presents += d[0]; if(!incorrects[d[2]].includes(d[0])) incorrects[d[2]] += d[0]; } break;
      case "correct": corrects[d[2]] = d[0]; presents = presents.replace(d[0], ''); incorrects = incorrects.map((v) => v.replace(d[0], '')); break;
      }
  }
  var regex = (absents && corrects.includes('.') ? '(?!.*'+(absents.length>1?'['+absents+']':absents)+')' : '') + (presents.split('').map((v) => '(?=.*'+v+')').join('')) + (incorrects.map((v, i) => v ? '(?!'+'.'.repeat(i)+(v.length>1?'['+v+']':v)+')' : '').join('')) + (corrects.join(''));
  if(confirm('Your regex is:\n'+regex+'\nProceed to Sketch Engine to see a word list? (Login required, free trial available.)')) window.open('https://app.sketchengine.eu/#wordlist?corpname=preloaded%2Fcoca&tab=advanced&keyword='+encodeURIComponent(regex)+'&filter=regex&wlattr=lc&wlminfreq=0&showresults=1&cols=%5B%22frq%22%5D');
}