Skip to content

Instantly share code, notes, and snippets.

@jealie
Forked from shussekaido/koohiistroke.js
Last active March 7, 2018 20:55
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 jealie/7569590bcb939a9bbd76c213a4b9f6bc to your computer and use it in GitHub Desktop.
Save jealie/7569590bcb939a9bbd76c213a4b9f6bc to your computer and use it in GitHub Desktop.
Adds kanji stroke order to the Study and Review sections of kanji.koohii.com. Works with Tampermonkey or Greasemonkey for Chrome or Firefox.
// ==UserScript==
// @name Kanji.koohii Stroke Order
// @namespace koohiistroke
// @description Adds kanji stroke order to the study and review sections on kanji.koohii.com - forked and modified from https://gist.github.com/shussekaido/3541ab70e37983f0360d
// @include http://kanji.koohii.com/study/kanji/*
// @include https://kanji.koohii.com/study/kanji/*
// @include http://kanji.koohii.com/review*
// @include https://kanji.koohii.com/review*
// @include http://staging.koohii.com/study/kanji/*
// @include https://staging.koohii.com/study/kanji/*
// @include http://staging.koohii.com/review*
// @include https://staging.koohii.com/review*
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @grant GM.xmlHttpRequest
// @grant GM_xmlhttpRequest
// @version 1.31
// @downloadURL https://gist.github.com/jealie/7569590bcb939a9bbd76c213a4b9f6bc/raw/koohiistroke.user.js
// ==/UserScript==
var stroke_container = ".k-sod";
var inject_container = document.createElement("div");
// Study section
if(window.location.href.indexOf("study") > -1) {
document.querySelector("#my-story .right").appendChild(inject_container);
GM.xmlHttpRequest({
method: "GET",
url: "http://www.ig.gmodules.com/gadgets/proxy/refresh=31556926&container=ig/http://tangorin.com/kanji/"+document.querySelector(".kanji>span").textContent,
onload: function(response) {
var responseHTML = new DOMParser().parseFromString(response.responseText, "text/html");
inject_container.appendChild(responseHTML.documentElement.querySelector(stroke_container));
}
});
};
// Review section
if(window.location.href.indexOf("review") > -1) {
var target = document.querySelector('#uiFcMain');
document.querySelector("#rd-side").appendChild(inject_container);
var observer = new MutationObserver(function(mutations) {
if (document.querySelector(".uiFcCard").classList.contains("uiFcState-1")) {
GM.xmlHttpRequest({
method: "GET",
url: "http://www.ig.gmodules.com/gadgets/proxy/refresh=31556926&container=ig/http://tangorin.com/kanji/"+document.querySelector(".d-kanji>div>div>span>span").textContent,
onload: function(response) {
var responseHTML = new DOMParser().parseFromString(response.responseText, "text/html");
inject_container.innerHTML = "<br />" + responseHTML.documentElement.querySelector(stroke_container).innerHTML;
}
});
} else {
inject_container.innerHTML = "";
};
});
var config = { attributes: true, subtree: true, childList: true };
observer.observe(target, config);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment