WaniKani URL Keyword search

Make it possible to search WaniKani by using a URL parameter https://www.wanikani.com/dashboard?q= so that you can register this search in your chrome keyword searches

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name       WaniKani URL Keyword search
// @namespace   irrelephant
// @description Make it possible to search WaniKani by using a URL parameter https://www.wanikani.com/dashboard?q= so that you can register this search in your chrome keyword searches
// @author     irrelephant
// @version    1.0.0
// @include https://www.wanikani.com/dashboard*
// @grant       none
// ==/UserScript==


(function () {
    'use strict';
    console.log('#### Starting WaniKani URL Keyword search.... ');
    init();

    function init() {
        var searchTerm = getSearchTerm();
        if (searchTerm) {
            submitSearch(searchTerm);
        }
    }

    function getSearchTerm() {
        var url_string = window.location.href;
        var url = new URL(url_string);
        var q = url.searchParams.get('q');
        console.log('Search parameter q was ' + q);
        return q;
    }

    /**
     * Simulate search form submit
     * @param searchTerm
     */
    function submitSearch(searchTerm) {
        var searchField = document.getElementById('query');
        searchField.value = searchTerm;

        var searchForm = document.getElementById('search-form');
        var submitProps = {
            bubbles: true,
            target: searchForm,
            type: 'submit'
        };
        var e = new Event('submit', submitProps);
        searchForm.dispatchEvent(e);
    }
})();