Skip to content

Instantly share code, notes, and snippets.

@psygo
Created November 5, 2021 18:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psygo/cfa3e42006abae464c40ba69fafa7d4c to your computer and use it in GitHub Desktop.
Save psygo/cfa3e42006abae464c40ba69fafa7d4c to your computer and use it in GitHub Desktop.
OGS Custom Diamond Stones from Greasy Fork
// ==UserScript==
// @name ogs custom stones
// @version 0.1
// @description custom stones on OGS
// @author michiakig
// @match https://online-go.com/*
// @run-at document-idle
// @namespace https://greasyfork.org/users/592542
// ==/UserScript==
// Here's the source: https://greasyfork.org/en/scripts/405885-ogs-custom-stones/code
(function() {
function setup() {
console.log("[ogs custom stones] setting up");
// custom place stone function for flat edges
var placeStoneFn = function(image) {
return function(ctx, shadow_ctx, stone, cx, cy, radius) {
ctx.drawImage(image, cx - radius, cy - radius, radius * 2, radius * 2);
};
};
var white = document.createElement('img');
white.setAttribute('src', 'https://i.imgur.com/b8lmPkX.png');
var black = document.createElement('img');
black.setAttribute('src', 'https://i.imgur.com/wlBc7bp.png');
GoThemes.white.Plain.prototype.placeWhiteStone = placeStoneFn(white);
GoThemes.black.Plain.prototype.placeBlackStone = placeStoneFn(black);
// click the theme selector which will trigger a redraw
document.querySelector("div.theme-set div.selector").click();
console.log("[ogs custom stones] done");
};
if (typeof data !== "undefined" && typeof GoThemes !== "undefined") {
setup();
} else {
// set up the mutation observer
// altho this should be installed with @run-at idle, I still saw the code run prior to these globals being available, so just watch the page for updates until they are present
var observer = new MutationObserver(function (mutations, me) {
if (typeof data !== "undefined" && typeof GoThemes !== "undefined") {
setup();
me.disconnect(); // stop observing
} else {
console.log("[ogs custom stones] data or GoThemes not found, waiting...");
}
});
// start observing
observer.observe(document, {
childList: true,
subtree: true
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment