Greasy Fork

Greasy Fork is available in English.

[skypesky 出品]闲鱼助手 完美去除广告+搜索框(2019-04-02)

闲鱼助手 完美去除广告+搜索框

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         [skypesky 出品]闲鱼助手 完美去除广告+搜索框(2019-04-02)
// @author:      skypesky
// @namespace    http://skyepsky.cn/fallowFish
// @version      19.04.02
// @description  闲鱼助手 完美去除广告+搜索框

// @grant        GM_addStyle


// @include      http*://2.taobao.com/*
// @include      http*://s.2.taobao.com/*

// @require      https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js

// ==/UserScript==

(function () {

    'use strict';

    let style = `
    .sky-search-div  {
        width: 100%;
        display: flex;
        flex-direction: row;
        justify-content: center;
        height: 60px;
    }
    .sky-search-input {
        max-width: 200px;
        height: 32px;
        padding: 0px 10px;
        margin: 0px;
    }
    .sky-search-button {
        width: 54px;
        height: 36px;
        display: inline;
        padding: 6px 12px;
        margin: 6px 0px 0px 0px;
        background-color: #ffd84d;
        color: black;
        border: 1px solid #ccc;
    }
    .sky-btn-primary {
        color: #fff;
        background-color: #337ab7;
        border-color: #2e6da4;
    }
    .sky-white {
        color: white;
    }
        `;
    try {
        GM_addStyle(style)
    } catch (e) {
        console.warn(e);
    }

    var targetList = [
        ".guide-img",
        'img[alt="Scan me!"]',
        '.close-img',
        ".download-layer",
    ];

    // 这段函数每次执行都会触犯添加元素的事件,在body里面寻找节点会更加完美
    $('body').on('DOMNodeInserted', function (event) {
        for (var i = 0; i < targetList.length; ++i) {
            var removeElement = $('body').find(targetList[i]);
            if ($(removeElement).length > 0) {
                console.log($(removeElement));
                console.log("成功了: " + targetList[i]);
                $(removeElement).remove();
                // 删除元素
                targetList.splice(i, 1);
            }
        }
    });


    // 添加搜索框
    addNormalSearchBox();
    // 添加首页搜索框
    addHomeSearchBox();
    // 替换链接
    $(function() {
        replaceAllLink();
    });
   
})();

function replaceAllLink() {
    // https://s.2.taobao.com/list/list.htm?start=&end=&itemfrom=1&cpp=true&st_trust=1&ist=1&userId=0&q=da
    let originTag = "//s.2.taobao.com/list/list.htm";
    let realTag = "//s.2.taobao.com/list/list";
    let elementArray = $(`[href^='${originTag}']`);
    console.log(elementArray);
    // 替换
    [].forEach.call(elementArray, function(item, index) {
        $(item).attr('href', $(item).attr('href').replace(originTag, realTag));
    });
    // form处理
    $(`form[action]`).attr('action', $(`form[action]`).attr('action').replace(originTag, realTag));
}

// 获取搜索框
function addNormalSearchBox() {   
   // 创建元素
   var element = $(`<div class="sky-search-div">
    <form method="get" action='//s.2.taobao.com/list'>
        <input name="q" class="sky-search-input" type="text" placeholder="搜闲鱼">
        <input type='hidden' name='search_type' value='item' autocomplete='off' />
        <input type='hidden' name='app' value='shopsearch' autocomplete='off' />
        <button class="sky-search-button sky-btn-primary" type="submit">
            搜索
        </button>
    </form>
    </div>`);

   // 添加到元素中
   $('div#page').before(element);
}

function addHomeSearchBox() {
    // 创建元素
    var element = $(`<div class="sky-search-div">
    <form method="get" action='//s.2.taobao.com/list/list'>
        <input name="q" class="sky-search-input" type="text" placeholder="搜闲鱼">
        <input type='hidden' name='search_type' value='item' autocomplete='off' />
        <input type='hidden' name='app' value='shopsearch' autocomplete='off' />
        <button class="sky-search-button sky-btn-primary" type="submit">
            搜索
        </button>
    </form>
    </div>`);

    // 添加到元素中
    $('div.slodbar-wrap').before(element);
}