-
-
Save MistahCheese/12f5c238ca5c65a14a0f2ed2cd5551f8 to your computer and use it in GitHub Desktop.
Adds kanji stroke order to the Study and Review sections of kanji.koohii.com, and a button to import the Heisig story from hochanh.github.io/rtk/. Also hides the new stories section by default.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Kanji.koohii Stroke Order | |
| // @namespace koohiistroke | |
| // @description Adds kanji stroke order to the study and review sections on kanji.koohii.com | |
| // @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* | |
| // @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js | |
| // @require https://gist.github.com/raw/2625891/waitForKeyElements.js | |
| // @grant GM_xmlhttpRequest | |
| // @grant GM_addStyle | |
| // @version 1.2 | |
| // @updateURL https://gist.githubusercontent.com/MistahCheese/12f5c238ca5c65a14a0f2ed2cd5551f8/raw/23d9101b44eac883d062dec57bd5a4305a180218/koohiistroke.js | |
| // ==/UserScript== | |
| var stroke_container = ".k-sod"; | |
| var inject_container = document.createElement("div"); | |
| // Mouse click stuff from http://stackoverflow.com/questions/15511381/normal-button-clicking-approaches-are-not-working-in-greasemonkey-script | |
| function triggerMouseEvent (node, eventType) { | |
| var clickEvent = document.createEvent('MouseEvents'); | |
| clickEvent.initEvent (eventType, true, true); | |
| node.dispatchEvent (clickEvent); | |
| } | |
| function triggerMostButtons (jNode) { | |
| triggerMouseEvent (jNode[0], "mouseover"); | |
| triggerMouseEvent (jNode[0], "mousedown"); | |
| triggerMouseEvent (jNode[0], "mouseup"); | |
| triggerMouseEvent (jNode[0], "click"); | |
| } | |
| function clickElement (e) { | |
| waitForKeyElements (e, triggerMostButtons); | |
| } | |
| // Study section | |
| if(window.location.href.indexOf("study") > -1) { | |
| // Stroke order | |
| 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)); | |
| } | |
| }); | |
| // Hide new stories | |
| $('#sharedstories-new').attr('class', 'JsHide'); | |
| // Heisig button | |
| var heisigButton = document.createElement("div"); | |
| document.querySelector("#EditStoryComponent > div").appendChild(heisigButton); | |
| heisigButton.innerHTML = '<div id="Heisigify" class="is-toggle-1" ' + | |
| 'style="position: absolute; top: -0px; left: 150px;">' + | |
| '<a href="#" class="uiGUI btn btn-ghost JsEditFlashcard is-1" ' + | |
| 'title="Heisigify" data-uri="/" ' + | |
| 'data-param="{}"><i class="fa fa-pencil"></i>Heisigify</a></div>'; | |
| linkKanji = function(s) { | |
| r = ''; | |
| for (var i = 0, len = s.length; i < len; i++) { | |
| if (/[\u4e00-\u9faf]/.test(s[i])) {r = r + '{' + s[i] + '}';} | |
| else {r = r + s[i];}}; | |
| return r; | |
| }; | |
| $('#Heisigify').click(function() { | |
| clickElement("#sv-textarea"); | |
| GM_xmlhttpRequest({ | |
| method: "GET", | |
| url: "https://hochanh.github.io/rtk/"+document.querySelector(".kanji>span").textContent+"/index.html", | |
| onload: function(response) { | |
| var responseHTML = new DOMParser().parseFromString(response.responseText, "text/html"); | |
| htext = linkKanji(responseHTML.querySelector("body > div.main > p:nth-child(8)").textContent); | |
| $('#frmStory').val(htext); | |
| clickElement('#storyedit > div > div:nth-child(2) > input[type="submit"]:nth-child(1)'); | |
| } | |
| }); | |
| }); | |
| }; | |
| // 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 (target.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("#kanjibig>p>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 }; | |
| observer.observe(target, config); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment