Greasy Fork镜像 还支持 简体中文。

NH_userscript

Wrappers for dealing with variations in userscript managers.

目前為 2023-10-27 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/478349/1271068/NH_userscript.js

  1. // ==UserScript==
  2. // ==UserLibrary==
  3. // @name NH_userscript
  4. // @description Wrappers for dealing with variations in userscript managers.
  5. // @version 0
  6. // @license GPL-3.0-or-later; https://www.gnu.org/licenses/gpl-3.0-standalone.html
  7. // @homepageURL https://github.com/nexushoratio/userscripts
  8. // @supportURL https://github.com/nexushoratio/userscripts/issues
  9. // @match https://www.example.com/*
  10. // ==/UserLibrary==
  11. // ==/UserScript==
  12.  
  13. window.NexusHoratio ??= {};
  14.  
  15. window.NexusHoratio.userscript = (function base() {
  16. 'use strict';
  17.  
  18. /** @type {number} - Bumped per release. */
  19. const version = 0;
  20.  
  21. /** Library specific exception. */
  22. class UserscriptError extends Error {
  23.  
  24. /** @inheritdoc */
  25. constructor(...rest) {
  26. super(...rest);
  27. this.name = this.constructor.name;
  28. }
  29.  
  30. }
  31.  
  32. /**
  33. * @typedef LicenseData
  34. * @property {string} name - License name.
  35. * @property {string} url - URL pointing to the license.
  36. */
  37.  
  38. /**
  39. * Per the *old* GM docs:
  40. * https://sourceforge.net/p/greasemonkey/wiki/Metadata_Block/#license
  41. * @returns {LicenseData} - Extracted from the userscript header.
  42. * @throws {Error} - If cannot be extracted.
  43. */
  44. function licenseData() {
  45. let license = GM.info.script.license;
  46. if (!license) {
  47. const magic = '// @license ';
  48.  
  49. // Try Tampermonkey's way.
  50. const header = GM.info.script.header;
  51. if (header) {
  52. const line = header.split('\n').find(l => l.startsWith(magic));
  53. if (line) {
  54. license = line.slice(magic.length).trim();
  55. }
  56. }
  57. }
  58.  
  59. if (!license) {
  60. const msg = [
  61. 'Unable to extract license information from the userscript.',
  62. // eslint-disable-next-line no-magic-numbers
  63. JSON.stringify(GM.info.script, null, 2),
  64. ].join('\n');
  65. throw new UserscriptError(msg);
  66. }
  67.  
  68. const [name, url] = license.split(';');
  69.  
  70. return {
  71. name: name.trim(),
  72. url: url.trim(),
  73. };
  74. }
  75.  
  76. return {
  77. version: version,
  78. UserscriptError: UserscriptError,
  79. licenseData: licenseData,
  80. };
  81.  
  82. }());

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址