TDK arama uzantısı

TDK'nın sözlük sitesinde URL'ye girilmiş kelimeyi aratır. URL örneği: http://sozluk.gov.tr/?q=KAİDE

目前為 2019-06-07 提交的版本,檢視 最新版本

// ==UserScript==
// @name         TDK arama uzantısı
// @namespace    https://github.com/nhtctn
// @version      1.1
// @description  TDK'nın sözlük sitesinde URL'ye girilmiş kelimeyi aratır. URL örneği: http://sozluk.gov.tr/?q=KAİDE
// @author       nht.ctn & Magnum357
// @include      *://sozluk.gov.tr/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

var urlParams = new URLSearchParams(window.location.search);
var word = urlParams.get('q');
var inputEl = document.querySelector('#tdk-srch-input');
var buttonEl = document.querySelector('#tdk-search-btn');
var suggestionPanelEl = document.querySelector('.autocmp');

// Show the result by a query when the page opened
if ( word != undefined ) showResult(word);

// Select the first suggestion on the enter press
inputEl.addEventListener('keypress', goToFirstSuggestion);

// Refresh the query on the enter press or a suggestion click
buttonEl.addEventListener('click', realTimeSearch);
suggestionPanelEl.addEventListener('click', realTimeSearch);

function showResult(word) {
	inputEl.value = word;
    buttonEl.click();
}

function setWord(word) {
    if (history.pushState) {
        var newurl = window.location.protocol + '//' + window.location.host + window.location.pathname + '?q=' + word;
        window.history.pushState({path:newurl}, '', newurl);
        document.title = word;
    }
}

function realTimeSearch() {
    setWord(inputEl.value);
}

function goToFirstSuggestion(e) {
    if ( e.keyCode == 13 ) {
        var word = suggestionPanelEl.querySelector('.selected').innerText;
        inputEl.value = word;
        setWord( word );
    }
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址