Skip to content

Instantly share code, notes, and snippets.

@dudukee
Created September 12, 2017 06:56
Show Gist options
  • Save dudukee/3c9173c42a9e495274000f3ef027588a to your computer and use it in GitHub Desktop.
Save dudukee/3c9173c42a9e495274000f3ef027588a to your computer and use it in GitHub Desktop.
闲鱼搜索框
// ==UserScript==
// @name 闲鱼搜索框
// @namespace https://yougg.github.io/
// @version 1.2
// @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(){
'use strict';
// 添加顶部导航栏的大搜索框
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>';
document.getElementById("J_IdleHeader").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>'
// 显示商品下面的收藏按钮
var b = document.getElementsByTagName('body')[0];
b.innerHTML = replaceAll(replaceAll(b.innerHTML, '<!--<a', '<a'), '</a>-->', '</a>');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment