// ==UserScript== // @name 每日杀手数独自动高亮 // @version 0.1.0 // @description Daily killer Sudoku AutoHighlight // @author DreamNya // @match https://www.dailykillersudoku.com/puzzle/* // @grant none // @license MIT // @run-at document-end // @namespace https://greasyfork.org/users/809466 // ==/UserScript== const getKey = function (key, defaultValue) { const value = JSON.parse(localStorage.getItem('AutoHighlight-' + key)); return value ?? defaultValue; }; const setKey = function (key, value) { localStorage.setItem('AutoHighlight-' + key, JSON.stringify(value)); return value; }; const AutoHighlight = {}; window.AutoHighlight = AutoHighlight; const config = {}; AutoHighlight.config = config; config.num = getKey('num', true); config.subnum = getKey('subnum', true); AutoHighlight.num = 0; AutoHighlight.reset = function () { AutoHighlight.highlight(0); }; AutoHighlight.toggleConfig = function (item, element) { config[item] = setKey(item, !config[item]); $(element).attr('data-icon', config[item] ? 'toggle-on' : 'toggle-off'); }; AutoHighlight.highlight = function (num) { DKS.puzzle.board.clearHighlightedCells(); if (AutoHighlight.num == num) { num = 0; } AutoHighlight.num = num; if (num == 0) { return; } const boardCells = DKS.puzzle.board._cells.flat(); const cells = boardCells.reduce((arr, cell) => { let flag = false; if (config.num) { if (cell.value == num) { flag = true; } } if (!flag && config.subnum) { if (cell.pencilMarks.includes(num)) { flag = true; } } if (flag) { arr.push(cell); } return arr; }, []); DKS.puzzle.board.highlightedCells.push(...cells); DKS.puzzle.board._drawHighlightedCells(); }; const off = 'M384 64H192C85.961 64 0 149.961 0 256s85.961 192 192 192h192c106.039 0 192-85.961 192-192S490.039 64 384 64zM64 256c0-70.741 57.249-128 128-128 70.741 0 128 57.249 128 128 0 70.741-57.249 128-128 128-70.741 0-128-57.249-128-128zm320 128h-48.905c65.217-72.858 65.236-183.12 0-256H384c70.741 0 128 57.249 128 128 0 70.74-57.249 128-128 128z'; const on = 'M384 64H192C86 64 0 150 0 256s86 192 192 192h192c106 0 192-86 192-192S490 64 384 64zm0 320c-70.8 0-128-57.3-128-128 0-70.8 57.3-128 128-128 70.8 0 128 57.3 128 128 0 70.8-57.3 128-128 128z'; $(document.body).append( `
Reset

AutoHighlight - 自动高亮

实数
候选数
${Array(9) .fill() .reduce((str, _, index) => { str += `
${index + 1}
`; return str; }, '')}
` ); $('#AutoHighlight').on('click mousedown', (e) => { e.stopPropagation(); }); $(document).on('mousedown', (e) => { if (DKS.puzzle.board.highlightedCells.length == 0) { AutoHighlight.num = 0; } });