🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Crossword Labs Solver

Automatically types the answer into crossword labs upon loading into a crossword page

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         Crossword Labs Solver
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  Automatically types the answer into crossword labs upon loading into a crossword page
// @author       You
// @match        https://crosswordlabs.com/view/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=crosswordlabs.com
// @grant        none
// @license      MIT
// @run-at       document-end
// ==/UserScript==
async function solveCrossword() {
    const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
    let extractedGrid = [];

    try {
        const scriptElements = document.querySelectorAll('script');
        let dataString = null;
        const startMarker = 'var grid = ';
        const endMarker = ']]';
        for (const script of scriptElements) {if (script.textContent.includes(startMarker)) {dataString = script.textContent; break;}}
        if (!dataString) return;
        const start = dataString.indexOf(startMarker) + startMarker.length;
        const end = dataString.indexOf(endMarker, start);
        if (start === -1 || end === -1 || end < start) return;
        let jsonString = dataString.substring(start, end + 2).trim().replace(/;$/, '');
        extractedGrid = JSON.parse(jsonString);
    } catch (e) {return;}

    if (!Array.isArray(extractedGrid) || extractedGrid.length === 0) return;

    let lettersFilled = 0;
    let errors = 0;

    for (let r = 0; r < extractedGrid.length; r++) {
        const rowData = extractedGrid[r];
        if (!Array.isArray(rowData)) continue;
        for (let c = 0; c < rowData.length; c++) {
            const cellObject = rowData[c];
            if (!cellObject || !cellObject.char) continue;
            const letter = String(cellObject.char || '').toUpperCase();
            if (letter.length === 0) continue;
            const groupId = `cx-${r}-${c}`;
            const groupElement = document.getElementById(groupId);
            if (groupElement) {
                try {groupElement.dispatchEvent(new MouseEvent('click', {bubbles: true, cancelable: true}));} catch (e) {groupElement.click();}
                const key = letter.charAt(0);
                const keyDownEvent = new KeyboardEvent('keydown', {key: key, keyCode: key.charCodeAt(0), bubbles: true, cancelable: true});
                document.dispatchEvent(keyDownEvent);
                const keyUpEvent = new KeyboardEvent('keyup', {key: key, keyCode: key.charCodeAt(0), bubbles: true, cancelable: true});
                document.dispatchEvent(keyUpEvent);
                const textElement = groupElement.querySelector('text.cx-a');
                if (textElement) {if (textElement.textContent !== key) {textElement.textContent = key;} lettersFilled++;} else {errors++;}
                await sleep(50);
            } else {errors++;}
        }
    }
}
solveCrossword();