网易严选按性别分类

给网易严选增加按性别分类的选项

目前为 2017-11-28 提交的版本。查看 最新版本

// ==UserScript==
// @name  网易严选按性别分类
// @name:en   You 163 Filter by Sex
// @namespace    https://github.com/BlindingDark/You163SexFilter
// @include 	 *://you.163.com/*
// @version      1.0
// @description  给网易严选增加按性别分类的选项
// @description:en  Add sex filter to you.163.com
// @author       BlindingDark
// @grant        none
// @license      Apache Licence 2.0
// ==/UserScript==

$(function() {
  const elementText =
    `<div class="category">
       <span class="name">性别:</span>
       <div class="sex">
         <a href="javascript:;" class="categoryItem j-categoryItem active" id="sex_filter_all">全部</a>
         <a href="javascript:;" class="categoryItem j-categoryItem" id="sex_filter_male">男</a>
         <a href="javascript:;" class="categoryItem j-categoryItem" id="sex_filter_female">女</a>
       </div>
     </div>`

  const NIL = [];
  const MALE_KEYWORDS = ["男", "绅士"];
  const FEMALE_KEYWORDS = ["女", "名媛"];
  let nowStatus = NIL;

  function injectGoods(sex) {
    nowStatus = sex;

    let goods = $("#j-goodsAreaWrap").find(".item");

    $.each(goods, (goodIndex, good) => {
      $(good).show();

      let name = $(good).find(".name span")[1].textContent;
      $.each(sex, (keyWordIndex, keyWord) => {
        if (name.includes(keyWord)) {
          $(good).hide();
        }
      });
    });
  }

  function initLink(element) {
    $.each([$("#sex_filter_all"),
            $("#sex_filter_male"),
            $("#sex_filter_female")],
           (index, e) => {e.removeClass("active");});

    element.addClass("active");
  }

  function jQueryStart(){
    let mContent = $(".m-content");

    if (mContent.length == 0) {
      console.log("waiting for m-content prepared");
      window.setTimeout(jQueryStart,1000);
    } else {
      $(".m-sortbar").append(elementText);

      all_filter = $("#sex_filter_all");
      male_filter = $("#sex_filter_male");
      female_filter = $("#sex_filter_female");

      all_filter.click(() => {initLink(all_filter); injectGoods(NIL);});
      male_filter.click(() => {initLink(male_filter); injectGoods(FEMALE_KEYWORDS);});
      female_filter.click(() => {initLink(female_filter); injectGoods(MALE_KEYWORDS);});

      mContent.bind('DOMNodeInserted', function(e) {
        injectGoods(nowStatus);
      });
    }
  }

  function Tampermonkey_jQuery_wait(){
    if(typeof jQuery == 'undefined') {
      console.log("waiting for jQuery prepared");
      window.setTimeout(Tampermonkey_jQuery_wait,1000);
    }
    else {
      console.log("jQuery ready");
      jQueryStart();
    }
  }

  Tampermonkey_jQuery_wait();
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址