油猴脚本 - dicts.cn 单词自动跳转 双核浏览器可用

发布时间 2023-06-05 09:38:50作者: 彭成刚

跳转格式 http://www.dicts.cn/?w=blight
20230605 更新

// ==UserScript==
// @name         dicts.cn 单词自动跳转 双核浏览器可用
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://www.dicts.cn/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    // Your code here...
    setTimeout(function () {
        console.info('code 111 run', document.getElementById('word'))
            document.getElementById('word').focus();
        }, 100)
    console.info('code run')
    $(document).ready(function(){
        document.getElementById('word').focus();
        setTimeout(function () {
            console.info('code 111 run', document.getElementById('word'))
            document.getElementById('word').focus();
        }, 200)
        
        const w = getQuery('w')
        if (w) {
            $('#word').val(w)
            window.select();
        }
    });

    function getQuery(variable)
    {
       var query = window.location.search.substring(1);
        console.info('query', query)
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
    }
})();