Greasy Fork is available in English.

抽奖系统添加搜索按钮

对系统进行增强

Od 29.05.2019.. Pogledajte najnovija verzija.

// ==UserScript==
// @name         抽奖系统添加搜索按钮
// @description  对系统进行增强
// @namespace    Violentmonkey Scripts
// @match        http://*/School/kefu.jsp
// @require      http://code.jquery.com/jquery-1.11.0.min.js
// @icon         https://ss1.baidu.com/70cFfyinKgQFm2e88IuM_a/forum/pic/item/d52a2834349b033bfcaf6df81fce36d3d539bde9.jpg
// @author       xzq
// @version      0.0.3
// @grant        none
// ==/UserScript==
(function() {
    'use strict';
    //定义搜索引擎
    var searchs = {
      "百度":"http://www.baidu.com/s?wd=",
      "必应":"https://cn.bing.com/search?q=",
      "360搜索":"http://www.so.com/s?q=",
      "搜狗":"http://www.sogou.com/sogou?query=",
      "Google(VPN)":"http://www.google.com.hk/search?q=",
      "Yahoo(VPN)":"https://search.yahoo.com/search?p="
    };
  
     //添加间隙
    $("<span>&nbsp;&nbsp;</span>").appendTo($("#search").parent());
     //添加----“搜索按钮的添加按钮”
    var addSearchBtn = $("#search").clone(true).attr("type","button").attr("id","addSearchBtn").attr("class","btn btn-info").text("添加搜索按钮").appendTo($("#search").parent());
    //添加间隙  
    $("<span>&nbsp;&nbsp;</span>").appendTo($("#search").parent());
    
  //添加select选择框
    var str = "<div class='input-group'><span class='input-group-addon'>搜索引擎</span><select id='seachEng' class='selectpicker show-tick form-control'>";
    for(var key in searchs){
        str += "<option value="+ searchs[key] +">"+ key +"</option>";
    }
    str += "</select></div>";
    var selectEng = $(str).appendTo($("#search").parent());
  
    //绑定选择框的change事件--选择对应引擎
    $('#seachEng').change(function(){
      $(".sjwbtn").remove();
      $(".stbbtn").remove();
      addBtn();
    });
  
    var addBtn = function(){
        var cjBtns = $("button:contains(抽奖咯)");
        //遍历每一个学校
        cjBtns.each(function(i){
            //防止重复添加
            if($(".sjwbtn").size() < cjBtns.size() && $(".stbbtn").size() < cjBtns.size()){
              //删除多余的br
              $(this).parent().next().find('br').remove();
              
              //添加搜索按钮
              var newjwbtn = $("<br/><button type='button' class='sjwbtn btn btn-default btn-xs' style='margin-bottom:5px'><span class='glyphicon glyphicon-search'></span> 搜教务系统</button>").appendTo($(this).parent().next());
              var newtbbtn = $("<br/><button type='button' class='stbbtn btn btn-default btn-xs'><span class='glyphicon glyphicon-search'></span> 搜百度贴吧</button>").appendTo($(this).parent().next());
              
              //获取学校名称
              var schoolName = $(this).parent().next().text();
              var reg = RegExp(/\(\d+\)/);
              if(reg.test(schoolName)){
                  schoolName = schoolName.substring(0, schoolName.indexOf("("));
              }
              
              //拼接url
              var jwurl = $('#seachEng').val() + schoolName + " 教务系统";
              var tburl = "http://tieba.baidu.com/f/search/res?ie=utf-8&kw=" + schoolName + "&qw=教务系统";
              
              //绑定按钮的打开新页面的事件
              newjwbtn.click(function(){
                 window.open(jwurl);
              });
              newtbbtn.click(function(){
                 window.open(tburl);
              });
            }
        });
    };
    
    //添加搜索按钮的点击事件
    addSearchBtn.click(addBtn);
})();