函数库

公共函数库

目前為 2022-01-18 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/438730/1009750/%E5%87%BD%E6%95%B0%E5%BA%93.js

// ==UserScript==
// @name         函数库
// @namespace    https://hz.cn2down.com
// @version      0.1
// @description  公共函数库
// @author       zenghp2015
// @license MIT
// ==/UserScript==

(function() {
  'use strict';
 
 const libs = {
     
     getQuery: function () {
        const url = decodeURI(location.search); // 获取url中"?"符后的字串(包括问号)
        let query = {};
        if (url.indexOf("?") != -1) {
            const str = url.substr(1);
            const pairs = str.split("&");
            for(let i = 0; i < pairs.length; i ++) {
                const pair = pairs[i].split("=");
                query[pair[0]] = pair[1];
            }
        }
        return query ;  // 返回对象
    },

    getQueryValue: function (name) {
        const url = decodeURI(location.search); // 获取url中"?"符后的字串(包括问号)
        let query = {};
        if (url.indexOf("?") != -1) {
            const str = url.substr(1);
            const pairs = str.split("&");
            for(let i = 0; i < pairs.length; i ++) {
                const pair = pairs[i].split("=");
                if(pair[0] === name) return  pair[1]; // 返回 参数值
            }
        }
        return(false);
    }
 }
 
 window.cn2Libs = libs

})();