Wordle bookmarklet

Do you have trouble remembering words when playing Wordle. I wrote a bookmarklet that examines your guesses and displays a list of words that potentially match for your next guess.

The bookmarklet is at the end of this post. If you don’t know what a bookmarklet is you can use the link above to learn about them.

To use the bookmarklet, first drag it to your bookmark bar. Then, when playing wordle, after your guess, click on the bookmarklet. The bookmarklet will analyze the board and in the header portion of the Wordle page display a list of possible words. For example: here is the start of a game.

Here is the board after your first guess:

Now you can press the Wordle bookmarket and the board will change to:

Where the header was now is a list of possible words for your next guess. Assume you type “blaze” in for your next guess:

Press the bookmarklet again to generate a new list of possible solutions.

Guessing “opera” gives:

Below is the bookmarklet. Simply drag and drop it onto your bookmark bar in your browser. This has been tested on Chrome, Firefox, and Edge.

<- drag the button to your bookmark or favorites bar

Note that this bookmarklet does not look at any of your personal information. It only analyzes the guesses on the page. This comes without any warranty. Below is the listing of the code, without the actual list of dictionary words.

function cheatWordle()
{
var ele = document.querySelectorAll('[aria-label*="letter"]') 
var absent = "";
var correct = ".....".split('');
var present = "";
var wrongloc = "     ".split('');
var l = 30;
for (var i=0;i<l;i++)
{ 
 var lab = ele[i].getAttribute("aria-label").split(/, /)

  if (lab.length == 3)
  {
    var lett = lab[1].toLowerCase();
    var j = lab[0][0]-1;
    if (lab[2].match(/present/)) 
      { present += lab[1].toLowerCase();  wrongloc[j] += lab[1].toLowerCase();  }
    // if absent add letter to absent list if not already there
    else if (lab[2].match(/absent/) && present.indexOf(lett) < 0 && absent.indexOf(lett) < 0) 
      { absent += lab[1].toLowerCase(); }
    else if (lab[2].match(/correct/)) 
      {  correct[j] = lab[1].toLowerCase(); }
  }
 }
correct.join('');
for (i in wrongloc) { if (wrongloc[i] == " ")
{
    wrongloc[i] = "."
  }
  else
  {
    wrongloc[i] = "[^"+wrongloc[i]+"]"
  }
}
var it = ["aahed", ....]; 
// The list of words is not included in this example. If you want to use 
// this code you will need to replace the above line with an array of 
// words

// remove words containing absent letters
var re = new RegExp("[^"+absent+"][^"+absent+"][^"+absent+"][^"+absent+"][^"+absent+"]");
var result = it.filter(function(word){ return re.test(word); })

// remove words not containing a present letter

re = new RegExp("["+present+"]");
present.split('').forEach(function(l){ var tmp = [...result]; re=new RegExp(l); result=tmp.filter(function(word){return re.test(word)}) })


// remove words with letter in wrong location
re = new RegExp(wrongloc.join(''));
var tmp = result.filter(function(word) { return re.test(word); })

// remove words that don't have letter in correct location
re = new RegExp(correct.join(''));
var result = tmp.filter(function(word){ return re.test(word);})

// display results
var main = document.querySelector("header")
if (document.contains(document.getElementById("wordleanswer"))) {
document.getElementById("wordleanswer").remove();
} else {  

// Create a new div element
const newDiv = document.createElement("div");

// Set the ID of the new div
newDiv.id = "wordleanswer";
newDiv.style.width = "600px";

// Append the new div to the parent element
main.innerHTML="";
main.appendChild(newDiv);
document.getElementById("wordleanswer").setAttribute("style","height:100%;background-color:white;overflow:auto;")
document.getElementById("wordleanswer").append(result.sort().join(", "))
}
// remove words containing absent letters
var re = new RegExp("[^"+absent+"][^"+absent+"][^"+absent+"][^"+absent+"][^"+absent+"]");
var result = it.filter(function(word){ return re.test(word); })

// remove words not containing a present letter

re = new RegExp("["+present+"]");
present.split('').forEach(function(l){ var tmp = [...result]; re=new RegExp(l); result=tmp.filter(function(word){return re.test(word)}) })


// remove words with letter in wrong location
re = new RegExp(wrongloc.join('').replace(/\s/g,''));
console.log(re);
var tmp = result.filter(function(word) { return re.test(word); })

// remove words that don't have letter in correct location
re = new RegExp(correct.join(''));
var result = tmp.filter(function(word){ return re.test(word);})

// display results
var main = document.querySelector("header")
if (document.contains(document.getElementById("wordleanswer"))) {
document.getElementById("wordleanswer").remove();
}  

// Create a new div element
const newDiv = document.createElement("div");

// Set the ID of the new div
newDiv.id = "wordleanswer";
newDiv.style.width = "600px";

// Append the new div to the parent element
main.innerHTML="";
main.appendChild(newDiv);
document.getElementById("wordleanswer").setAttribute("style","height:100%;background-color:white;overflow:auto;")
document.getElementById("wordleanswer").append(result.sort().join(", "))

return;
}
cheatWordle();

Leave a Reply

Your email address will not be published. Required fields are marked *