函数库

公共函数库

当前为 2022-01-18 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/438730/1009750/%E5%87%BD%E6%95%B0%E5%BA%93.js

  1. // ==UserScript==
  2. // @name 函数库
  3. // @namespace https://hz.cn2down.com
  4. // @version 0.1
  5. // @description 公共函数库
  6. // @author zenghp2015
  7. // @license MIT
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12. const libs = {
  13. getQuery: function () {
  14. const url = decodeURI(location.search); // 获取url中"?"符后的字串(包括问号)
  15. let query = {};
  16. if (url.indexOf("?") != -1) {
  17. const str = url.substr(1);
  18. const pairs = str.split("&");
  19. for(let i = 0; i < pairs.length; i ++) {
  20. const pair = pairs[i].split("=");
  21. query[pair[0]] = pair[1];
  22. }
  23. }
  24. return query ; // 返回对象
  25. },
  26.  
  27. getQueryValue: function (name) {
  28. const url = decodeURI(location.search); // 获取url中"?"符后的字串(包括问号)
  29. let query = {};
  30. if (url.indexOf("?") != -1) {
  31. const str = url.substr(1);
  32. const pairs = str.split("&");
  33. for(let i = 0; i < pairs.length; i ++) {
  34. const pair = pairs[i].split("=");
  35. if(pair[0] === name) return pair[1]; // 返回 参数值
  36. }
  37. }
  38. return(false);
  39. }
  40. }
  41. window.cn2Libs = libs
  42.  
  43. })();