Greasy Fork is available in English.

pub-functions

公共函数库

Dette scriptet burde ikke installeres direkte. Det er et bibliotek for andre script å inkludere med det nye metadirektivet // @require https://update.greatest.deepsurf.us/scripts/438730/1011459/pub-functions.js

  1. // ==UserScript==
  2. // @name functions
  3. // @namespace https://hz.cn2down.com
  4. // @version 0.1.1
  5. // @description 公共函数库
  6. // @author zenghp2015
  7. // @grant GM_openInTab
  8. // @license MIT
  9. // ==/UserScript==
  10. (function() {
  11. 'use strict';
  12. const libs = {
  13. getQuery: function () {
  14. const url = decodeURI(location.search);
  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. getQueryValue: function (name) {
  27. const url = decodeURI(location.search);
  28. if (url.indexOf("?") != -1) {
  29. const str = url.substr(1);
  30. const pairs = str.split("&");
  31. for(let i = 0; i < pairs.length; i ++) {
  32. const pair = pairs[i].split("=");
  33. if(pair[0] === name) return pair[1];
  34. }
  35. }
  36. return false;
  37. },
  38. sleep: function(time) {
  39. return new Promise((resolve) => setTimeout(resolve, time));
  40. },
  41. openWindow: function(url, callback, opts = {}) {
  42. return new Promise((resolve) => {
  43. const newTab = GM_openInTab(url, opts)
  44. newTab.onclose = function() {
  45. callback();
  46. resolve();
  47. }
  48. })
  49. }
  50. }
  51. window.$libs = libs
  52. })();