User:Opencooper/jishoResult.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Uses the experimental jisho.org API to see if the kanji has any hits in
// JMDict
// Doc: https://jisho.org/forum/54fefc1f6e73340b1f160000-is-there-any-kind-of-search-api
// Example: https://jisho.org/api/v1/search/words?keyword=house
function setup() {
    // If we're not reading an article, do nothing
    if (!(mw.config.get( 'wgAction' ) === 'view'
          && mw.config.get( 'wgIsArticle' )
          && !location.search.split('oldid=')[1]
          && !mw.config.get("wgIsMainPage")
          && mw.config.get('wgNamespaceNumber') === 0)) {
        return;
    }

    var target = document.querySelector("#firstHeading");
    var observer = new MutationObserver(function(mutationsList) {
        for (var mutation of mutationsList) {
            if (mutation.target.id == "kanjiInfo") {
                observer.disconnect();
                $("#kanjiInfo").addClass("kanjiInfo-neutral");
                getDefinition();
            }
        }
    });

    observer.observe(target, {childList: true, subtree: true});
}

function getDefinition() {
    
}

$(setup);