Skip to content

Instantly share code, notes, and snippets.

@Mativve
Created April 1, 2026 20:11
Show Gist options
  • Select an option

  • Save Mativve/5251ca834d659491164c4c02830e2c79 to your computer and use it in GitHub Desktop.

Select an option

Save Mativve/5251ca834d659491164c4c02830e2c79 to your computer and use it in GitHub Desktop.
Skrypt zamienia kolory planszy według podanego schematu
// ==UserScript==
// @name KurnikStyle
// @namespace http://tampermonkey.net/
// @version 2026-04-01
// @description
// @author Mativve
// @match https://www.kurnik.pl/*/
// @icon https://www.google.com/s2/favicons?sz=64&domain=kurnik.pl
// @grant none
// ==/UserScript==
(function() {
'use strict';
let canvas = document.querySelector('canvas.noth');
function init(){
const colorMap = [
{ from: '#287840', to: '#402878', tol: 10 },
{ from: '#ffffff', to: '#ebe4d2', tol: 10 },
{ from: '#000000', to: '#FFFFFF', tol: 10 },
{ from: '#dc0000', to: '#3c8cff', tol: 10 },
{ from: '#4488cc', to: '#00FF00', tol: 10 },
].map(rule => ({
from: hexToRgb(rule.from),
to: hexToRgb(rule.to),
tol: rule.tol
}));
function hexToRgb(hex) {
hex = hex.replace('#', '').trim();
if (hex.length === 3) {
hex = hex.split('').map(ch => ch + ch).join('');
}
const num = parseInt(hex, 16);
return [
(num >> 16) & 255,
(num >> 8) & 255,
num & 255
];
}
function near(r, g, b, target, tol) {
return Math.abs(r - target[0]) <= tol &&
Math.abs(g - target[1]) <= tol &&
Math.abs(b - target[2]) <= tol;
}
function remapCanvas(ctx, x = 0, y = 0, w = ctx.canvas.width, h = ctx.canvas.height) {
const img = ctx.getImageData(x, y, w, h);
const d = img.data;
for (let i = 0; i < d.length; i += 4) {
const r = d[i];
const g = d[i + 1];
const b = d[i + 2];
const a = d[i + 3];
if (!a) continue;
for (const rule of colorMap) {
if (near(r, g, b, rule.from, rule.tol)) {
d[i] = rule.to[0];
d[i + 1] = rule.to[1];
d[i + 2] = rule.to[2];
break;
}
}
}
ctx.putImageData(img, x, y);
}
const intervalId = setInterval(() => {
if (!canvas) return;
const ctx = canvas.getContext('2d', { willReadFrequently: true });
remapCanvas(ctx);
}, 50);
}
let initInterval = setInterval(function(){
canvas = document.querySelector('canvas.noth');
if (canvas){
clearInterval(initInterval);
init();
}
}, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment