TDK Arama Yardımcısı

TDK'nın sözlük sitesinde URL'den arama yapmaya olanak sağlar (URL örneği: http://sozluk.gov.tr/?q=KAİDE), tarayıcı geçmişinde aranan kelimeler için kayıt oluşturur ve site anasayfasında eski aramaları gösterir.

当前为 2019-06-11 提交的版本,查看 最新版本

// ==UserScript==
// @name         TDK Arama Yardımcısı
// @namespace    https://github.com/nhtctn
// @version      1.5
// @description  TDK'nın sözlük sitesinde URL'den arama yapmaya olanak sağlar (URL örneği: http://sozluk.gov.tr/?q=KAİDE), tarayıcı geçmişinde aranan kelimeler için kayıt oluşturur ve site anasayfasında eski aramaları gösterir.
// @author       nht.ctn & Magnum357
// @include      *://sozluk.gov.tr/*

// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @run-at       document-idle
// ==/UserScript==

/*
** [ ESSENTIALS ]
*/

var urlParams = new URLSearchParams(window.location.search);
var word = urlParams.get('q');
var inputEl = document.querySelector('#tdk-srch-input');
var formEl = document.querySelector('#tdk-srch-form');
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); setWord(word);}

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

// Refresh query
 formEl.onsubmit = realTimeSearch;

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

function setWord(word) {
    // Browser History
    if (history.pushState) {
        // Refresh the query and write it history
        var newurl = window.location.protocol + '//' + window.location.host + window.location.pathname + '?q=' + word;
        window.history.replaceState({}, '', newurl);

        // Title on history
        document.title = word;
    }

        // Script History (maximum 1000 entry)
        var pastArray_word = GM_getValue("pastArray_word");
        var pastArray_time = GM_getValue("pastArray_time");
        if (!pastArray_word || !pastArray_time) {pastArray_word = []; pastArray_time = [];}
        if (word != pastArray_word[pastArray_word.length-1]) {
            pastArray_word[pastArray_word.length] = word;
            pastArray_time[pastArray_time.length] = new Date().getTime();
        }
        else {
            pastArray_time[pastArray_time.length-1] = new Date().getTime(); // If the word searced for second time, just update the time.
        }
        var cleaner = (pastArray_word.length > 1000) ? 1 : 0 ; // If the word number goes beyond 1000, it will delete one word for each new word. The number will remain 1000.
        GM_setValue("pastArray_word", pastArray_word.splice(cleaner, 1000));
        GM_setValue("pastArray_time", pastArray_time.splice(cleaner, 1000));
}

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

    var oldSignHTML = document.querySelector('div#signs_648');
    if (oldSignHTML) {oldSignHTML.remove();};
}

function goToFirstSuggestion(e) {
    if (e.keyCode == 13) {
        var wordEl = suggestionPanelEl.querySelector('.selected');

        if ( wordEl != undefined ) {
            inputEl.value = wordEl.innerText;
        }
    }
}

/*
** [ HIDING SIGN LANGUAGE ]
*/

var signLangContHTML = `
<div id="signs_648" class="card">
    <div class="card-header" id="headingThree">
        <h5 class="mb-0">
            <button class="btn collapsed" btn-link="" collapsed="" type="button" data-toggle="collapse" data-target="#isaret-gts0" aria-expanded="false" aria-controls="collapseThree">
                <strong style="padding:5px;font-size:15px">İşaret Dili</strong>
            </button>
        </h5>
    </div>
    <div id="isaret-gts0" class="collapse" aria-labelledby="headingThree" data-parent="#accordionExample-gts0" aria-expanded="false" style="height: 0px;">
        <div id="isaret-gts0" class="card-body" birlesik-gts0="">
        </div>
    </div>
</div>
`

var accordionHTML = `<div class="accordion" id="accordionExample-gts0"> </div>`

waitForKeyElements('div#isaretBulunan', hideSignLang, false);

function hideSignLang() {
    var accordion = document.querySelector('div.accordion');
    if (accordion == null) {document.querySelector('div#maddeleri-sar').insertAdjacentHTML("beforeend", accordionHTML);}
    document.querySelector('div.accordion').insertAdjacentHTML("beforeend", signLangContHTML);
    var signs = document.querySelector('div#isaretSoz');
    var signContainer = document.querySelector('div#isaret-gts0');
    signs.parentElement.style.display = "none";
    signContainer.insertAdjacentElement("afterbegin", signs);
}

/*
** [ PAST MODULE ]
*/

var pastContainerHTML = `
<div class="contain">
    <div id="past" style="padding: 0 5px;">
        <span class="thumbnail text-center" style="height: auto;">
            <h4 class="text-danger" style="color:red; font-weight:bolder; margin: 15px 0;">Geçmiş</h4>
            <ul class="pastUl">
            </ul>
            <div style="margin: 15px; text-align: left;">
                <button id="deletePast" class="btn" type="button"> <strong style="padding:5px;font-size:15px">Geçmişi Sil</strong> </button>
`//                <button class="btn" type="button"> <strong style="padding:5px;font-size:15px">Geçmiş Detayları</strong> </button>
+ `            </div>
        </span>
    </div>
</div>
`

GM_addStyle(`
.pastUl {margin: 15px; list-style: none; overflow: auto;}
.wordElements, .wordElements:hover {color:#cd853f; font-size:18px; font-weight: 700; margin: 0 10px 5px 10px; display: inline-block;}
`);

addPastToPage();
document.querySelector('button#deletePast').onclick = function() {deleteWord("all")};
waitForKeyElements('div#bulunmayan-gts.hata', function() {deleteWord("last")},false);

function addPastToPage() {
    // Container
    var pastContainer = document.querySelector('div#past > span > ul');
    if (pastContainer == null) {
        document.querySelector('div#kelime').parentElement.parentElement.parentElement.insertAdjacentHTML( "afterbegin", pastContainerHTML );
    }

    // Words
    getPast();
}

function getPast() {
    var wordElements = '';
    var counter = 0;
    var pastArray_word = GM_getValue("pastArray_word");
    var pastArray_time = GM_getValue("pastArray_time");
    for (var x = pastArray_word.length-1; x > -1 && counter < 40; x--) {
        if (wordElements.indexOf('?q=' + pastArray_word[x] + '"') <= 0)
        {
            wordElements += '<a href="http://sozluk.gov.tr/?q=' + pastArray_word[x] + '" class="wordElements" title="' + convertDate(pastArray_time[x]) + '">' + pastArray_word[x] + '</a>';
            counter++
        }
    }
    document.querySelector('div#past > span > ul').innerHTML = wordElements;
}

function convertDate(milliseconds) {
    var months = ["Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"];
    var d = new Date(milliseconds);
    var newDate = d.getDate() + ' ' + months[d.getMonth()] + ' ' + d.getFullYear() + ' (' + d.getHours().toString().padStart(2, "0") + ':' + d.getMinutes().toString().padStart(2, "0") + ')';
    return newDate;
}

function deleteWord( type ) {
    if (type == "all") {
        var c = confirm("Arama geçmişinizi silmek istediğinize emin misiniz?");
        if (c) {
            GM_setValue("pastArray_word", null);
            GM_setValue("pastArray_time", null);
            document.querySelector('div#past > span > ul').innerHTML = '';
        }
    }
    else if (type == "last") {
        var pastArray_word = GM_getValue("pastArray_word");
        var pastArray_time = GM_getValue("pastArray_time");
        pastArray_word.splice(pastArray_word.length-1, 1);
        pastArray_time.splice(pastArray_word.length-1, 1);
        GM_setValue("pastArray_word", pastArray_word);
        GM_setValue("pastArray_time", pastArray_time);
        document.querySelector('div#past > span > ul > a').remove();
    }
    else if (isNumber(type)) {
        // En mükemmel kod henüz yazılmamış olandır.
    }
}

function isNumber(val) {
    return (val >=0 || val < 0);
}

    function waitForKeyElements (
        selectorTxt,    /* Required: The jQuery selector string that
                            specifies the desired element(s).
                        */
        actionFunction, /* Required: The code to run when elements are
                            found. It is passed a jNode to the matched
                            element.
                        */
        bWaitOnce,      /* Optional: If false, will continue to scan for
                            new elements even after the first match is
                            found.
                        */
        iframeSelector  /* Optional: If set, identifies the iframe to
                            search.
                        */
    ) {
        var targetNodes, btargetsFound;

        if (typeof iframeSelector == "undefined")
            targetNodes     = $(selectorTxt);
        else
            targetNodes     = $(iframeSelector).contents ()
                                               .find (selectorTxt);

        if (targetNodes  &&  targetNodes.length > 0) {
            btargetsFound   = true;
            /*--- Found target node(s).  Go through each and act if they
                are new.
            */
            targetNodes.each ( function () {
                var jThis        = $(this);
                var alreadyFound = jThis.data ('alreadyFound')  ||  false;

                if (!alreadyFound) {
                    //--- Call the payload function.
                    var cancelFound     = actionFunction (jThis);
                    if (cancelFound)
                        btargetsFound   = false;
                    else
                        jThis.data ('alreadyFound', true);
                }
            } );
        }
        else {
            btargetsFound   = false;
        }

        //--- Get the timer-control variable for this selector.
        var controlObj      = waitForKeyElements.controlObj  ||  {};
        var controlKey      = selectorTxt.replace (/[^\w]/g, "_");
        var timeControl     = controlObj [controlKey];

        //--- Now set or clear the timer as appropriate.
        if (btargetsFound  &&  bWaitOnce  &&  timeControl) {
            //--- The only condition where we need to clear the timer.
            clearInterval (timeControl);
            delete controlObj [controlKey]
        }
        else {
            //--- Set a timer, if needed.
            if ( ! timeControl) {
                timeControl = setInterval ( function () {
                        waitForKeyElements (    selectorTxt,
                                                actionFunction,
                                                bWaitOnce,
                                                iframeSelector
                                            );
                    },
                    300
                );
                controlObj [controlKey] = timeControl;
            }
        }
        waitForKeyElements.controlObj   = controlObj;
    }

QingJ © 2025

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