My jQuery Plugin

获取URL参数

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/35940/241249/My%20jQuery%20Plugin.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @version        0.0.4
// @modifvm        2018.01.05
// @name           My jQuery Plugin
// @homepage       https://greasyfork.org/zh-CN/scripts/35940
// ==/UserScript==

(function ($) {
  $.getUrlParam = function(name, url, option) {//筛选参数,url 参数为数字时
    url = url ? url.replace(/^.+\?/,'') : location.search;
    //网址传递的参数提取,如果传入了url参数则使用传入的参数,否则使用当前页面的网址参数
    var reg = new RegExp("(?:^|&)(" + name + ")=([^&]*)(?:&|$)", "i");		//正则筛选参数
    var str = url.replace(/^\?/,'').match(reg);

    if (str !== null) {
      switch(option) {
        case 'param':
        case 0:
          return unescape(str[0]);		//所筛选的完整参数串
        case 'name':
        case 1:
          return unescape(str[1]);		//所筛选的参数名
        case 'value':
        case 2:
          return unescape(str[2]);		//所筛选的参数值
        default:
          return unescape(str[2]);        //默认返回参数值
      } 
    } else {
      return null;
    }
  }
  //设置新的参数
  $.setUrlParam = function(name, url, newVal){
    var checkParam=$.getUrlParam(name, url, 0);
    if(checkParam){
      return url.replace(checkParam, $.getUrlParam(name, url, 1)+"="+newVal);
    }
  }
})(jQuery);