Github-bot(留言 | 贡献) (Git更新:([https://github.com/TopRealm/InterfaceCodes/commit/382f0d5f77104964acdf3a9acbfe08e57b1685dc 382f0d5]) chore: change urls) |
小 (Git commit 315405d: feat: sync upstream with Qiuwen) |
||
(未显示2个用户的7个中间版本) | |||
第1行: | 第1行: | ||
/** |
/** |
||
* SPDX-License-Identifier: |
* SPDX-License-Identifier: CC-BY-SA-4.0 |
||
* _addText: '{{Gadget Header|license= |
* _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}' |
||
* |
* |
||
* @source |
* @source {@link https://github.com/TopRealm/YsArchives-Gadgets/tree/master/src/Geo} |
||
* @license CC-BY-SA-4.0 {@link https://youshou.wiki/wiki/H:CC-BY-SA-4.0} |
|||
* @dependency mediawiki.storage |
|||
*/ |
*/ |
||
/** |
/** |
||
* +--------------------------------------------------------+ |
* +------------------------------------------------------------+ |
||
* | === WARNING: GLOBAL GADGET FILE === | |
* | === WARNING: GLOBAL GADGET FILE === | |
||
* +--------------------------------------------------------+ |
* +------------------------------------------------------------+ |
||
* | All changes should be made in the repository, | |
* | All changes should be made in the repository, | |
||
* | otherwise they will be lost. | |
* | otherwise they will be lost. | |
||
* +--------------------------------------------------------+ |
* +------------------------------------------------------------+ |
||
* | Changes to this page affect many users. | |
* | Changes to this page may affect many users. | |
||
* | |
* | Please discuss changes by opening an issue before editing. | |
||
* +--------------------------------------------------------+ |
* +------------------------------------------------------------+ |
||
*/ |
*/ |
||
/* <nowiki> */ |
/* <nowiki> */ |
||
'use strict'; |
|||
(() => { |
|||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } |
|||
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } |
|||
"use strict"; |
|||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } |
|||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } |
|||
// dist/Geo/Geo.js |
|||
(function geoJS() { |
|||
function asyncGeneratorStep(n, t, e, r, o, a, c) { |
|||
var storageItemName = 'GeoIP'; |
|||
try { |
|||
var defaultGeoInfo = { |
|||
var i = n[a](c), u = i.value; |
|||
country: '', |
|||
} catch (n2) { |
|||
return void e(n2); |
|||
} |
|||
i.done ? t(u) : Promise.resolve(u).then(r, o); |
|||
} |
|||
function _asyncToGenerator(n) { |
|||
return function() { |
|||
var t = this, e = arguments; |
|||
return new Promise(function(r, o) { |
|||
var a = n.apply(t, e); |
|||
function _next(n2) { |
|||
asyncGeneratorStep(a, r, o, _next, _throw, "next", n2); |
|||
} |
|||
function _throw(n2) { |
|||
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n2); |
|||
} |
|||
_next(void 0); |
|||
}); |
|||
}; |
}; |
||
} |
|||
/** |
|||
function _createForOfIteratorHelper(r, e) { |
|||
* Parse geo data in storageValue and return an object with properties from |
|||
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; |
|||
* the fields therein. Returns null if the value couldn't be parsed or |
|||
if (!t) { |
|||
* doesn't contain location data. |
|||
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { |
|||
* |
|||
t && (r = t); |
|||
* The storage item will look like one of the following: |
|||
var n = 0, F = function() { |
|||
* - "CN-SH-Shanghai" |
|||
}; |
|||
return { s: F, n: function() { |
|||
* - "CN--" |
|||
return n >= r.length ? { done: true } : { done: false, value: r[n++] }; |
|||
* - "--" |
|||
}, e: function(r2) { |
|||
* |
|||
throw r2; |
|||
* @param {string} storageValue |
|||
}, f: F }; |
|||
*/ |
|||
var parseStorageValue = function parseStorageValue(storageValue) { |
|||
var _matches$, _matches$2; |
|||
// TODO Verify that these Regexes are optimal. (Why no anchors? Why the |
|||
// semicolon in the last group?) |
|||
// Parse storage item |
|||
var matches = storageValue.match(/([^-]*)-([^-]*)-([^-]*)/); |
|||
// No matches...? Boo, no data. |
|||
if (!matches) { |
|||
return defaultGeoInfo; |
|||
} |
} |
||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
|||
// There was no info found if there's no country field, or if it's |
|||
} |
|||
// empty |
|||
var o, a = true, u = false; |
|||
if (typeof matches[1] !== 'string' || !matches[1].length) { |
|||
return { s: function() { |
|||
t = t.call(r); |
|||
}, n: function() { |
|||
var r2 = t.next(); |
|||
return a = r2.done, r2; |
|||
}, e: function(r2) { |
|||
u = true, o = r2; |
|||
}, f: function() { |
|||
try { |
|||
a || null == t.return || t.return(); |
|||
} finally { |
|||
if (u) throw o; |
|||
} |
|||
} }; |
|||
} |
|||
function _unsupportedIterableToArray(r, a) { |
|||
if (r) { |
|||
if ("string" == typeof r) return _arrayLikeToArray(r, a); |
|||
var t = {}.toString.call(r).slice(8, -1); |
|||
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; |
|||
} |
|||
} |
|||
function _arrayLikeToArray(r, a) { |
|||
(null == a || a > r.length) && (a = r.length); |
|||
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; |
|||
return n; |
|||
} |
|||
var __defProp = Object.defineProperty; |
|||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
|||
var __getOwnPropNames = Object.getOwnPropertyNames; |
|||
var __hasOwnProp = Object.prototype.hasOwnProperty; |
|||
var __export = (target, all) => { |
|||
for (var name in all) __defProp(target, name, { |
|||
get: all[name], |
|||
enumerable: true |
|||
}); |
|||
}; |
|||
var __copyProps = (to, from, except, desc) => { |
|||
if (from && typeof from === "object" || typeof from === "function") { |
|||
var _iterator = _createForOfIteratorHelper(__getOwnPropNames(from)), _step; |
|||
try { |
|||
for (_iterator.s(); !(_step = _iterator.n()).done; ) { |
|||
let key = _step.value; |
|||
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { |
|||
get: () => from[key], |
|||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable |
|||
}); |
|||
} |
|||
} catch (err) { |
|||
_iterator.e(err); |
|||
} finally { |
|||
_iterator.f(); |
|||
} |
|||
} |
|||
return to; |
|||
}; |
|||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { |
|||
value: true |
|||
}), mod); |
|||
//! src/Geo/Geo.ts |
|||
var Geo_exports = {}; |
|||
__export(Geo_exports, { |
|||
getGeoInfo: () => getGeoInfo |
|||
}); |
|||
module.exports = __toCommonJS(Geo_exports); |
|||
//! src/Geo/options.json |
|||
var defaultGeoInfo = { |
|||
countryOrArea: "", |
|||
region: "", |
|||
city: "" |
|||
}; |
|||
//! src/Geo/modules/constant.ts |
|||
var STORAGE_KEY = "GeoIP"; |
|||
//! src/Geo/Geo.ts |
|||
var getGeoInfo = /* @__PURE__ */ function() { |
|||
var _ref = _asyncToGenerator(function* () { |
|||
const storeGeoInfo = mw.storage.getObject(STORAGE_KEY); |
|||
if (storeGeoInfo) { |
|||
return storeGeoInfo; |
|||
} |
|||
try { |
|||
var _ref2, _response$country, _response$region, _response$city; |
|||
const response = yield $.getJSON("https://geo.qiuwen.net.cn"); |
|||
const geoInfo = { |
|||
countryOrArea: (_ref2 = (_response$country = response.country) !== null && _response$country !== void 0 ? _response$country : response.countryOrArea) !== null && _ref2 !== void 0 ? _ref2 : "", |
|||
region: (_response$region = response.region) !== null && _response$region !== void 0 ? _response$region : "", |
|||
city: (_response$city = response.city) !== null && _response$city !== void 0 ? _response$city : "" |
|||
}; |
|||
mw.storage.setObject(STORAGE_KEY, geoInfo, 60 * 60 * 1e3); |
|||
return geoInfo; |
|||
} catch { |
|||
return defaultGeoInfo; |
return defaultGeoInfo; |
||
} |
} |
||
}); |
|||
// Return a juicy Geo object |
|||
return function getGeoInfo2() { |
|||
return { |
|||
return _ref.apply(this, arguments); |
|||
country: matches[1], |
|||
region: (_matches$ = matches[2]) !== null && _matches$ !== void 0 ? _matches$ : '', |
|||
city: (_matches$2 = matches[3]) !== null && _matches$2 !== void 0 ? _matches$2 : '' |
|||
}; |
|||
}; |
}; |
||
}(); |
|||
/** |
|||
* Request geo data and store it in the local storage |
|||
*/ |
|||
var storeGeoInStorage = /*#__PURE__*/function () { |
|||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() { |
|||
var response, data, parts, storageValue; |
|||
return _regeneratorRuntime().wrap(function _callee$(_context) { |
|||
while (1) switch (_context.prev = _context.next) { |
|||
case 0: |
|||
_context.prev = 0; |
|||
_context.next = 3; |
|||
return fetch('https://geo.qiuwen.net.cn'); |
|||
case 3: |
|||
response = _context.sent; |
|||
_context.next = 6; |
|||
return response.json(); |
|||
case 6: |
|||
data = _context.sent; |
|||
parts = [data.country, data.region, data.city]; |
|||
storageValue = parts.join('-'); |
|||
mw.storage.set(storageItemName, storageValue, 3600); // 1 hour |
|||
// Return Geo object |
|||
return _context.abrupt("return", parseStorageValue(storageValue)); |
|||
case 13: |
|||
_context.prev = 13; |
|||
_context.t0 = _context["catch"](0); |
|||
return _context.abrupt("return", defaultGeoInfo); |
|||
case 16: |
|||
case "end": |
|||
return _context.stop(); |
|||
} |
|||
}, _callee, null, [[0, 13]]); |
|||
})); |
|||
return function storeGeoInStorage() { |
|||
return _ref.apply(this, arguments); |
|||
}; |
|||
}(); |
|||
window.Geo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { |
|||
return _regeneratorRuntime().wrap(function _callee2$(_context2) { |
|||
while (1) switch (_context2.prev = _context2.next) { |
|||
case 0: |
|||
_context2.next = 2; |
|||
return storeGeoInStorage(); |
|||
case 2: |
|||
return _context2.abrupt("return", _context2.sent); |
|||
case 3: |
|||
case "end": |
|||
return _context2.stop(); |
|||
} |
|||
}, _callee2); |
|||
})); |
|||
})(); |
})(); |
||
/* </nowiki> */ |
/* </nowiki> */ |
||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsic3JjL0dlby9HZW8udHMiLCAic3JjL0dlby9vcHRpb25zLmpzb24iLCAic3JjL0dlby9tb2R1bGVzL2NvbnN0YW50LnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyJpbXBvcnQgKiBhcyBPUFRJT05TIGZyb20gJy4vb3B0aW9ucy5qc29uJztcbmltcG9ydCB0eXBlIHtHZW9JbmZvfSBmcm9tICcuL21vZHVsZXMvdHlwZXMnO1xuaW1wb3J0IHtTVE9SQUdFX0tFWX0gZnJvbSAnLi9tb2R1bGVzL2NvbnN0YW50JztcblxuY29uc3QgZ2V0R2VvSW5mbyA9IGFzeW5jICgpOiBQcm9taXNlPEdlb0luZm8+ID0+IHtcblx0Y29uc3Qgc3RvcmVHZW9JbmZvID0gbXcuc3RvcmFnZS5nZXRPYmplY3QoU1RPUkFHRV9LRVkpIGFzIEdlb0luZm8gfCBudWxsO1xuXHRpZiAoc3RvcmVHZW9JbmZvKSB7XG5cdFx0cmV0dXJuIHN0b3JlR2VvSW5mbztcblx0fVxuXG5cdHRyeSB7XG5cdFx0Y29uc3QgcmVzcG9uc2UgPSAoYXdhaXQgJC5nZXRKU09OKCdodHRwczovL2dlby5xaXV3ZW4ubmV0LmNuJykpIGFzIFBhcnRpYWw8R2VvSW5mbz4gJiB7XG5cdFx0XHRjb3VudHJ5Pzogc3RyaW5nO1xuXHRcdH07XG5cdFx0Y29uc3QgZ2VvSW5mbzogR2VvSW5mbyA9IHtcblx0XHRcdGNvdW50cnlPckFyZWE6IHJlc3BvbnNlLmNvdW50cnkgPz8gcmVzcG9uc2UuY291bnRyeU9yQXJlYSA/PyAnJyxcblx0XHRcdHJlZ2lvbjogcmVzcG9uc2UucmVnaW9uID8/ICcnLFxuXHRcdFx0Y2l0eTogcmVzcG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JfcmVmMiIsICJfcmVzcG9uc2UkY291bnRyeSIsICJfcmVzcG9uc2UkcmVnaW9uIiwgIl9yZXNwb25zZSRjaXR5IiwgInJlc3BvbnNlIiwgIiQiLCAiZ2V0SlNPTiIsICJnZW9JbmZvIiwgImNvdW50cnkiLCAic2V0T2JqZWN0IiwgImFwcGx5IiwgImFyZ3VtZW50cyJdCn0K |
2024年5月31日 (五) 15:57的最新版本
/**
* SPDX-License-Identifier: CC-BY-SA-4.0
* _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}'
*
* @source {@link https://github.com/TopRealm/YsArchives-Gadgets/tree/master/src/Geo}
* @license CC-BY-SA-4.0 {@link https://youshou.wiki/wiki/H:CC-BY-SA-4.0}
*/
/**
* +------------------------------------------------------------+
* | === WARNING: GLOBAL GADGET FILE === |
* +------------------------------------------------------------+
* | All changes should be made in the repository, |
* | otherwise they will be lost. |
* +------------------------------------------------------------+
* | Changes to this page may affect many users. |
* | Please discuss changes by opening an issue before editing. |
* +------------------------------------------------------------+
*/
/* <nowiki> */
(() => {
"use strict";
// dist/Geo/Geo.js
function asyncGeneratorStep(n, t, e, r, o, a, c) {
try {
var i = n[a](c), u = i.value;
} catch (n2) {
return void e(n2);
}
i.done ? t(u) : Promise.resolve(u).then(r, o);
}
function _asyncToGenerator(n) {
return function() {
var t = this, e = arguments;
return new Promise(function(r, o) {
var a = n.apply(t, e);
function _next(n2) {
asyncGeneratorStep(a, r, o, _next, _throw, "next", n2);
}
function _throw(n2) {
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n2);
}
_next(void 0);
});
};
}
function _createForOfIteratorHelper(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
t && (r = t);
var n = 0, F = function() {
};
return { s: F, n: function() {
return n >= r.length ? { done: true } : { done: false, value: r[n++] };
}, e: function(r2) {
throw r2;
}, f: F };
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var o, a = true, u = false;
return { s: function() {
t = t.call(r);
}, n: function() {
var r2 = t.next();
return a = r2.done, r2;
}, e: function(r2) {
u = true, o = r2;
}, f: function() {
try {
a || null == t.return || t.return();
} finally {
if (u) throw o;
}
} };
}
function _unsupportedIterableToArray(r, a) {
if (r) {
if ("string" == typeof r) return _arrayLikeToArray(r, a);
var t = {}.toString.call(r).slice(8, -1);
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
}
}
function _arrayLikeToArray(r, a) {
(null == a || a > r.length) && (a = r.length);
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
return n;
}
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
var _iterator = _createForOfIteratorHelper(__getOwnPropNames(from)), _step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done; ) {
let key = _step.value;
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
//! src/Geo/Geo.ts
var Geo_exports = {};
__export(Geo_exports, {
getGeoInfo: () => getGeoInfo
});
module.exports = __toCommonJS(Geo_exports);
//! src/Geo/options.json
var defaultGeoInfo = {
countryOrArea: "",
region: "",
city: ""
};
//! src/Geo/modules/constant.ts
var STORAGE_KEY = "GeoIP";
//! src/Geo/Geo.ts
var getGeoInfo = /* @__PURE__ */ function() {
var _ref = _asyncToGenerator(function* () {
const storeGeoInfo = mw.storage.getObject(STORAGE_KEY);
if (storeGeoInfo) {
return storeGeoInfo;
}
try {
var _ref2, _response$country, _response$region, _response$city;
const response = yield $.getJSON("https://geo.qiuwen.net.cn");
const geoInfo = {
countryOrArea: (_ref2 = (_response$country = response.country) !== null && _response$country !== void 0 ? _response$country : response.countryOrArea) !== null && _ref2 !== void 0 ? _ref2 : "",
region: (_response$region = response.region) !== null && _response$region !== void 0 ? _response$region : "",
city: (_response$city = response.city) !== null && _response$city !== void 0 ? _response$city : ""
};
mw.storage.setObject(STORAGE_KEY, geoInfo, 60 * 60 * 1e3);
return geoInfo;
} catch {
return defaultGeoInfo;
}
});
return function getGeoInfo2() {
return _ref.apply(this, arguments);
};
}();
})();
/* </nowiki> */
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsic3JjL0dlby9HZW8udHMiLCAic3JjL0dlby9vcHRpb25zLmpzb24iLCAic3JjL0dlby9tb2R1bGVzL2NvbnN0YW50LnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyJpbXBvcnQgKiBhcyBPUFRJT05TIGZyb20gJy4vb3B0aW9ucy5qc29uJztcbmltcG9ydCB0eXBlIHtHZW9JbmZvfSBmcm9tICcuL21vZHVsZXMvdHlwZXMnO1xuaW1wb3J0IHtTVE9SQUdFX0tFWX0gZnJvbSAnLi9tb2R1bGVzL2NvbnN0YW50JztcblxuY29uc3QgZ2V0R2VvSW5mbyA9IGFzeW5jICgpOiBQcm9taXNlPEdlb0luZm8+ID0+IHtcblx0Y29uc3Qgc3RvcmVHZW9JbmZvID0gbXcuc3RvcmFnZS5nZXRPYmplY3QoU1RPUkFHRV9LRVkpIGFzIEdlb0luZm8gfCBudWxsO1xuXHRpZiAoc3RvcmVHZW9JbmZvKS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