// ==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.6
// @grant none
// @downloadURL 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="
};
//添加----“搜索按钮的添加按钮”
var addSearchBtn = $("#search").clone(true).attr("type","button").attr("id","addSearchBtn").attr("style","margin-left:5px").attr("class","btn btn-info").text("添加搜索按钮").appendTo($("#search").parent());
//添加select选择框
var str = "
搜索引擎
";
var searcgEngine = $(str).appendTo($("#search").parent());
//绑定选择框的change事件--选择对应引擎
$('#searcgEngine').change(function(){
addBtn();
});
var addBtn = function(){
//删除存在的按钮
$(".sjwbtn").remove();
$(".stbbtn").remove();
var cjBtns = $("button:contains(抽奖咯)");
//遍历每一个学校
cjBtns.each(function(i){
//删除多余的br
$(this).parent().next().find('br').remove();
//添加搜索按钮
var newjwbtn = $("
").appendTo($(this).parent().next());
var newtbbtn = $("
").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 = $('#searcgEngine').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);
})();