Suppenbiatch

WordleShare

Jan 27th, 2022
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         WordleShare
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  extract wordle bitmap
  6. // @author       Suppenbiatch
  7. // @match        https://www.powerlanguage.co.uk/wordle/
  8. // @icon         https://www.powerlanguage.co.uk/wordle/images/wordle_logo_192x192.png
  9. // @run-at       document-idle
  10. // @grant        none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.     'use strict';
  15.  
  16.     var result = []
  17.     var row = []
  18.  
  19.     function parse_rows (ele, idx, arr) {
  20.         var items = ele.shadowRoot.querySelectorAll('game-tile')
  21.         row = []
  22.         items.forEach(parse_items)
  23.         result.push(row)
  24.     }
  25.  
  26.     function parse_items(ele, idx, arr) {
  27.         try {
  28.             var evaluation = ele.attributes.evaluation.value
  29.         } catch (e) {
  30.             if (e instanceof TypeError) {
  31.                 row.push(0)
  32.                 return;
  33.             }
  34.             console.log(e)
  35.         }
  36.         if (evaluation === 'absent') {
  37.             row.push(0)
  38.         } else if (evaluation === 'present') {
  39.             row.push(1)
  40.         } else if (evaluation === 'correct') {
  41.             row.push(2)
  42.         }
  43.         return;
  44.     }
  45.  
  46.     function createBitmap() {
  47.         result = []
  48.         const rows = document.querySelector('game-app').shadowRoot.querySelectorAll('game-row');
  49.         rows.forEach(parse_rows)
  50.         console.log(result)
  51.         const output = '!wordle ' + btoa(JSON.stringify(result))
  52.         navigator.clipboard.writeText(output).then(function() {
  53.             return;
  54.           }, function(err) {
  55.             console.error(err);
  56.           })
  57.     }
  58.  
  59.  
  60.     function addButton(text, onclick, cssObj, parentElement) {
  61.         cssObj = cssObj || {color: '#e8e6e3', 'background-color': '#181a1b', 'z-index': 1}
  62.         parentElement = parentElement || document.body
  63.         let button = document.createElement('button'), btnStyle = button.style
  64.         parentElement.appendChild(button)
  65.         button.innerHTML = text
  66.         button.onclick = onclick
  67.         Object.keys(cssObj).forEach(key => btnStyle[key] = cssObj[key])
  68.         return button
  69.     }
  70.  
  71.     function add_button_element() {
  72.         var buttonList = document.createElement('ul');
  73.         buttonList.setAttribute('id', 'button-header');
  74.         buttonList.style.listStyleType = 'none'
  75.         buttonList.style.margin = '4%';
  76.         buttonList.style.padding = '2px';
  77.         buttonList.style.textAlign = 'center';
  78.         buttonList.style.position = 'fixed';
  79.         buttonList.style.bottom = '7%';
  80.         buttonList.style.left = '10%';
  81.         buttonList.style.zIndex = '10';
  82.         document.body.appendChild(buttonList);
  83.  
  84.         var button = document.createElement('li');
  85.         window.addEventListener('load', () => {
  86.             addButton('Create BitMap', createBitmap, null, button)
  87.         })
  88.         buttonList.appendChild(button);
  89.     }
  90.  
  91.     add_button_element()
  92.  
  93.     // Your code here...
  94. })();
Add Comment
Please, Sign In to add comment