dingxiaobo / 闲鱼助手

// ==UserScript==
// @name         闲鱼助手
// @namespace    http://dxbtech.cn/
// @version      1.1
// @description  1.显示搜索框    2.宝贝加上标题
// @author       dingxiaobo
// @match        https://2.taobao.com/*
// @match        https://s.2.taobao.com/*
// @match        https://trade.2.taobao.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    //加上title
    function addTitle(){
        var items = document.getElementsByClassName("item-pic");
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            var title = item.getElementsByTagName("a")[0].getAttribute("title");

            if(item.getElementsByTagName("p").length===0){
                var p = document.createElement("p");
                p.innerHTML = "<p style='margin-top: 0.3rem;'>" + title + "</p>";
                //item.insertBefore(p,item.firstChild);
                item.append(p);
            }
        }
    }
    addTitle();
    document.body.onmousewheel = function(){
        addTitle();
    };
    document.onkeyup = function(){
        addTitle();
    };

    //加搜索框
    var searchBox = document.createElement("div");
    searchBox.className = "idle-search";
    searchBox.innerHTML ='  <form method="get" action="//s.2.taobao.com/list/list.htm" name="search" target="_top">' +
        '    <input class="input-search" id="J_HeaderSearchQuery" name="q" type="text" value="" placeholder="搜闲鱼" />' +
        '    <input type="hidden" name="search_type" value="item" autocomplete="off" />' +
        '    <input type="hidden" name="app" value="shopsearch" autocomplete="off" />' +
        '    <button class="btn-search" type="submit"><i class="iconfont">&#xe602;</i><span class="search-img"></span></button>' +
        '  </form>';
    document.getElementById("J_IdleHeader").appendChild(searchBox);

    //小搜索框
    var s = document.getElementsByClassName('search-filters-block search-filters');
    if (s.length > 0) {
        s[0].style.display = "initial";
    }

})();