Greasy Fork

Greasy Fork is available in English.

闲鱼搜索框

恢复导航栏的大搜索框和列表栏的小搜索框

当前为 2018-12-05 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         闲鱼搜索框
// @namespace    https://yougg.github.io/
// @version      1.5
// @description  恢复导航栏的大搜索框和列表栏的小搜索框
// @author       yougg
// @match        https://2.taobao.com/*
// @match        https://s.2.taobao.com/*
// @match        https://trade.2.taobao.com/*
// @grant        none
// ==/UserScript==

function escapeRegExp(str) {
    return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}

function replaceAll(str, find, replace) {
    return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}

function showFavorite() {
    var goods = document.getElementsByClassName('item-other-info');
    if (goods.length > 0) {
        for (var i = 0; i < goods.length; i++) {
            var v = goods[i];
            v.innerHTML = replaceAll(replaceAll(v.innerHTML, '<!--<a', '<a'), '</a>-->', '</a>');
        }
    }
}

(function(){
    'use strict';

    var style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = '.idle-search { position: absolute; right: 65px; top: 27px; width: 222px; height: 36px; background-color: #333; }' +
        '.input-search { width: 164px; height: 32px; padding: 0 10px; margin: 0; border: 0; outline: 0; position: absolute; left: 2px; top: 2px; font-size: 13px; }' +
        '.btn-search { display: block; width: 36px; height: 36px; position: absolute; top: 0; right: 0; color: #fff; background-color: #333; border: 0; margin: 0; padding: 0; cursor: pointer; outline: 0; }' +
        '.iconfont { font-family: xy-iconfont; font-size: 18px; font-style: normal; }' +
        '.search-img { position: absolute; right: -65px; top: -13px; display: block; width: 79px; height: 60px; background: url(//gtms02.alicdn.com/tps/i2/TB1VqSxHVXXXXb.XVXXqw4SJXXX-79-60.png) no-repeat 0 0; _background: 0 0; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'images/\', sizingMethod=\'scale\'); zoom: 1; }';
    document.getElementsByTagName('head')[0].appendChild(style);
    //document.getElementById('xxxElementId').className = 'xxxClass';

    // 添加顶部导航栏的大搜索框
    var S = document.createElement("div");
    S.className = "idle-search";
    S.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>';
    var s0 = document.getElementById("J_IdleHeader");
    if (s0 !== null) {
        s0.appendChild(S);
    }
    var s1 = document.getElementsByClassName('navbar-wrap');
    if (s1.length > 0) {
        s1[0].appendChild(S);
    }

    // 显示列表页过滤栏的小搜索框
    var s = document.getElementsByClassName('search-filters-block search-filters');
    if (s.length > 0) {
        s[0].style.display = "initial";
    }

    // 备份小搜索框源码,防马云删除!
    // '<div class="search-filters-block search-filters">' +
    // '	<label for="J_SearchFilterInput">搜索</label>' +
    // '	<div class="search-input-wrapper">' +
    // '		<input id="J_SearchFilterInput" type="text" name="q" value="Pixel XL">' +
    // '	</div>' +
    // '	<button type="submit">确定</button>' +
    // '</div>'

    document.body.onload = function() {
        // 移除App下载提示
        var d = document.getElementsByClassName('download-layer');
        if (d.length > 0) {
            d[0].parentElement.remove();
        }
        var d1 = document.getElementsByClassName('pop-wrap');
        if (d1.length > 0) {
            d1[0].innerHTML = '';
            d1[0].className = '';
        }
        var d2 = document.getElementsByClassName('bottom-wrap');
        if (d2.length > 0) {
            d2[0].parentElement.innerHTML = '';
        }
        var m = document.getElementsByClassName('mau-guide');
        if (m.length >0) {
            m[0].parentNode.removeChild(m[0]);
        }
        var g = document.getElementsByClassName('xy-guide');
        if (g.length > 0) {
            g[0].remove();
        }
        var j = document.getElementById('J_Message');
        if (j !== null) {
            j.firstElementChild.remove();
        }
        var t = document.getElementById('guarantee');
        if (t !== null) {
            t.remove();
        }
        document.getElementById('J_IdleFooter').remove();

        // 显示商品下面的收藏按钮
        showFavorite();
    };

    var c = document.getElementById('J_ItemListsContainer');
    if (c !== null) {
        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
        var observer = new MutationObserver(function(mutations, observer) {
            showFavorite();
        });
        observer.observe(c, {
            childList: true
        });
    }
})();