边读边看图

功能一览:1、图文对照: 双击把图片固定在页面上,同时支持缩放、移动功能,便于图文对照阅读; 2、图片背景图: 使用浏览器查看在线图片或本地图片时,增加页面背景图,以便清晰显示当前图片轮廓 3、命名链接:打开链接方式,总是以命名的新窗口,跳转同一个链接页面,只激活,不刷新;4、快捷链接:点击链接文本时,跳转相应链接页面;5、鼠标选中文字后,(0.5秒内)立马松开左键,自动复制文字;反之,保持鼠标不移动超过 0.5秒后再松开,不会复制文字; 6、一键复制代码块:鼠标悬浮代码块后,点击显示的红色边框,复制到剪贴板 7、CSDN:仅在主动触发登录时,显示登录弹层 【最后:1、localStorage中,支持关闭某一特定功能】

Version vom 14.11.2024. Aktuellste Version

  1. // ==UserScript==
  2. // @name 边读边看图
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.8.75
  5. // @description 功能一览:1、图文对照: 双击把图片固定在页面上,同时支持缩放、移动功能,便于图文对照阅读; 2、图片背景图: 使用浏览器查看在线图片或本地图片时,增加页面背景图,以便清晰显示当前图片轮廓 3、命名链接:打开链接方式,总是以命名的新窗口,跳转同一个链接页面,只激活,不刷新;4、快捷链接:点击链接文本时,跳转相应链接页面;5、鼠标选中文字后,(0.5秒内)立马松开左键,自动复制文字;反之,保持鼠标不移动超过 0.5秒后再松开,不会复制文字; 6、一键复制代码块:鼠标悬浮代码块后,点击显示的红色边框,复制到剪贴板 7、CSDN:仅在主动触发登录时,显示登录弹层 【最后:1、localStorage中,支持关闭某一特定功能】
  6. // @author Enjoy
  7. // @icon https://foruda.gitee.com/avatar/1698283059572409586/4867929_enjoy_li_1698283059.png!avatar200
  8. // @match *://*/*
  9. // @match file:///*
  10. // @exclude *localhost*
  11. // @grant GM_addElement
  12. // @grant GM_setClipboard
  13. // @license GPL License
  14. // 函数文档 https://www.tampermonkey.net/documentation.php#api:GM_addElement
  15. // @homepageURL https://greasyfork.org/zh-CN/scripts/456560
  16. // ==/UserScript==
  17.  
  18. /******/ (() => { // webpackBootstrap
  19. /******/ var __webpack_modules__ = ({
  20.  
  21. /***/ 342:
  22. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  23.  
  24. var _typeof = (__webpack_require__(882)["default"]);
  25. function _regeneratorRuntime() {
  26. "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
  27. module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
  28. return e;
  29. }, module.exports.__esModule = true, module.exports["default"] = module.exports;
  30. var t,
  31. e = {},
  32. r = Object.prototype,
  33. n = r.hasOwnProperty,
  34. o = Object.defineProperty || function (t, e, r) {
  35. t[e] = r.value;
  36. },
  37. i = "function" == typeof Symbol ? Symbol : {},
  38. a = i.iterator || "@@iterator",
  39. c = i.asyncIterator || "@@asyncIterator",
  40. u = i.toStringTag || "@@toStringTag";
  41. function define(t, e, r) {
  42. return Object.defineProperty(t, e, {
  43. value: r,
  44. enumerable: !0,
  45. configurable: !0,
  46. writable: !0
  47. }), t[e];
  48. }
  49. try {
  50. define({}, "");
  51. } catch (t) {
  52. define = function define(t, e, r) {
  53. return t[e] = r;
  54. };
  55. }
  56. function wrap(t, e, r, n) {
  57. var i = e && e.prototype instanceof Generator ? e : Generator,
  58. a = Object.create(i.prototype),
  59. c = new Context(n || []);
  60. return o(a, "_invoke", {
  61. value: makeInvokeMethod(t, r, c)
  62. }), a;
  63. }
  64. function tryCatch(t, e, r) {
  65. try {
  66. return {
  67. type: "normal",
  68. arg: t.call(e, r)
  69. };
  70. } catch (t) {
  71. return {
  72. type: "throw",
  73. arg: t
  74. };
  75. }
  76. }
  77. e.wrap = wrap;
  78. var h = "suspendedStart",
  79. l = "suspendedYield",
  80. f = "executing",
  81. s = "completed",
  82. y = {};
  83. function Generator() {}
  84. function GeneratorFunction() {}
  85. function GeneratorFunctionPrototype() {}
  86. var p = {};
  87. define(p, a, function () {
  88. return this;
  89. });
  90. var d = Object.getPrototypeOf,
  91. v = d && d(d(values([])));
  92. v && v !== r && n.call(v, a) && (p = v);
  93. var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
  94. function defineIteratorMethods(t) {
  95. ["next", "throw", "return"].forEach(function (e) {
  96. define(t, e, function (t) {
  97. return this._invoke(e, t);
  98. });
  99. });
  100. }
  101. function AsyncIterator(t, e) {
  102. function invoke(r, o, i, a) {
  103. var c = tryCatch(t[r], t, o);
  104. if ("throw" !== c.type) {
  105. var u = c.arg,
  106. h = u.value;
  107. return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
  108. invoke("next", t, i, a);
  109. }, function (t) {
  110. invoke("throw", t, i, a);
  111. }) : e.resolve(h).then(function (t) {
  112. u.value = t, i(u);
  113. }, function (t) {
  114. return invoke("throw", t, i, a);
  115. });
  116. }
  117. a(c.arg);
  118. }
  119. var r;
  120. o(this, "_invoke", {
  121. value: function value(t, n) {
  122. function callInvokeWithMethodAndArg() {
  123. return new e(function (e, r) {
  124. invoke(t, n, e, r);
  125. });
  126. }
  127. return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  128. }
  129. });
  130. }
  131. function makeInvokeMethod(e, r, n) {
  132. var o = h;
  133. return function (i, a) {
  134. if (o === f) throw Error("Generator is already running");
  135. if (o === s) {
  136. if ("throw" === i) throw a;
  137. return {
  138. value: t,
  139. done: !0
  140. };
  141. }
  142. for (n.method = i, n.arg = a;;) {
  143. var c = n.delegate;
  144. if (c) {
  145. var u = maybeInvokeDelegate(c, n);
  146. if (u) {
  147. if (u === y) continue;
  148. return u;
  149. }
  150. }
  151. if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
  152. if (o === h) throw o = s, n.arg;
  153. n.dispatchException(n.arg);
  154. } else "return" === n.method && n.abrupt("return", n.arg);
  155. o = f;
  156. var p = tryCatch(e, r, n);
  157. if ("normal" === p.type) {
  158. if (o = n.done ? s : l, p.arg === y) continue;
  159. return {
  160. value: p.arg,
  161. done: n.done
  162. };
  163. }
  164. "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
  165. }
  166. };
  167. }
  168. function maybeInvokeDelegate(e, r) {
  169. var n = r.method,
  170. o = e.iterator[n];
  171. if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
  172. var i = tryCatch(o, e.iterator, r.arg);
  173. if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
  174. var a = i.arg;
  175. return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
  176. }
  177. function pushTryEntry(t) {
  178. var e = {
  179. tryLoc: t[0]
  180. };
  181. 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
  182. }
  183. function resetTryEntry(t) {
  184. var e = t.completion || {};
  185. e.type = "normal", delete e.arg, t.completion = e;
  186. }
  187. function Context(t) {
  188. this.tryEntries = [{
  189. tryLoc: "root"
  190. }], t.forEach(pushTryEntry, this), this.reset(!0);
  191. }
  192. function values(e) {
  193. if (e || "" === e) {
  194. var r = e[a];
  195. if (r) return r.call(e);
  196. if ("function" == typeof e.next) return e;
  197. if (!isNaN(e.length)) {
  198. var o = -1,
  199. i = function next() {
  200. for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
  201. return next.value = t, next.done = !0, next;
  202. };
  203. return i.next = i;
  204. }
  205. }
  206. throw new TypeError(_typeof(e) + " is not iterable");
  207. }
  208. return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
  209. value: GeneratorFunctionPrototype,
  210. configurable: !0
  211. }), o(GeneratorFunctionPrototype, "constructor", {
  212. value: GeneratorFunction,
  213. configurable: !0
  214. }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
  215. var e = "function" == typeof t && t.constructor;
  216. return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
  217. }, e.mark = function (t) {
  218. return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
  219. }, e.awrap = function (t) {
  220. return {
  221. __await: t
  222. };
  223. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
  224. return this;
  225. }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
  226. void 0 === i && (i = Promise);
  227. var a = new AsyncIterator(wrap(t, r, n, o), i);
  228. return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
  229. return t.done ? t.value : a.next();
  230. });
  231. }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
  232. return this;
  233. }), define(g, "toString", function () {
  234. return "[object Generator]";
  235. }), e.keys = function (t) {
  236. var e = Object(t),
  237. r = [];
  238. for (var n in e) r.push(n);
  239. return r.reverse(), function next() {
  240. for (; r.length;) {
  241. var t = r.pop();
  242. if (t in e) return next.value = t, next.done = !1, next;
  243. }
  244. return next.done = !0, next;
  245. };
  246. }, e.values = values, Context.prototype = {
  247. constructor: Context,
  248. reset: function reset(e) {
  249. if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
  250. },
  251. stop: function stop() {
  252. this.done = !0;
  253. var t = this.tryEntries[0].completion;
  254. if ("throw" === t.type) throw t.arg;
  255. return this.rval;
  256. },
  257. dispatchException: function dispatchException(e) {
  258. if (this.done) throw e;
  259. var r = this;
  260. function handle(n, o) {
  261. return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
  262. }
  263. for (var o = this.tryEntries.length - 1; o >= 0; --o) {
  264. var i = this.tryEntries[o],
  265. a = i.completion;
  266. if ("root" === i.tryLoc) return handle("end");
  267. if (i.tryLoc <= this.prev) {
  268. var c = n.call(i, "catchLoc"),
  269. u = n.call(i, "finallyLoc");
  270. if (c && u) {
  271. if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
  272. if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
  273. } else if (c) {
  274. if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
  275. } else {
  276. if (!u) throw Error("try statement without catch or finally");
  277. if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
  278. }
  279. }
  280. }
  281. },
  282. abrupt: function abrupt(t, e) {
  283. for (var r = this.tryEntries.length - 1; r >= 0; --r) {
  284. var o = this.tryEntries[r];
  285. if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
  286. var i = o;
  287. break;
  288. }
  289. }
  290. i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
  291. var a = i ? i.completion : {};
  292. return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
  293. },
  294. complete: function complete(t, e) {
  295. if ("throw" === t.type) throw t.arg;
  296. return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
  297. },
  298. finish: function finish(t) {
  299. for (var e = this.tryEntries.length - 1; e >= 0; --e) {
  300. var r = this.tryEntries[e];
  301. if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
  302. }
  303. },
  304. "catch": function _catch(t) {
  305. for (var e = this.tryEntries.length - 1; e >= 0; --e) {
  306. var r = this.tryEntries[e];
  307. if (r.tryLoc === t) {
  308. var n = r.completion;
  309. if ("throw" === n.type) {
  310. var o = n.arg;
  311. resetTryEntry(r);
  312. }
  313. return o;
  314. }
  315. }
  316. throw Error("illegal catch attempt");
  317. },
  318. delegateYield: function delegateYield(e, r, n) {
  319. return this.delegate = {
  320. iterator: values(e),
  321. resultName: r,
  322. nextLoc: n
  323. }, "next" === this.method && (this.arg = t), y;
  324. }
  325. }, e;
  326. }
  327. module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
  328.  
  329. /***/ }),
  330.  
  331. /***/ 882:
  332. /***/ ((module) => {
  333.  
  334. function _typeof(o) {
  335. "@babel/helpers - typeof";
  336.  
  337. return module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  338. return typeof o;
  339. } : function (o) {
  340. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  341. }, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof(o);
  342. }
  343. module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
  344.  
  345. /***/ }),
  346.  
  347. /***/ 501:
  348. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  349.  
  350. // TODO(Babel 8): Remove this file.
  351.  
  352. var runtime = __webpack_require__(342)();
  353. module.exports = runtime;
  354.  
  355. // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
  356. try {
  357. regeneratorRuntime = runtime;
  358. } catch (accidentalStrictMode) {
  359. if (typeof globalThis === "object") {
  360. globalThis.regeneratorRuntime = runtime;
  361. } else {
  362. Function("r", "regeneratorRuntime = r")(runtime);
  363. }
  364. }
  365.  
  366.  
  367. /***/ })
  368.  
  369. /******/ });
  370. /************************************************************************/
  371. /******/ // The module cache
  372. /******/ var __webpack_module_cache__ = {};
  373. /******/
  374. /******/ // The require function
  375. /******/ function __webpack_require__(moduleId) {
  376. /******/ // Check if module is in cache
  377. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  378. /******/ if (cachedModule !== undefined) {
  379. /******/ return cachedModule.exports;
  380. /******/ }
  381. /******/ // Create a new module (and put it into the cache)
  382. /******/ var module = __webpack_module_cache__[moduleId] = {
  383. /******/ // no module.id needed
  384. /******/ // no module.loaded needed
  385. /******/ exports: {}
  386. /******/ };
  387. /******/
  388. /******/ // Execute the module function
  389. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  390. /******/
  391. /******/ // Return the exports of the module
  392. /******/ return module.exports;
  393. /******/ }
  394. /******/
  395. /************************************************************************/
  396. /******/ /* webpack/runtime/compat get default export */
  397. /******/ (() => {
  398. /******/ // getDefaultExport function for compatibility with non-harmony modules
  399. /******/ __webpack_require__.n = (module) => {
  400. /******/ var getter = module && module.__esModule ?
  401. /******/ () => (module['default']) :
  402. /******/ () => (module);
  403. /******/ __webpack_require__.d(getter, { a: getter });
  404. /******/ return getter;
  405. /******/ };
  406. /******/ })();
  407. /******/
  408. /******/ /* webpack/runtime/define property getters */
  409. /******/ (() => {
  410. /******/ // define getter functions for harmony exports
  411. /******/ __webpack_require__.d = (exports, definition) => {
  412. /******/ for(var key in definition) {
  413. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  414. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  415. /******/ }
  416. /******/ }
  417. /******/ };
  418. /******/ })();
  419. /******/
  420. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  421. /******/ (() => {
  422. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  423. /******/ })();
  424. /******/
  425. /************************************************************************/
  426. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  427. (() => {
  428. "use strict";
  429.  
  430. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/typeof.js
  431. function typeof_typeof(o) {
  432. "@babel/helpers - typeof";
  433.  
  434. return typeof_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  435. return typeof o;
  436. } : function (o) {
  437. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  438. }, typeof_typeof(o);
  439. }
  440.  
  441. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/toPrimitive.js
  442.  
  443. function toPrimitive(t, r) {
  444. if ("object" != typeof_typeof(t) || !t) return t;
  445. var e = t[Symbol.toPrimitive];
  446. if (void 0 !== e) {
  447. var i = e.call(t, r || "default");
  448. if ("object" != typeof_typeof(i)) return i;
  449. throw new TypeError("@@toPrimitive must return a primitive value.");
  450. }
  451. return ("string" === r ? String : Number)(t);
  452. }
  453.  
  454. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/toPropertyKey.js
  455.  
  456.  
  457. function toPropertyKey(t) {
  458. var i = toPrimitive(t, "string");
  459. return "symbol" == typeof_typeof(i) ? i : i + "";
  460. }
  461.  
  462. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/createClass.js
  463.  
  464. function _defineProperties(e, r) {
  465. for (var t = 0; t < r.length; t++) {
  466. var o = r[t];
  467. o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, toPropertyKey(o.key), o);
  468. }
  469. }
  470. function createClass_createClass(e, r, t) {
  471. return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
  472. writable: !1
  473. }), e;
  474. }
  475.  
  476. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/classCallCheck.js
  477. function classCallCheck_classCallCheck(a, n) {
  478. if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
  479. }
  480.  
  481. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/defineProperty.js
  482.  
  483. function defineProperty_defineProperty(e, r, t) {
  484. return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
  485. value: t,
  486. enumerable: !0,
  487. configurable: !0,
  488. writable: !0
  489. }) : e[r] = t, e;
  490. }
  491.  
  492. // EXTERNAL MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/regenerator/index.js
  493. var regenerator = __webpack_require__(501);
  494. var regenerator_default = /*#__PURE__*/__webpack_require__.n(regenerator);
  495. ;// CONCATENATED MODULE: ./tools/GM.js
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502. function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
  503. function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { defineProperty_defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
  504. /** @描述 函数文档 https://www.tampermonkey.net/documentation.php#api:GM_addElement */
  505.  
  506. /**
  507. * @description 创建element
  508. * @export
  509. * @param {*} tag
  510. * @param {*} [options={}]
  511. * @param {*} [win=window]
  512. * @returns {*}
  513. */
  514. function createElement(tag) {
  515. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  516. var win = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : window;
  517. if (!win.GM_createElement) {
  518. win.GM_createElement = GM_createElement;
  519. }
  520. return GM_createElement(tag, options);
  521. /**
  522. * @param {*} tag
  523. * @param {*} options {
  524. * idPrefix = `enjoy_${ENV_CRX}_${tag}`,
  525. * el = 'html',
  526. * autoInsert = true,
  527. * randomType = 'single',
  528. * id = '',
  529. * addPrefix = true,
  530. * insertType = tag === 'style' ? 'appendChild' : 'prepend',
  531. * }
  532. * @returns {*} dom
  533. */
  534. function GM_createElement(tag, options) {
  535. var _options$idPrefix = options.idPrefix,
  536. idPrefix = _options$idPrefix === void 0 ? "enjoy_".concat("ImgPreview", "_").concat(tag, "_") : _options$idPrefix,
  537. _options$el = options.el,
  538. el = _options$el === void 0 ? 'html' : _options$el,
  539. _options$autoInsert = options.autoInsert,
  540. autoInsert = _options$autoInsert === void 0 ? true : _options$autoInsert,
  541. _options$randomType = options.randomType,
  542. randomType = _options$randomType === void 0 ? 'single' : _options$randomType,
  543. _options$id = options.id,
  544. id = _options$id === void 0 ? '' : _options$id,
  545. _options$addPrefix = options.addPrefix,
  546. addPrefix = _options$addPrefix === void 0 ? true : _options$addPrefix,
  547. _options$insertType = options.insertType,
  548. insertType = _options$insertType === void 0 ? tag === 'style' ? 'appendChild' : 'prepend' : _options$insertType;
  549. if (addPrefix) {
  550. id = "".concat(idPrefix).concat(id);
  551. }
  552. if (randomType !== 'single') {
  553. id = "".concat(id, "_").concat(Math.floor(Math.random() * 1000));
  554. }
  555. options.id = id;
  556. var dom = document.querySelector("#".concat(id));
  557. if (!dom) {
  558. dom = document.createElement(tag);
  559. }
  560. for (var key in options) {
  561. if (Object.hasOwnProperty.call(options, key) && key !== 'el') {
  562. dom[key] = options[key];
  563. }
  564. }
  565. if (autoInsert) {
  566. if (typeof el === 'string') {
  567. el = document.querySelector(el);
  568. }
  569.  
  570. //insertType prepend | appendChild
  571. el[insertType](dom);
  572. }
  573. return dom;
  574. }
  575. }
  576.  
  577. /** @描述 是否匹配到目标url */
  578. function isMatched() {
  579. var urls = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  580. var currentUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : location.href;
  581. if (typeof urls === 'string') {
  582. urls = [urls];
  583. }
  584. return !!urls.find(function (regUrl) {
  585. return new RegExp(regUrl).test(currentUrl);
  586. });
  587. }
  588. function prependMetaUF8() {
  589. return document.querySelector('meta[charset="UTF-8"]') || createElement('meta', {
  590. charset: 'utf-8'
  591. });
  592. }
  593.  
  594. /**
  595. * @description doCopy 复制文本到剪贴板
  596. * @export
  597. * @param {*} text
  598. */
  599. function doCopy(text) {
  600. var _navigator;
  601. if (!text) return console.warn('doCopy 参数为空');
  602. if (document.hasFocus() && (_navigator = navigator) !== null && _navigator !== void 0 && (_navigator = _navigator.clipboard) !== null && _navigator !== void 0 && _navigator.writeText) {
  603. // localhost、127.0.0.1或者https中才能正常使用
  604. // 读取剪贴板
  605. // navigator.clipboard.readText().then((clipText) => {console.log('clipText=',clipText)})
  606.  
  607. // 写入剪贴板
  608. navigator.clipboard.writeText(text)["catch"](function (err) {
  609. return console.error("clipboard.writeText\uFF1A".concat(err));
  610. });
  611. return;
  612. }
  613. var textarea = document.createElement('textarea');
  614. document.body.appendChild(textarea);
  615. textarea.value = text;
  616. textarea.select();
  617. document.execCommand('Copy');
  618. setTimeout(function () {
  619. textarea.remove();
  620. }, 1000);
  621. }
  622.  
  623. /**
  624. * 检测element元素的可见性,即 非display:none
  625. * @param {*} element
  626. * @returns {*} {Boolean}
  627. */
  628. function checkVisibility(element) {
  629. if (element.checkVisibility) {
  630. return element.checkVisibility();
  631. }
  632. return !!element.offsetParent;
  633. }
  634. /**
  635. * @description 创建element的提示
  636. * @export
  637. * @param {*} [options={}]
  638. * @returns {*}
  639. */
  640. function createElementTipFn() {
  641. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  642. var _options$setTimeoutSt = options.setTimeoutStep,
  643. setTimeoutStep = _options$setTimeoutSt === void 0 ? 1000 : _options$setTimeoutSt,
  644. _options$backgroundCo = options.backgroundColors,
  645. backgroundColors = _options$backgroundCo === void 0 ? {
  646. warn: 'rgb(181 156 51 / 60%)',
  647. success: 'rgb(3 113 3 / 60%)',
  648. error: 'rgb(165 2 2 / 60%)',
  649. info: 'rgb(67 62 62 / 60%)'
  650. } : _options$backgroundCo,
  651. _options$color = options.color,
  652. color = _options$color === void 0 ? '#ffffff' : _options$color,
  653. _options$opacity = options.opacity,
  654. opacity = _options$opacity === void 0 ? 1 : _options$opacity;
  655. var setTimeoutStamp = 0;
  656. return function createElementTip() {
  657. var configs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  658. var content = configs.content,
  659. e = configs.e,
  660. _configs$type = configs.type,
  661. type = _configs$type === void 0 ? 'info' : _configs$type,
  662. _configs$tagType = configs.tagType,
  663. tagType = _configs$tagType === void 0 ? 'span' : _configs$tagType;
  664. if (!content) return;
  665. console.log("content => %O ", content);
  666. clearTimeout(setTimeoutStamp);
  667. var contentDom = createElement(tagType, {
  668. id: 'createElementTip',
  669. innerText: content,
  670. style: "\n font-size:14px;\n font-weight:600;\n color:".concat(color, ";\n position: fixed;\n left: ").concat(numbericalInterval(e.clientX - 46), "px;\n top: ").concat(numbericalInterval(e.clientY - 35, [5, window.innerHeight - 35]), "px;\n background-color:").concat(backgroundColors[type], ";\n opacity: ").concat(opacity, ";\n border-radius: 4px;\n padding: 4px 8px;\n box-shadow:0 0 5px 0 rgb(255 255 255 / 60%) inset;\n pointer-event:none;\n z-index:").concat((Math.floor(Date.now() / 1000) + '').slice(-5), ";\n\t\t\t\t\t\tdisplay:inline-block;\n ")
  671. });
  672. setTimeoutStamp = setTimeout(function () {
  673. // contentDom.remove()
  674. contentDom.style.display = 'none';
  675. }, setTimeoutStep);
  676. };
  677. }
  678. /**
  679. * @description dom是否可编辑
  680. * @param {*} [dom=document.activeElement]
  681. * @returns {*} {boolean}
  682. */
  683.  
  684. function isContentEditableOfDOM() {
  685. var dom = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement;
  686. if (dom.tagName === 'INPUT' || dom.tagName === 'TEXTAREA') {
  687. return !dom.disabled;
  688. } else {
  689. return !!findParentElement(dom, function (dom) {
  690. return dom.contentEditable === 'true';
  691. }, null);
  692. }
  693. }
  694.  
  695. /**
  696. * @description 数字区间
  697. * @param {*} val
  698. * @param {*} [interval=[10, window.innerWidth]]
  699. * @returns {*}
  700. */
  701. function numbericalInterval(val) {
  702. var interval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [5, window.innerWidth - 130];
  703. var indexStart = interval[0];
  704. var indexEnd = interval[1];
  705. if (val < indexStart) return indexStart;
  706. if (val > indexEnd) return indexEnd;
  707. return val;
  708. }
  709.  
  710. /**
  711. * @description 可滚动的dom
  712. * @param {*} dom
  713. * @returns {*}
  714. */
  715. function findHasScrollbarDom(dom) {
  716. if (!(dom instanceof HTMLElement)) {
  717. console.warn("\u53EF\u6EDA\u52A8\u7684dom\u51FD\u6570 findHasScrollbarDom:\u53C2\u6570dom\u5FC5\u987B\u4E3Aelement\u5143\u7D20 ");
  718. return void 0;
  719. }
  720. while (dom) {
  721. if (dom.offsetHeight < dom.scrollHeight && !(window.getComputedStyle(dom).overflowY == 'visible' || window.getComputedStyle(dom).overflowY == 'hidden')) {
  722. break;
  723. }
  724. dom = dom.parentElement;
  725. }
  726. if (!dom || dom === document.body) {
  727. // 始终是 documentElement等同于window
  728. dom = document.documentElement;
  729. }
  730. console.warn("\u9875\u9762\u6EDA\u52A8\u5143\u7D20\u7684tagName: ", dom.tagName.toLocaleLowerCase(), 'dom.className:', dom.className);
  731. return dom;
  732. }
  733.  
  734. /**
  735. * @description 获取方法配置
  736. * @param {string} [key='']
  737. * @param {*} [defaultOpt={ includedUrls: [] }]
  738. * @returns {*} {Object}
  739. **/
  740. function getSettingFromLocalStorage() {
  741. var fileName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  742. var defaultOpt = arguments.length > 1 ? arguments[1] : undefined;
  743. var mergedSettingOpt = _objectSpread({
  744. runType: '0',
  745. includedUrls: [],
  746. excludeUrls: []
  747. }, defaultOpt);
  748. var fullSettingKey = "enjoy_setting";
  749. var storageData = localStorage.getItem(fullSettingKey);
  750. var fullSettings = storageData ? JSON.parse(storageData) : {};
  751. var SETTING = _objectSpread(_objectSpread({}, mergedSettingOpt), fullSettings === null || fullSettings === void 0 ? void 0 : fullSettings[fileName]);
  752. fullSettings[fileName] = SETTING;
  753. fullSettings.runTypeDest = undefined;
  754. fullSettings.instructions = "\n\u4E00\u3001\u5339\u914D\u89C4\u5219\u4F18\u5148\u7EA7\uFF1Aruntype > * > excludedUrls > includedUrls\n\u4E8C\u3001runType\u662F\u9488\u5BF9\u5728\u5F53\u524D\u57DF\u540D\u89C4\u5219\uFF1A0(\u9ED8\u8BA4\u6267\u884C\u5339\u914D\u89C4\u5219)\uFF1B1(\u5F3A\u5236\u6267\u884C,\u5373\u8DF3\u8FC7\u5339\u914D\u89C4\u5219)\uFF1B2(\u4E0D\u6267\u884C)\n";
  755. localStorage.setItem(fullSettingKey, JSON.stringify(fullSettings || {}, null, 2));
  756. return SETTING;
  757. }
  758.  
  759. /**
  760. * @description 是否执行该方法
  761. * @param {*} [settingOpt={}]
  762. * @returns {*} {Boolean}
  763. */
  764. function isExcutableBySetting() {
  765. var settingOpt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  766. var runType = settingOpt.runType,
  767. _settingOpt$excludeUr = settingOpt.excludeUrls,
  768. excludeUrls = _settingOpt$excludeUr === void 0 ? [] : _settingOpt$excludeUr,
  769. _settingOpt$includedU = settingOpt.includedUrls,
  770. includedUrls = _settingOpt$includedU === void 0 ? [] : _settingOpt$includedU;
  771. if (runType == '1') return true;
  772. if (runType == '2') return false;
  773. var HREF = location.href;
  774. if (excludeUrls !== null && excludeUrls !== void 0 && excludeUrls.length && isMatched(excludeUrls, HREF)) {
  775. return false;
  776. }
  777. if ((includedUrls === null || includedUrls === void 0 ? void 0 : includedUrls.length) === 0) return true;
  778. var findOne = isMatched(includedUrls, HREF);
  779. return !!findOne;
  780. }
  781.  
  782. /**
  783. * @description 是否不执行
  784. * @param {String} fileName
  785. * @param {Object} settingOpt { excludeUrls: [ ],feature:"feature",includedUrls: [ ],name: "name",runType: "0",}
  786. * @returns {Boolean}
  787. */
  788. function codeIsNotExcutable(fileName, settingOpt) {
  789. try {
  790. // logSettingOptWithColor()
  791. var setting = getSettingFromLocalStorage(fileName, settingOpt);
  792. return _objectSpread({
  793. notExcutable: !isExcutableBySetting(setting)
  794. }, setting);
  795. } catch (error) {
  796. // base64路径下,禁用storage
  797. console.error(error);
  798. return _objectSpread({
  799. notExcutable: true
  800. }, settingOpt);
  801. }
  802. }
  803.  
  804. /**
  805. * @description 彩色打印
  806. * @param {string} [key='enjoy_setting']
  807. */
  808. function logSettingOptWithColor(key) {
  809. var dataKey = 'is-log-of-enjoy';
  810. if (true) return;
  811. // if (document.body.getAttribute(dataKey)) return
  812. document.body.setAttribute(dataKey, '1');
  813.  
  814. // clearTimeout(window.EnjoyColorLogTimer || 0)
  815. window.EnjoyColorLogTimer = setTimeout(function () {
  816. var _key;
  817. (_key = key) !== null && _key !== void 0 ? _key : key = 'enjoy_setting';
  818. var SETTINGS = JSON.parse(localStorage[key] || '{}');
  819. console.log("%c\uD83D\uDC47 ".concat(key, " \u8BBE\u7F6E\u53C2\u6570\uFF1A"), 'background:#4e0ab780;color:#fff;', '\n', SETTINGS, "\n\nkeyNameList:", Object.keys(SETTINGS));
  820. console.log("%c\uD83D\uDC47\u81EA\u5B9A\u4E49\u914D\u7F6E\uFF0C\u4EE3\u7801\u5982\u4E0B\uFF1A", 'background:#4e0ab747;color:#fff;', "\n\u5F53\u524D\u57DF\u540D\u4E0B\u662F\u5426\u8FD0\u884C\u76F8\u5E94\u51FD\u6570,", "\n\u8BBE\u7F6ErunType(1\u3001\u5F3A\u5236\u8FD0\u884C\uFF1B2\u3001\u4E0D\u8FD0\u884C)\u3002", '\n\n', modifyRuntype.toString(), "\nmodifyRuntype('keyName',2)");
  821. }, 3 * 1000);
  822. }
  823. /**
  824. * @description 修改运行机制
  825. * @export
  826. * @param {string} keyName
  827. * @param {0|1|2} runType
  828. */
  829. function modifyRuntype(keyName, runType) {
  830. var keyOfSETTINGS = 'enjoy_setting';
  831. var SETTINGS = JSON.parse(localStorage.getItem(keyOfSETTINGS) || '{}');
  832. if (!SETTINGS[keyName]) return;
  833. SETTINGS[keyName].runType = runType || 2;
  834. localStorage.setItem(keyOfSETTINGS, JSON.stringify(SETTINGS, null, 2));
  835. }
  836.  
  837. /**
  838. * @description 查找特定条件的父级元素
  839. * @export
  840. * @param {Element} dom
  841. * @param {Function} callback
  842. * @param {Element} [defaultVal=document.documentElement]
  843. * @returns {Element}
  844. */
  845. function findParentElement(dom, callback) {
  846. var defaultVal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.documentElement;
  847. if (!(dom instanceof HTMLElement)) {
  848. console.warn("\u67E5\u627E\u7279\u5B9A\u6761\u4EF6\u7684\u7236\u7EA7\u5143\u7D20\u51FD\u6570 findParentElement:\u53C2\u6570dom\u5FC5\u987B\u4E3Aelement\u5143\u7D20 ");
  849. return void 0;
  850. }
  851. while (dom) {
  852. if (callback(dom)) {
  853. break;
  854. }
  855. dom = dom.parentElement;
  856. }
  857. if (!dom || dom === document.body) {
  858. // 始终是 documentElement等同于window
  859. dom = defaultVal;
  860. }
  861. return dom;
  862. }
  863.  
  864. /** 原生横向滚动条 吸附 页面底部 */
  865. var StickyHorizontalNativeScrollBar = /*#__PURE__*/(/* unused pure expression or super */ null && (_createClass(function StickyHorizontalNativeScrollBar() {
  866. var _this = this;
  867. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  868. _classCallCheck(this, StickyHorizontalNativeScrollBar);
  869. /** 创建滚轴组件元素 */
  870. _defineProperty(this, "createScrollbar", function () {
  871. var style = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  872. if (_this.scrollbar) return _this.scrollbar;
  873. var timer = Date.now();
  874. _this.thumbId = "thumb".concat(timer);
  875. _this.scrollbarId = "scrollbar".concat(timer);
  876. _this.scrollbar = document.createElement('div');
  877. _this.scrollbar.setAttribute('id', _this.scrollbarId);
  878. _this.scrollbar.innerHTML = "\n\t\t\t<style>\n\t\t\t\t#".concat(_this.scrollbarId, " {\n\t\t\t\t\tposition: sticky;\n\t\t\t\t\twidth: 100%;\n\t\t\t\t\tbox-shadow: 0 15px 0 0 #fff;\n\t\t\t\t\tbottom: 8px;\n\t\t\t\t\tleft: 0;\n\t\t\t\t\theight: 17px;\n\t\t\t\t\toverflow-x: auto;\n\t\t\t\t\toverflow-y: hidden;\n\t\t\t\t\tmargin-top: -17px;\n\t\t\t\t\tz-index: 3;\n\t\t\t\t\t").concat(style, "\n\t\t\t\t}\n\t\t\t</style>\n\t\t\t<div id=\"").concat(_this.thumbId, "\" style=\"height: 1px;\"></div>\n\t\t");
  879. });
  880. /** 把滚轴组件元素插入目标元素的后面 */
  881. _defineProperty(this, "insertScrollbar", function (el) {
  882. _this.target = el;
  883. if (typeof el === 'string') {
  884. _this.target = document.querySelector(el);
  885. }
  886. if (!_this.target) throw Error('el Dom do not exit');
  887. _this.targetParentElement = document.querySelector(el).parentElement;
  888. if (!_this.targetParentElement.querySelector("#".concat(_this.scrollbarId))) {
  889. _this.targetParentElement.insertBefore(_this.scrollbar, _this.target.nextSibling);
  890. }
  891. return _this.target;
  892. });
  893. /** 设置 滚轴组件元素尺寸 */
  894. _defineProperty(this, "setScrollbarSize", throttle(function () {
  895. _this.scrollbar.style.width = _this.target.clientWidth + 'px';
  896. _this.scrollbar.querySelector("#".concat(_this.thumbId)).style.width = _this.target.scrollWidth + 'px';
  897. }, 100));
  898. /** 监听目标元素和滚轴元素的scroll和页面resize事件 */
  899. _defineProperty(this, "onEvent", function () {
  900. _this.target.addEventListener('scroll', _this.onScrollTarget);
  901. _this.scrollbar.addEventListener('scroll', _this.onScrollScrollbar);
  902. window.addEventListener('resize', _this.setScrollbarSize);
  903. });
  904. /** 移除事件 */
  905. _defineProperty(this, "removeEvent", function () {
  906. _this.target.removeEventListener('scroll', _this.onScrollTarget);
  907. _this.scrollbar.removeEventListener('scroll', _this.onScrollScrollbar);
  908. window.removeEventListener('resize', _this.setScrollbarSize);
  909. });
  910. _defineProperty(this, "onScrollTarget", throttle(function (e) {
  911. _this.scrollbar.scrollLeft = e.target.scrollLeft;
  912. }, 100));
  913. _defineProperty(this, "onScrollScrollbar", throttle(function (e) {
  914. _this.target.scrollLeft = e.target.scrollLeft;
  915. }, 100));
  916. var _el = options.el,
  917. _options$style = options.style,
  918. _style = _options$style === void 0 ? '' : _options$style;
  919. this.createScrollbar(_style);
  920. this.insertScrollbar(_el);
  921. this.setScrollbarSize();
  922. this.onEvent();
  923. })));
  924.  
  925. /** 插入横向滚动条 */
  926. var HorizontalScrollBar = /*#__PURE__*/(/* unused pure expression or super */ null && (function () {
  927. function HorizontalScrollBar() {
  928. var _this2 = this;
  929. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  930. _classCallCheck(this, HorizontalScrollBar);
  931. /** 创建滚轴组件元素 */
  932. _defineProperty(this, "createScrollbar", function (setStyle) {
  933. if (_this2.scrollbar) return _this2.scrollbar;
  934. var timer = Date.now();
  935. _this2.scrollbarId = "scrollbar".concat(timer);
  936. _this2.scrollbar = document.createElement('div');
  937. _this2.scrollbar.setAttribute('data-part', 'scrollbar');
  938. _this2.scrollbar.setAttribute('id', _this2.scrollbarId);
  939. _this2.scrollbar.innerHTML = "\n\t\t".concat(setStyle(_this2.scrollbarId) || _this2.setDefaultStyle(_this2.scrollbarId), "\n\t\t<div data-part=\"thumb\"></div>\n\t\t");
  940. });
  941. /** 把滚轴组件元素插入目标元素的后面 */
  942. _defineProperty(this, "insertScrollbar", function (el) {
  943. _this2.target = el;
  944. if (typeof el === 'string') {
  945. _this2.target = document.querySelector(el);
  946. }
  947. if (!_this2.target) throw Error('el Dom do not exit');
  948. _this2.targetParentElement = document.querySelector(el).parentElement;
  949. if (!_this2.targetParentElement.querySelector("#".concat(_this2.scrollbarId))) {
  950. _this2.targetParentElement.insertBefore(_this2.scrollbar, _this2.target.nextSibling);
  951. }
  952. return _this2.target;
  953. });
  954. /** 根据目标元素 设置 滚轴组件元素尺寸 */
  955. _defineProperty(this, "setScrollbarSize", function () {
  956. _this2.scrollbar.style.width = _this2.target.clientWidth + 'px';
  957. _this2.thumb = _this2.scrollbar.querySelector('[data-part="thumb"]');
  958. _this2.thumb.style.width = _this2.scrollbar.clientWidth * _this2.target.clientWidth / _this2.target.scrollWidth + 'px';
  959. _this2.offsetMax = _this2.scrollbar.clientWidth - _this2.thumb.clientWidth;
  960. _this2.rate = (_this2.target.scrollWidth - _this2.target.clientWidth) / _this2.offsetMax;
  961. });
  962. /** */
  963. _defineProperty(this, "onMouseDownOfThumb", function (e) {
  964. console.log("mousedown => %O ");
  965. _this2.prePageX = e.pageX;
  966. _this2.isMousedown = true;
  967. });
  968. /** */
  969. _defineProperty(this, "onMouseUpOfWindow", function (e) {
  970. _this2.isMousedown = false;
  971. });
  972. /** */
  973. _defineProperty(this, "requestAnimationFrameCallback", function (offsetLeft) {
  974. _this2.thumb.style.left = offsetLeft + 'px';
  975. _this2.target.scrollLeft = offsetLeft * _this2.rate;
  976. });
  977. /** */
  978. _defineProperty(this, "onMousemoveOfWindow", function (e) {
  979. if (_this2.isMousedown) {
  980. var offsetLeft = Number(_this2.thumb.style.left.replace('px', '')) + Number(e.pageX - _this2.prePageX);
  981. offsetLeft = Math.max(0, offsetLeft);
  982. offsetLeft = Math.min(offsetLeft, _this2.offsetMax);
  983. _this2.requestAnimationFrameCallback(offsetLeft);
  984. _this2.prePageX = e.pageX;
  985. }
  986. });
  987. /** 监听目标元素和滚轴元素的scroll和页面resize事件 */
  988. _defineProperty(this, "onEvent", function () {
  989. _this2.thumb.addEventListener('mousedown', _this2.onMouseDownOfThumb);
  990. window.addEventListener('mouseup', _this2.onMouseUpOfWindow);
  991. window.addEventListener('mousemove', _this2.onMousemoveOfWindow);
  992. window.addEventListener('resize', _this2.setScrollbarSize);
  993. });
  994. /** 移除事件 */
  995. _defineProperty(this, "removeEvent", function () {
  996. _this2.thumb.removeEventListener('mousedown', _this2.onMouseDownOfThumb);
  997. window.removeEventListener('mouseup', _this2.onMouseUpOfWindow);
  998. window.removeEventListener('mousemove', _this2.onMousemoveOfWindow);
  999. window.removeEventListener('resize', _this2.setScrollbarSize);
  1000. });
  1001. var _el2 = options.el,
  1002. _options$setStyle = options.setStyle,
  1003. _setStyle = _options$setStyle === void 0 ? function () {
  1004. return null;
  1005. } : _options$setStyle;
  1006. this.createScrollbar(_setStyle);
  1007. this.insertScrollbar(_el2);
  1008. this.setScrollbarSize();
  1009. this.onEvent();
  1010. }
  1011. return _createClass(HorizontalScrollBar, [{
  1012. key: "setDefaultStyle",
  1013. value: function setDefaultStyle(scrollbarId) {
  1014. return "\n\t\t<style>\n\t\t\t#".concat(scrollbarId, " {\n\t\t\t\theight: 17px;\n\t\t\t\tbackground-color: #f1f1f1;\n\t\t\t\tposition: relative;\n\t\t\t}\n\t\t\t#").concat(scrollbarId, ">[data-part=\"thumb\"] {\n\t\t\t\theight: 100%;\n\t\t\t\tbackground-color: #c1c1c1;\n\t\t\t\tposition: absolute;\n\t\t\t}\n\t\t\t#").concat(scrollbarId, ">[data-part=\"thumb\"]:active {\n\t\t\t\tbackground-color: #787878;\n\t\t\t}\n\t\t</style>\n\t");
  1015. }
  1016. }]);
  1017. }()));
  1018.  
  1019. /** 持久化数据状态 */
  1020. var PersistentStorage = /*#__PURE__*/(/* unused pure expression or super */ null && (function () {
  1021. function PersistentStorage() {
  1022. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1023. _classCallCheck(this, PersistentStorage);
  1024. var _options$valKey = options.valKey,
  1025. valKey = _options$valKey === void 0 ? 'valKey' : _options$valKey,
  1026. _options$storageType = options.storageType,
  1027. storageType = _options$storageType === void 0 ? 'sessionStorage' : _options$storageType;
  1028. this.valKey = valKey;
  1029. this.storageType = storageType;
  1030. }
  1031. return _createClass(PersistentStorage, [{
  1032. key: "write",
  1033. value: function write(val) {
  1034. val = _typeof(val) === 'object' ? JSON.stringify(val, null, 2) : val;
  1035. val && window[this.storageType].setItem(this.valKey, val);
  1036. }
  1037. }, {
  1038. key: "read",
  1039. value: function read() {
  1040. var val = window[this.storageType].getItem(this.valKey);
  1041. return val ? JSON.parse(val) : val;
  1042. }
  1043. }, {
  1044. key: "remove",
  1045. value: function remove() {
  1046. window[this.storageType].removeItem(this.valKey);
  1047. }
  1048. }]);
  1049. }()));
  1050.  
  1051. /**
  1052. * @description 节流函数
  1053. * @export
  1054. * @param {Function} func
  1055. * @param {Number} [wait=100]
  1056. * @returns {Function}
  1057. */
  1058. function throttle(func) {
  1059. var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
  1060. var isDoing = false;
  1061. return function () {
  1062. if (isDoing) return;
  1063. isDoing = true;
  1064. func.apply(void 0, arguments);
  1065. setTimeout(function () {
  1066. isDoing = false;
  1067. }, wait);
  1068. };
  1069. }
  1070.  
  1071. /**
  1072. * @description 防抖函数
  1073. * @export
  1074. * @param {Function} func
  1075. * @param {Number} [wait=100]
  1076. * @param {'end'|'front'} type
  1077. * @returns {Function}
  1078. */
  1079. function debounce(func) {
  1080. var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
  1081. var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'end';
  1082. var timer = 0;
  1083. return function () {
  1084. clearTimeout(timer);
  1085. for (var _len = arguments.length, rest = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
  1086. rest[_key2] = arguments[_key2];
  1087. }
  1088. timer = setTimeout.apply(void 0, [func, wait].concat(rest));
  1089. };
  1090. }
  1091.  
  1092. /**
  1093. * @description 等候
  1094. * @export
  1095. * @param {number} [interval=17]
  1096. * @returns {Promise}
  1097. */
  1098. function awaitTime() {
  1099. var interval = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 17;
  1100. return new Promise(function (resolve) {
  1101. setTimeout(resolve, interval);
  1102. });
  1103. }
  1104.  
  1105. /**
  1106. * @description 打开已在窗口仅激活,不刷新
  1107. * @export
  1108. * @class OpenPlus
  1109. */
  1110. var OpenPlus = /*#__PURE__*/createClass_createClass(function OpenPlus() {
  1111. var _this3 = this;
  1112. var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1113. classCallCheck_classCallCheck(this, OpenPlus);
  1114. defineProperty_defineProperty(this, "openPre", function () {
  1115. var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
  1116. return null;
  1117. };
  1118. for (var _len2 = arguments.length, rest = new Array(_len2 > 1 ? _len2 - 1 : 0), _key3 = 1; _key3 < _len2; _key3++) {
  1119. rest[_key3 - 1] = arguments[_key3];
  1120. }
  1121. var win = _this3.open.apply(_this3, rest);
  1122. callback === null || callback === void 0 || callback();
  1123. return win;
  1124. });
  1125. defineProperty_defineProperty(this, "open", function (href) {
  1126. var willOpenTab = _this3.win.tabsCacheOfOpenPlus[href];
  1127. for (var _len3 = arguments.length, rest = new Array(_len3 > 1 ? _len3 - 1 : 0), _key4 = 1; _key4 < _len3; _key4++) {
  1128. rest[_key4 - 1] = arguments[_key4];
  1129. }
  1130. if (willOpenTab === undefined) {
  1131. var _this3$win;
  1132. willOpenTab = (_this3$win = _this3.win).open.apply(_this3$win, [href].concat(rest));
  1133. _this3.win.nextOfOpenPlus.forEach(function (item) {
  1134. return item === null || item === void 0 ? void 0 : item();
  1135. });
  1136. return _this3.win.tabsCacheOfOpenPlus[href] = willOpenTab;
  1137. } else if (willOpenTab.closed === true) {
  1138. var _this3$win2;
  1139. return (_this3$win2 = _this3.win).open.apply(_this3$win2, [href].concat(rest));
  1140. } else if (willOpenTab.closed === false) {
  1141. willOpenTab.focus();
  1142. return willOpenTab;
  1143. }
  1144. });
  1145. var _opt$win = opt.win,
  1146. _win = _opt$win === void 0 ? window : _opt$win,
  1147. _opt$next = opt.next,
  1148. next = _opt$next === void 0 ? function () {
  1149. return null;
  1150. } : _opt$next;
  1151. this.win = _win;
  1152. this.win.tabsCacheOfOpenPlus = this.win.tabsCacheOfOpenPlus || {};
  1153. this.win.nextOfOpenPlus = this.win.nextOfOpenPlus || [];
  1154. this.win.nextOfOpenPlus.push(next);
  1155. });
  1156. function modifyStorage() {
  1157. var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1158. var _opt$storageName = opt.storageName,
  1159. storageName = _opt$storageName === void 0 ? 'localStorage' : _opt$storageName,
  1160. chainKeys = opt.chainKeys,
  1161. _opt$doType = opt.doType,
  1162. doType = _opt$doType === void 0 ? 'get' : _opt$doType,
  1163. val = opt.val,
  1164. _opt$prefix = opt.prefix,
  1165. prefix = _opt$prefix === void 0 ? 'enjoy_setting' : _opt$prefix;
  1166. if (prefix) {
  1167. chainKeys = "".concat(prefix, ".").concat(chainKeys);
  1168. }
  1169. chainKeys = chainKeys.split('.');
  1170. var keyOfLevel1 = chainKeys.shift();
  1171. var keyOfEnd = chainKeys.pop();
  1172. var isObject = true;
  1173. var storage = null;
  1174. try {
  1175. storage = JSON.parse(window[storageName].getItem(keyOfLevel1));
  1176. } catch (error) {
  1177. isObject = false;
  1178. storage = window[storageName].getItem(keyOfLevel1);
  1179. console.error("".concat(storageName, " ").concat(chainKeys, " \u4E00\u7EA7\u5C5E\u6027\u503C\u4E3A\u57FA\u672C\u7C7B\u578B"));
  1180. return;
  1181. }
  1182. var obj = storage;
  1183. chainKeys.forEach(function (key) {
  1184. obj = obj[key];
  1185. });
  1186. if (doType === 'set') {
  1187. obj[keyOfEnd] = val;
  1188. window[storageName].setItem(keyOfLevel1, JSON.stringify(storage, null, 2));
  1189. } else {
  1190. return obj[keyOfEnd];
  1191. }
  1192. }
  1193.  
  1194. /**
  1195. * @description 简便的Storage SimpleStorage({ prefix: 'prefix' })
  1196. * @param {*} opt
  1197. */
  1198. function storagex() {
  1199. var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1200. var Storage = /*#__PURE__*/_createClass(function Storage() {
  1201. var _this4 = this;
  1202. var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1203. _classCallCheck(this, Storage);
  1204. _defineProperty(this, "storage", null);
  1205. _defineProperty(this, "setItem", function (keys, val) {
  1206. _this4.formatChainKeys(keys);
  1207. _this4.getFirstLevelVal();
  1208. _this4.chainVal('set', val);
  1209. return void 0;
  1210. });
  1211. _defineProperty(this, "getItem", function (keys) {
  1212. _this4.formatChainKeys(keys);
  1213. _this4.getFirstLevelVal();
  1214. return _this4.chainVal('get');
  1215. });
  1216. _defineProperty(this, "removeItem", function (keys) {
  1217. _this4.formatChainKeys(keys);
  1218. _this4.getFirstLevelVal();
  1219. return _this4.chainVal('remove');
  1220. });
  1221. _defineProperty(this, "clear", function () {
  1222. var keysWithPrefix = Object.keys(_this4.storage).filter(function (item) {
  1223. return item.startsWith(_this4.prefix);
  1224. });
  1225. keysWithPrefix.forEach(function (key) {
  1226. return _this4.storage.removeItem(key);
  1227. });
  1228. return void 0;
  1229. });
  1230. _defineProperty(this, "getFirstLevelVal", function () {
  1231. var state = _this4.storage[_this4.prefix + _this4.startKey];
  1232. try {
  1233. state = JSON.parse(state);
  1234. } catch (error) {}
  1235. _this4.cache = state;
  1236. return state;
  1237. });
  1238. _defineProperty(this, "formatChainKeys", function (keys) {
  1239. keys = keys.split('.');
  1240. _this4.startKey = keys.shift();
  1241. _this4.endKey = keys.pop();
  1242. _this4.middlekeys = keys;
  1243. return keys;
  1244. });
  1245. _defineProperty(this, "chainVal", function (doType, val) {
  1246. var obj = _this4.cache;
  1247. _this4.middlekeys.forEach(function (key) {
  1248. obj = obj[key];
  1249. });
  1250. if (doType === 'set') {
  1251. if (_this4.endKey) {
  1252. obj[_this4.endKey] = val;
  1253. } else {
  1254. _this4.cache = val;
  1255. }
  1256. _this4.storage.setItem(_this4.prefix + _this4.startKey, _this4.isObject(_this4.cache) ? JSON.stringify(_this4.cache, null, 2) : _this4.cache);
  1257. } else if (doType === 'get') {
  1258. if (_this4.endKey) {
  1259. return obj[_this4.endKey];
  1260. }
  1261. return _this4.cache;
  1262. } else if (doType === 'remove') {
  1263. if (_this4.endKey) {
  1264. var isDeleted = delete obj[_this4.endKey];
  1265. isDeleted && _this4.setItem(_this4.startKey, _this4.cache);
  1266. return isDeleted;
  1267. }
  1268. _this4.storage.removeItem(_this4.prefix + _this4.startKey);
  1269. }
  1270. });
  1271. _defineProperty(this, "isObject", function (value) {
  1272. var type = _typeof(value);
  1273. return value != null && (type === 'object' || type === 'function');
  1274. });
  1275. var prefix = opt.prefix,
  1276. storage = opt.storage;
  1277. this.prefix = prefix ? "".concat(prefix, "_") : '';
  1278. this.storage = storage;
  1279. });
  1280. if (opt.storage && sessionStorage.__proto__.setItemX) return opt.storage;
  1281. var storage = new Storage(opt);
  1282. if (opt.storage) return storage;
  1283. if (sessionStorage.__proto__.setItemX) return;
  1284. sessionStorage.__proto__.setItemX = function (key, val) {
  1285. storage.storage = this;
  1286. storage.setItem(key, val);
  1287. };
  1288. sessionStorage.__proto__.getItemX = function (key) {
  1289. storage.storage = this;
  1290. return storage.getItem(key);
  1291. };
  1292. sessionStorage.__proto__.removeItemX = function (key) {
  1293. storage.storage = this;
  1294. return storage.removeItem(key);
  1295. };
  1296. sessionStorage.__proto__.clearX = function () {
  1297. storage.storage = this;
  1298. return storage.clear();
  1299. };
  1300. }
  1301.  
  1302. /**
  1303. * @description 处理标记内容
  1304. * @param {*} opt
  1305. * @returns {*}
  1306. */
  1307. function operateComment(opt) {
  1308. var _opt$text = opt.text,
  1309. text = _opt$text === void 0 ? '' : _opt$text,
  1310. _opt$S = opt.S,
  1311. S = _opt$S === void 0 ? '/*' : _opt$S,
  1312. _opt$E = opt.E,
  1313. E = _opt$E === void 0 ? '*/' : _opt$E,
  1314. _opt$modify = opt.modify,
  1315. modify = _opt$modify === void 0 ? function (val) {
  1316. return val;
  1317. } : _opt$modify;
  1318. var stack = [];
  1319. var index = text.indexOf(S);
  1320. if (index === -1) return text;
  1321. while (index <= text.length - 1) {
  1322. if (text[index] + text[index + 1] == S) {
  1323. stack.push(index);
  1324. } else if (text[index] + text[index + 1] == E) {
  1325. var latestIndex = stack.pop();
  1326. if (latestIndex !== undefined) {
  1327. var middle = modify(text.slice(latestIndex + S.length, index));
  1328. text = text.slice(0, latestIndex) + middle + text.slice(index + S.length);
  1329. index = latestIndex + middle.length;
  1330. }
  1331. }
  1332. index++;
  1333. }
  1334. return text;
  1335. }
  1336.  
  1337. /** 添加动画函数 */
  1338. function addAnimation(dom, className) {
  1339. if (!dom || !className) return;
  1340. if (!dom.animationend) {
  1341. dom.animationend = function () {
  1342. dom.classList.remove(className);
  1343. };
  1344. }
  1345. dom.removeEventListener('animationend', dom.animationend);
  1346. dom.addEventListener('animationend', dom.animationend);
  1347. dom.classList.add(className);
  1348. }
  1349.  
  1350. // 判断当前浏览器运行环境
  1351. function getBrowserEnv() {
  1352. var userAgent = window.navigator.userAgent.toLowerCase();
  1353. var agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
  1354. // 是否为支付宝环境
  1355. var isAliPay = /alipayclient/.test(userAgent);
  1356. // 是否为淘宝环境
  1357. var isTaoBao = /windvane/.test(userAgent);
  1358. // 是否为企业微信环境
  1359. var isWxWork = /wxwork/.test(userAgent);
  1360. // 是否为微信环境
  1361. var isWeChat = /micromessenger/.test(userAgent) && !isWxWork;
  1362. // 是否为移动端
  1363. var isPhone = agents.some(function (x) {
  1364. return new RegExp(x.toLocaleLowerCase()).test(userAgent);
  1365. });
  1366. return {
  1367. isAliPay: isAliPay,
  1368. isTaoBao: isTaoBao,
  1369. isWxWork: isWxWork,
  1370. isWeChat: isWeChat,
  1371. isPhone: isPhone
  1372. };
  1373. }
  1374. var RegisterDbltouchEvent = /*#__PURE__*/(/* unused pure expression or super */ null && (function () {
  1375. function RegisterDbltouchEvent(el, fn) {
  1376. _classCallCheck(this, RegisterDbltouchEvent);
  1377. this.el = el || window;
  1378. this.callback = fn;
  1379. this.timer = null;
  1380. this.prevPosition = {};
  1381. this.isWaiting = false;
  1382.  
  1383. // 注册click事件,注意this指向
  1384. this.el.addEventListener('click', this.handleClick.bind(this), true);
  1385. }
  1386. return _createClass(RegisterDbltouchEvent, [{
  1387. key: "handleClick",
  1388. value: function handleClick(evt) {
  1389. var _this5 = this;
  1390. var pageX = evt.pageX;
  1391. var pageY = evt.pageY;
  1392. if (this.timer) {
  1393. clearTimeout(this.timer);
  1394. this.timer = null;
  1395. }
  1396. if (!evt.isTrusted) {
  1397. return;
  1398. }
  1399. if (this.isWaiting) {
  1400. this.isWaiting = false;
  1401. var diffX = Math.abs(pageX - this.prevPosition.pageX);
  1402. var diffY = Math.abs(pageY - this.prevPosition.pageY);
  1403. // 如果满足位移小于10,则是双击
  1404. if (diffX <= 10 && diffY <= 10) {
  1405. // 取消当前事件传递,并派发1个自定义双击事件
  1406. evt.stopPropagation();
  1407. evt.target.dispatchEvent(new PointerEvent('dbltouch', {
  1408. cancelable: false,
  1409. bubbles: true
  1410. }));
  1411. // 也可以采用回调函数的方式
  1412. this.callback && this.callback(evt);
  1413. }
  1414. } else {
  1415. this.prevPostion = {
  1416. pageX: pageX,
  1417. pageY: pageY
  1418. };
  1419. // 阻止冒泡,不让事件继续传播
  1420. evt.stopPropagation();
  1421. // 开始等待第2次点击
  1422. this.isWaiting = true;
  1423. // 设置200ms倒计时,200ms后重新派发当前事件
  1424. this.timer = setTimeout(function () {
  1425. _this5.isWaiting = false;
  1426. evt.target.dispatchEvent(evt);
  1427. }, 200);
  1428. }
  1429. }
  1430. }]);
  1431. }()));
  1432. /**移动端 双击 */
  1433. function addDbltouch() {
  1434. var dom = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
  1435. var handle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (event) {
  1436. console.log('双击', event, Date.now());
  1437. };
  1438. var preTimestamp = 0;
  1439. dom.addEventListener('click', function (event) {
  1440. var currentTimestamp = Date.now();
  1441. if (currentTimestamp - preTimestamp < 200) handle(event);
  1442. preTimestamp = currentTimestamp;
  1443. });
  1444. }
  1445.  
  1446. /**
  1447. * @description 获取dom
  1448. * @export
  1449. * @param {*} element
  1450. * @param {*} selector
  1451. * @param {number} [timeout=80]
  1452. * @param {boolean} [isAlways=true]
  1453. * @returns {*}
  1454. */
  1455. function getElement(_x, _x2) {
  1456. return _getElement.apply(this, arguments);
  1457. }
  1458.  
  1459. /**
  1460. * @description 分隔dom分区
  1461. * @param {*} e
  1462. * @param {number} [divideX=3]
  1463. * @param {*} [divideY=divideX]
  1464. * @returns {*} string
  1465. */
  1466. function _getElement() {
  1467. _getElement = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(element, selector) {
  1468. var timeout,
  1469. isAlways,
  1470. count,
  1471. _args = arguments;
  1472. return _regeneratorRuntime.wrap(function _callee$(_context) {
  1473. while (1) switch (_context.prev = _context.next) {
  1474. case 0:
  1475. timeout = _args.length > 2 && _args[2] !== undefined ? _args[2] : 80;
  1476. isAlways = _args.length > 3 && _args[3] !== undefined ? _args[3] : true;
  1477. count = 0;
  1478. return _context.abrupt("return", new Promise(function (resolve, reject) {
  1479. var timeId = setInterval(function () {
  1480. if (timeout && count++ >= timeout) {
  1481. clearInterval(timeId);
  1482. console.warn('[utils.getElement] Element is not find.' + ' selector: ' + selector);
  1483. // 保持原生逻辑,即未找到时,返回null,便于之后执行埋点,比如错误上报
  1484. return resolve(null);
  1485. }
  1486. var node = element.querySelector(selector);
  1487. if (node) {
  1488. //node 总是返回 或 显示状态条件下,找到后即刻返回
  1489. if (isAlways || node.offsetParent) {
  1490. resolve(node);
  1491. clearInterval(timeId);
  1492. }
  1493. }
  1494. }, 200);
  1495. }));
  1496. case 4:
  1497. case "end":
  1498. return _context.stop();
  1499. }
  1500. }, _callee);
  1501. }));
  1502. return _getElement.apply(this, arguments);
  1503. }
  1504. function divideDom(e) {
  1505. var divideX = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
  1506. var divideY = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : divideX;
  1507. if (!divideX) {
  1508. throw new Error('divideDom 函数 divideX 参数不能为空');
  1509. }
  1510. if (!divideY) {
  1511. divideX = divideY;
  1512. console.warn("divideDom \u51FD\u6570 dom \u5206\u533A \u4E3A ".concat(divideX, "*").concat(divideY));
  1513. }
  1514. var resultStr = "".concat(getIdx(e.target.offsetWidth, divideX, e.offsetX), "-").concat(getIdx(e.target.offsetHeight, divideY, e.offsetY));
  1515. console.log("resultStr => %O ", resultStr);
  1516. return resultStr;
  1517.  
  1518. // 获取坐标
  1519. function getIdx(size, divide, offsetPosition) {
  1520. var size_step = Math.ceil(size / divide);
  1521. var posi_idx = Math.floor(offsetPosition / size_step);
  1522. if (offsetPosition % size_step) {
  1523. posi_idx++;
  1524. }
  1525. return posi_idx;
  1526. }
  1527. }
  1528. ;// CONCATENATED MODULE: ./src/tool/previewImg.js
  1529.  
  1530.  
  1531.  
  1532.  
  1533. var EMIT_EVENT_TYPE = getBrowserEnv().isPhone ? 'dbltouch' : 'dblclick';
  1534. // const EMIT_EVENT_TYPE = 'dblclick'
  1535. var ImgPreviewer = /*#__PURE__*/createClass_createClass(function ImgPreviewer() {
  1536. var _this = this;
  1537. var _options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1538. classCallCheck_classCallCheck(this, ImgPreviewer);
  1539. defineProperty_defineProperty(this, "createGlobalStyle", function () {
  1540. createElement('style', {
  1541. randomType: 'newOne',
  1542. innerHTML: "\n\t\t\t/* \u7F29\u653E */\n\t\t\t body img {\n\n\t\t\t /* \u5149\u6807 \u5448\u73B0 \u653E\u5927\u56FE\u6807 */\n\t\t\t /*\tcursor: zoom-in !important; */\n\n\t\t\t/* \u907F\u514D pointer-events: none; \u60C5\u51B5\u51FA\u73B0 inherit initial auto */\n pointer-events: auto !important;\n\n\t\t\t}\n\n\n\t\t\t"
  1543. });
  1544. });
  1545. /** @描述 状态 */
  1546. defineProperty_defineProperty(this, "state", null);
  1547. defineProperty_defineProperty(this, "shadowRoot", null);
  1548. defineProperty_defineProperty(this, "maskContent", null);
  1549. /** @描述 创建 shadowRoot */
  1550. defineProperty_defineProperty(this, "createShadowRoot", function () {
  1551. var selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '#imgPreview';
  1552. selector = selector.replace(/[.#]/g, '');
  1553. var dom = document.querySelector("#".concat(selector));
  1554. if (!dom) {
  1555. dom = createElement('div', {
  1556. addPrefix: false,
  1557. id: selector,
  1558. style: 'width:0;height:0'
  1559. });
  1560. }
  1561. if (!dom.shadowRoot) {
  1562. // 添加在body下,获取 dom.shadowRoot
  1563. dom.attachShadow({
  1564. mode: 'open'
  1565. });
  1566. // dom.shadowRoot.appendChild(maskContent)
  1567. // 创建蒙层容器
  1568. var maskContent = createElement('div', {
  1569. className: 'modal',
  1570. el: dom.shadowRoot
  1571. });
  1572. maskContent.appendChild(_this.createStyle(_this.state));
  1573. }
  1574. return dom.shadowRoot;
  1575. });
  1576. /** @描述 合并选项 */
  1577. defineProperty_defineProperty(this, "mergeOptions", function (options) {
  1578. var opt = {};
  1579. var defaultOptions = {
  1580. contentSelector: 'body',
  1581. selector: 'img',
  1582. showRootSelector: '#img_preview',
  1583. backgroundColor: 'rgba(0,0,0,0)',
  1584. extraStyle: ''
  1585. };
  1586. Object.assign(opt, defaultOptions, options);
  1587. return opt;
  1588. });
  1589. /** @描述 创建shadowbox中的样式 */
  1590. defineProperty_defineProperty(this, "createStyle", function (_ref) {
  1591. var contentSelector = _ref.contentSelector,
  1592. selector = _ref.selector,
  1593. backgroundColor = _ref.backgroundColor,
  1594. extraStyle = _ref.extraStyle;
  1595. return createElement('style', {
  1596. autoInsert: false,
  1597. randomType: 'newOne',
  1598. innerHTML: "".concat(contentSelector, " ").concat(selector, " {\n cursor: zoom-in;\n }\n /* \u56FE\u7247\u9884\u89C8 */\n .modal {\n touch-action: none;\n position: fixed;\n z-index: 10000;\n top: 0;\n left: 0;\n width: 100vw;\n height: 100vh;\n background-color: ").concat(backgroundColor, ";\n user-select: none;\n pointer-events: none;\n\t\t\t--box-shadow-focus:rgb(125 230 221 / 90%);\n }\n .modal>*{\n pointer-events: auto;\n }\n .modal>img {\n position: absolute;\n padding: 0;\n margin: 0;\n box-shadow: var(--box-shadow-focus) 0 0 8px 2px;\n /* border-radius: 10px; */\n /* transition: all var(--delay_time); */\n transform: translateZ(0);\n\t\t\t/* \u900F\u660E\u56FE\u7247 \u886C\u56FE */\n\t\t\tbackground: repeating-conic-gradient(#202020 0, #202020 25%, #303030 0, #303030 50%) 0 0/30px 30px;\n }\n\n img.isPreviewed {\n animation: activeImg 0.5s 4 ease-out forwards;\n transition: all;\n\n }\n\n @keyframes activeImg {\n 0% {\n box-shadow: var(--box-shadow-focus) 0 0 8px 2px;\n }\n 50% {\n box-shadow: rgb(255 0 0 / 70%) 0 0 8px 2px;\n }\n 100% {\n box-shadow: rgb(239 126 4 / 95%) 0 0 8px 2px;\n }\n }\n ").concat(extraStyle, "\n ")
  1599. });
  1600. });
  1601. /** @描述 预览操作 */
  1602. defineProperty_defineProperty(this, "onPreviwerEvent", function () {
  1603. var that = _this;
  1604. var _that$state = that.state,
  1605. contentSelector = _that$state.contentSelector,
  1606. selector = _that$state.selector;
  1607. var eventsProxy = document.querySelector(contentSelector) || window.document.body;
  1608. var operationHandle = function operationHandle(e) {
  1609. var _e$target$imgItemInMo;
  1610. var src = that.getImgSrc(e.target);
  1611. if (!src) return;
  1612. e.preventDefault();
  1613.  
  1614. // let previewTargetDom = [...that.shadowRoot.querySelectorAll(selector)].find((item) => that.getImgSrc(item) === src)
  1615. var previewTargetDom = (_e$target$imgItemInMo = e.target.imgItemInModal) === null || _e$target$imgItemInMo === void 0 || (_e$target$imgItemInMo = _e$target$imgItemInMo.state) === null || _e$target$imgItemInMo === void 0 ? void 0 : _e$target$imgItemInMo.cloneEl;
  1616.  
  1617. // 第n+1次双击原图预览时
  1618. if (previewTargetDom) {
  1619. //原图的预览图已存在,则激活并最上面显示
  1620. if (!previewTargetDom.classList.contains('isPreviewed')) {
  1621. previewTargetDom.classList.add('isPreviewed');
  1622. // previewTargetDom.remove()
  1623. // that.shadowRoot.querySelector('.modal').appendChild(previewTargetDom)
  1624. that.setTopImg(previewTargetDom);
  1625. } else {
  1626. // previewTargetDom.remove()
  1627.  
  1628. e.target.imgItemInModal.ondblclick({
  1629. animation: 'opacity',
  1630. preventDefault: function preventDefault() {
  1631. return null;
  1632. }
  1633. });
  1634. previewTargetDom = null;
  1635. }
  1636. return;
  1637. }
  1638. // 第一次双击原图预览时
  1639. if (!previewTargetDom) {
  1640. // originalEl.style.opacity = 0
  1641. e.target.imgItemInModal = new ImgItemInModal(that.shadowRoot, e.target, src);
  1642. console.log("e.target.imgItemInModal => %O ", e.target.imgItemInModal);
  1643. }
  1644. };
  1645. getBrowserEnv().isPhone ? addDbltouch(eventsProxy, operationHandle) : eventsProxy.addEventListener(EMIT_EVENT_TYPE, operationHandle);
  1646. });
  1647. defineProperty_defineProperty(this, "getImgSrc", function (dom) {
  1648. var _dom$dataset, _window$getComputedSt;
  1649. return (dom === null || dom === void 0 || (_dom$dataset = dom.dataset) === null || _dom$dataset === void 0 ? void 0 : _dom$dataset.src) || (dom === null || dom === void 0 ? void 0 : dom.src) || ((_window$getComputedSt = window.getComputedStyle(dom).backgroundImage.match(/^url\("([^\s]+)"\)$/i)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt[1]);
  1650. });
  1651. /** 最顶层的图片 绑定到容器*/
  1652. defineProperty_defineProperty(this, "setTopImg", function (domImg) {
  1653. if (!_this.maskContent) {
  1654. _this.maskContent = _this.shadowRoot.querySelector('.modal');
  1655. }
  1656. if (domImg && _this.maskContent && _this.maskContent.topImg !== domImg) {
  1657. if (_this.maskContent.topImg) {
  1658. _this.maskContent.topImg.style.zIndex = '';
  1659. }
  1660. domImg.style.zIndex = '1';
  1661. _this.maskContent.topImg = domImg;
  1662. }
  1663. });
  1664. this.state = this.mergeOptions(_options);
  1665. this.shadowRoot = this.createShadowRoot();
  1666. this.onPreviwerEvent();
  1667. this.createGlobalStyle();
  1668. return this.shadowRoot;
  1669. });
  1670. var ImgItemInModal = /*#__PURE__*/function () {
  1671. function ImgItemInModal(_shadowRoot, _originalEl, _src) {
  1672. var _this2 = this;
  1673. classCallCheck_classCallCheck(this, ImgItemInModal);
  1674. defineProperty_defineProperty(this, "state", {
  1675. scale: 1,
  1676. offset: {
  1677. left: 0,
  1678. top: 0
  1679. },
  1680. origin: 'center',
  1681. initialData: {
  1682. offset: {},
  1683. origin: 'center',
  1684. scale: 1
  1685. },
  1686. startPoint: {
  1687. x: 0,
  1688. y: 0
  1689. },
  1690. // 记录初始触摸点位
  1691. isTouching: false,
  1692. // 标记是否正在移动
  1693. isMove: false,
  1694. // 正在移动中,与点击做区别
  1695. touches: new Map(),
  1696. // 触摸点数组
  1697. lastDistance: 0,
  1698. lastScale: 1,
  1699. // 记录下最后的缩放值
  1700. scaleOrigin: {
  1701. x: 0,
  1702. y: 0
  1703. },
  1704. // 原图originalEl与预览图cloneEl互相引用
  1705. originalEl: null,
  1706. cloneEl: null
  1707. });
  1708. defineProperty_defineProperty(this, "mergeOptions", function (shadowRoot, originalEl, src) {
  1709. var _window = window,
  1710. winWidth = _window.innerWidth,
  1711. winHeight = _window.innerHeight;
  1712. var offsetWidth = originalEl.offsetWidth,
  1713. offsetHeight = originalEl.offsetHeight;
  1714.  
  1715. // Element.getBoundingClientRect() 方法返回元素的大小及其相对于【视口】的位置
  1716. var _originalEl$getBoundi = originalEl.getBoundingClientRect(),
  1717. top = _originalEl$getBoundi.top,
  1718. left = _originalEl$getBoundi.left;
  1719. return {
  1720. shadowRoot: shadowRoot,
  1721. originalEl: originalEl,
  1722. src: src,
  1723. winWidth: winWidth,
  1724. winHeight: winHeight,
  1725. offsetWidth: offsetWidth,
  1726. offsetHeight: offsetHeight,
  1727. top: top,
  1728. left: left,
  1729. maskContent: shadowRoot.querySelector('.modal')
  1730. };
  1731. });
  1732. /** @描述 添加图片 */
  1733. defineProperty_defineProperty(this, "appendImg", function (src, originalEl) {
  1734. // 克隆节点 能从缓存中获取图片,以便节省流量
  1735. var cloneEl = null;
  1736. if (originalEl.tagName === 'IMG') {
  1737. cloneEl = originalEl.cloneNode();
  1738. } else {
  1739. cloneEl = document.createElement('img');
  1740. cloneEl.src = src;
  1741. }
  1742. console.log("\u53CC\u51FB\u7684\u56FE\u7247\u5730\u5740 => %O ", cloneEl.src);
  1743. _this2.state.maskContent.appendChild(cloneEl);
  1744. _this2.setTopImg(cloneEl);
  1745. return cloneEl;
  1746. });
  1747. /** 最顶层的图片 绑定到容器*/
  1748. defineProperty_defineProperty(this, "setTopImg", function (domImg) {
  1749. if (domImg && _this2.state.maskContent && _this2.state.maskContent.topImg !== domImg) {
  1750. if (_this2.state.maskContent.topImg) {
  1751. _this2.state.maskContent.topImg.style.zIndex = '';
  1752. }
  1753. domImg.style.zIndex = '1';
  1754. _this2.state.maskContent.topImg = domImg;
  1755. }
  1756. });
  1757. /** @描述 预览容器modal中的Img元素 添加监听滚轴缩放、移动、双击事件 */
  1758. defineProperty_defineProperty(this, "onEventsController", function (cloneEl) {
  1759. var eventType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'addEventListener';
  1760. var events = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [EMIT_EVENT_TYPE, 'mousewheel', 'pointerdown', 'pointerup', 'pointermove', 'pointercancel', 'mouseleave'];
  1761. console.log("onEventsController \u7684 eventType=> %O ", eventType);
  1762. var that = _this2;
  1763. events.forEach(function (item) {
  1764. if (item === 'mousewheel') {
  1765. if (EMIT_EVENT_TYPE === 'dbltouch') {
  1766. addDbltouch(cloneEl, that.ondbltouch);
  1767. } else {
  1768. cloneEl[eventType]('mousewheel', that["on".concat(item)], {
  1769. passive: false
  1770. });
  1771. }
  1772. return;
  1773. }
  1774. cloneEl[eventType](item, that["on".concat(item)]);
  1775. });
  1776. });
  1777. /** @描述 双击事件 */
  1778. defineProperty_defineProperty(this, "ondblclick", function (e) {
  1779. _this2.ondbltouch(e);
  1780. return;
  1781. e.preventDefault();
  1782. var that = _this2;
  1783. var state = that.state;
  1784. console.log("\u5F53\u524D\u9884\u89C8\u56FE\u7247\u7684\u72B6\u6001\u53CA\u5F15\u7528\u5173\u7CFBstate => %O ", state);
  1785. if (state.isMove) {
  1786. state.isMove = false;
  1787. } else {
  1788. // const animationTime = this.getTimeOfClearImgAnimation(state)
  1789. var animationTime = 0.4;
  1790. var originalElPositionState = state.originalEl.getBoundingClientRect();
  1791. that.changeStyle(state.cloneEl, ["transform: translate(0,0)", "transition: all ".concat(animationTime, "s ease-out"), "left: ".concat(originalElPositionState.left, "px"), "top: ".concat(originalElPositionState.top, "px"), "width: ".concat(originalElPositionState.width, "px")]);
  1792. // state.cloneEl.removeEventListener('dblclick', that.ondblclick)
  1793.  
  1794. // this.onEventsController(state.cloneEl, 'removeEventListener')
  1795. setTimeout(function () {
  1796. // state.maskContent.removeChild(state.cloneEl)
  1797. console.log('开始执行清除预览图片');
  1798. // 先清除原图对预览图的引用
  1799. state.cloneEl.remove();
  1800. state.cloneEl = null;
  1801. state.originalEl.imgItemInModal = null;
  1802. }, animationTime * 1000 + 100);
  1803. }
  1804. });
  1805. /** @描述 双触摸事件 */
  1806. defineProperty_defineProperty(this, "ondbltouch", function (e) {
  1807. e.preventDefault();
  1808. var that = _this2;
  1809. var state = that.state;
  1810. console.log("\u5F53\u524D\u9884\u89C8\u56FE\u7247\u7684\u72B6\u6001\u53CA\u5F15\u7528\u5173\u7CFBstate => %O ", state);
  1811. if (state.isMove) {
  1812. state.isMove = false;
  1813. } else {
  1814. var animationTime = 0.4;
  1815. if (e.animation == 'opacity') {
  1816. // 点击原图清除时,透明后清除,不干扰用户浏览内容
  1817. // const animationTime = this.getTimeOfClearImgAnimation(state)
  1818. var originalElPositionState = state.originalEl.getBoundingClientRect();
  1819. that.changeStyle(state.cloneEl, ["opacity: 0", "transition: all ".concat(animationTime, "s ease-out")]);
  1820. } else {
  1821. // 点击预览图清除时,移动后清除,便于定位预览图的原图位置
  1822. // const animationTime = this.getTimeOfClearImgAnimation(state)
  1823. var _originalElPositionState = state.originalEl.getBoundingClientRect();
  1824. that.changeStyle(state.cloneEl, ["transform: translate(0,0)", "transition: all ".concat(animationTime, "s ease-out"), "left: ".concat(_originalElPositionState.left, "px"), "top: ".concat(_originalElPositionState.top, "px"), "width: ".concat(_originalElPositionState.width, "px")]);
  1825. }
  1826.  
  1827. // state.cloneEl.removeEventListener('dblclick', that.ondblclick)
  1828. _this2.onEventsController(state.cloneEl, 'removeEventListener');
  1829. setTimeout(function () {
  1830. // state.maskContent.removeChild(state.cloneEl)
  1831. console.log('开始执行清除预览图片');
  1832. // 先清除原图对预览图的引用
  1833. state.cloneEl.remove();
  1834. state.cloneEl = null;
  1835. state.originalEl.imgItemInModal = null;
  1836. }, animationTime * 1000 + 100);
  1837. }
  1838. });
  1839. /** 清除预览图片动作时长 */
  1840. defineProperty_defineProperty(this, "getTimeOfClearImgAnimation", function (state) {
  1841. var cloneElPositionState = state.cloneEl.getBoundingClientRect();
  1842. var originalElPositionState = state.originalEl.getBoundingClientRect();
  1843. var maxOffsetVal = Math.max(Math.abs(originalElPositionState.left - cloneElPositionState.left), Math.abs(originalElPositionState.top - cloneElPositionState.top));
  1844. var animationTime = 0.1 * maxOffsetVal / 400 + 0.2;
  1845. console.log('清除预览图片的距离及动作时长: ', maxOffsetVal + 'px', animationTime + 's');
  1846. return animationTime;
  1847. });
  1848. /** @描述 指针按下事件*/
  1849. defineProperty_defineProperty(this, "onpointerdown", function (e) {
  1850. e.preventDefault();
  1851. var that = _this2;
  1852. var state = that.state;
  1853. state.touches.set(e.pointerId, e);
  1854. // TODO: 点击存入触摸点
  1855. state.isTouching = true;
  1856. state.startPoint = {
  1857. x: e.clientX,
  1858. y: e.clientY
  1859. };
  1860. if (state.touches.size === 2) {
  1861. // TODO: 判断双指触摸,并立即记录初始数据
  1862. state.lastDistance = that.getDistance();
  1863. state.lastScale = state.scale;
  1864. }
  1865. _this2.setTopImg(e.target);
  1866. });
  1867. /** @描述 滚轮缩放 */
  1868. defineProperty_defineProperty(this, "onmousewheel", function (e) {
  1869. e.preventDefault();
  1870. if (!e.deltaY) return;
  1871. var that = _this2;
  1872. var state = that.state;
  1873. state.origin = "".concat(e.offsetX, "px ").concat(e.offsetY, "px");
  1874.  
  1875. // 缩放执行
  1876. if (e.deltaY < 0) {
  1877. // 放大
  1878. state.scale += 0.18;
  1879. } else if (e.deltaY > 0) {
  1880. state.scale >= 0.28 && (state.scale -= 0.18);
  1881. // 缩小
  1882. }
  1883. if (state.scale < state.initialData.scale) {
  1884. that.reduction();
  1885. }
  1886. state.offset = that.getOffsetPageCenter(e.offsetX, e.offsetY);
  1887. that.changeStyle(state.cloneEl, ['transition: all .15s', "transform-origin: ".concat(state.origin), "transform: translate(".concat(state.offset.left + 'px', ", ").concat(state.offset.top + 'px', ") scale(").concat(state.scale, ")")]);
  1888. _this2.setTopImg(e.target);
  1889. });
  1890. /** @描述 获取中心改变的偏差 */
  1891. defineProperty_defineProperty(this, "getOffsetPageCenter", function () {
  1892. var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  1893. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  1894. var state = _this2.state;
  1895. var touchArr = Array.from(state.touches);
  1896. if (touchArr.length === 2) {
  1897. var start = touchArr[0][1];
  1898. var end = touchArr[1][1];
  1899. x = (start.offsetX + end.offsetX) / 2;
  1900. y = (start.offsetY + end.offsetY) / 2;
  1901. }
  1902. state.origin = "".concat(x, "px ").concat(y, "px");
  1903. var offsetLeft = (state.scale - 1) * (x - state.scaleOrigin.x) + state.offset.left;
  1904. var offsetTop = (state.scale - 1) * (y - state.scaleOrigin.y) + state.offset.top;
  1905. state.scaleOrigin = {
  1906. x: x,
  1907. y: y
  1908. };
  1909. return {
  1910. left: offsetLeft,
  1911. top: offsetTop
  1912. };
  1913. });
  1914. /** @描述 获取距离*/
  1915. defineProperty_defineProperty(this, "getDistance", function () {
  1916. var touchArr = Array.from(_this2.state.touches);
  1917. if (touchArr.length < 2) {
  1918. return 0;
  1919. }
  1920. var start = touchArr[0][1];
  1921. var end = touchArr[1][1];
  1922. return Math.hypot(end.x - start.x, end.y - start.y);
  1923. });
  1924. /** @描述 修改样式,减少回流重绘*/
  1925. defineProperty_defineProperty(this, "changeStyle", function (el, arr, isResetAllStyle) {
  1926. var original = el.style.cssText.split(';');
  1927. original.pop();
  1928. if (isResetAllStyle) {
  1929. el.className = '';
  1930. el.style.cssText = arr.join(';') + ';';
  1931. } else {
  1932. el.style.cssText = original.concat(arr).join(';') + ';';
  1933. }
  1934. });
  1935. /** @描述 还原记录,用于边界处理 */
  1936. defineProperty_defineProperty(this, "reduction", function () {
  1937. var that = _this2;
  1938. var state = that.state;
  1939. that.timer && clearTimeout(that.timer);
  1940. that.timer = setTimeout(function () {
  1941. that.changeStyle(state.cloneEl, ["transform: translate(".concat(state.offset.left + 'px', ", ").concat(state.offset.top + 'px', ") scale(").concat(state.scale, ")"), "transform-origin: ".concat(state.origin)]);
  1942. }, 300);
  1943. });
  1944. /** @描述 松开指针 事件 */
  1945. defineProperty_defineProperty(this, "onpointerup", function (e) {
  1946. e.preventDefault();
  1947. var that = _this2;
  1948. var state = that.state;
  1949. state.touches["delete"](e.pointerId);
  1950. // TODO: 抬起移除触摸点
  1951. if (state.touches.size <= 0) {
  1952. state.isTouching = false;
  1953. } else {
  1954. var touchArr = Array.from(state.touches);
  1955. // 更新点位
  1956. state.startPoint = {
  1957. x: touchArr[0][1].clientX,
  1958. y: touchArr[0][1].clientY
  1959. };
  1960. }
  1961. setTimeout(function () {
  1962. state.isMove = false;
  1963. }, 300);
  1964. });
  1965. /** @描述 指针移动事件 */
  1966. defineProperty_defineProperty(this, "onpointermove", function (e) {
  1967. e.preventDefault();
  1968. var that = _this2;
  1969. var state = that.state;
  1970. if (state.isTouching) {
  1971. state.isMove = true;
  1972. if (state.touches.size < 2) {
  1973. // 单指滑动
  1974. state.offset = {
  1975. left: state.offset.left + (e.clientX - state.startPoint.x),
  1976. top: state.offset.top + (e.clientY - state.startPoint.y)
  1977. };
  1978. that.changeStyle(state.cloneEl, ['transition: all 0s', "transform: translate(".concat(state.offset.left + 'px', ", ").concat(state.offset.top + 'px', ") scale(").concat(state.scale, ")"), "transform-origin: ".concat(origin)]);
  1979. // 更新点位
  1980. state.startPoint = {
  1981. x: e.clientX,
  1982. y: e.clientY
  1983. };
  1984. } else {
  1985. // 双指缩放
  1986. state.touches.set(e.pointerId, e);
  1987. var ratio = that.getDistance() / state.lastDistance;
  1988. state.scale = ratio * state.lastScale;
  1989. state.offset = that.getOffsetPageCenter();
  1990. if (state.scale < state.initialData.scale) {
  1991. that.reduction();
  1992. }
  1993. that.changeStyle(state.cloneEl, ['transition: all 0s', "transform: translate(".concat(state.offset.left + 'px', ", ").concat(state.offset.top + 'px', ") scale(").concat(state.scale, ")"), "transform-origin: ".concat(state.origin)]);
  1994. }
  1995. }
  1996. });
  1997. /** @描述 取消指针事件 */
  1998. defineProperty_defineProperty(this, "onpointercancel", function (e) {
  1999. e.preventDefault();
  2000. _this2.state.touches.clear();
  2001. // 可能存在特定事件导致中断,真机操作时 pointerup 在某些边界情况下不会生效,所以需要清空
  2002. });
  2003. /** 鼠标离开图片时,移动操作结束 */
  2004. defineProperty_defineProperty(this, "onmouseleave", function (e) {
  2005. _this2.state.isMove = false;
  2006. _this2.state.isTouching = false;
  2007. });
  2008. /** @描述 移动图片到屏幕中心位置 */
  2009. defineProperty_defineProperty(this, "fixPosition", function (cloneEl) {
  2010. var that = _this2;
  2011. var state = that.state;
  2012.  
  2013. /** @描述 原图片 中心点 */
  2014. var originalCenterPoint = {
  2015. x: state.offsetWidth / 2 + state.left,
  2016. y: state.offsetHeight / 2 + state.top
  2017. };
  2018.  
  2019. /** @描述 页面 中心点 */
  2020. var winCenterPoint = {
  2021. x: state.winWidth / 2,
  2022. y: state.winHeight / 2
  2023. };
  2024.  
  2025. /** @描述 新建图片的定位点:通过原图片中心点到页面中心点的 偏移量*/
  2026. var offsetDistance = {
  2027. left: winCenterPoint.x - originalCenterPoint.x + state.left,
  2028. top: winCenterPoint.y - originalCenterPoint.y + state.top
  2029. };
  2030.  
  2031. /** @描述 放大后的 */
  2032. var scaleNum = _this2.adaptScale();
  2033. var diffs = {
  2034. left: (scaleNum - 1) * state.offsetWidth / 2,
  2035. top: (scaleNum - 1) * state.offsetHeight / 2
  2036. };
  2037. _this2.changeStyle(cloneEl, ["left: ".concat(state.left, "px"), "top: ".concat(state.top, "px"), 'transition: all 0.3s', "width: ".concat(state.offsetWidth * scaleNum + 'px'), "height:auto", "transform: translate(".concat(offsetDistance.left - state.left - diffs.left, "px, ").concat(offsetDistance.top - state.top - diffs.top, "px)")], true);
  2038.  
  2039. /** @描述 消除偏差:让图片相对于window 0 0定位,通过translate设置中心点重合*/
  2040. setTimeout(function () {
  2041. that.changeStyle(cloneEl, ['transition: all 0s', "left: 0", "top: 0", "transform: translate(".concat(offsetDistance.left - diffs.left, "px, ").concat(offsetDistance.top - diffs.top, "px)")]);
  2042. that.state.offset = {
  2043. left: offsetDistance.left - diffs.left,
  2044. top: offsetDistance.top - diffs.top
  2045. };
  2046. // 记录值
  2047. that.record();
  2048. }, 300);
  2049. });
  2050. /** @描述 计算自适应屏幕的缩放 */
  2051. defineProperty_defineProperty(this, "adaptScale", function () {
  2052. var _this2$state = _this2.state,
  2053. winWidth = _this2$state.winWidth,
  2054. winHeight = _this2$state.winHeight,
  2055. originalEl = _this2$state.originalEl;
  2056. var w = originalEl.offsetWidth,
  2057. h = originalEl.offsetHeight;
  2058. var scale = (winWidth - 60) / w;
  2059. if (h * scale > winHeight - 60) {
  2060. scale = (winHeight - 60) / h;
  2061. }
  2062. return scale;
  2063. });
  2064. this.state = Object.assign({}, this.state, this.mergeOptions(_shadowRoot, _originalEl, _src));
  2065. var _cloneEl = this.appendImg(_src, _originalEl);
  2066. this.state.cloneEl = _cloneEl;
  2067. this.fixPosition(_cloneEl);
  2068. this.onEventsController(_cloneEl);
  2069. // return this
  2070. }
  2071. return createClass_createClass(ImgItemInModal, [{
  2072. key: "record",
  2073. value: /** @描述 记录初始化数据 */
  2074. function record() {
  2075. var state = this.state;
  2076. state.initialData = Object.assign({}, {
  2077. offset: state.offset,
  2078. origin: state.origin,
  2079. scale: state.scale
  2080. });
  2081. }
  2082. }]);
  2083. }();
  2084. function run() {
  2085. try {
  2086. if (codeIsNotExcutable('previewImg', {
  2087. name: '图文对照阅读',
  2088. feature: '图片预览,固定图片,便于图文对照阅读',
  2089. includedUrls: []
  2090. }).notExcutable) return;
  2091. var shadowRoot = new ImgPreviewer({
  2092. backgroundColor: 'transparent'
  2093. });
  2094. } catch (error) {
  2095. console.error(error);
  2096. }
  2097. }
  2098. ;// CONCATENATED MODULE: ./src/tool/addBackgroundImg.js
  2099.  
  2100. /**
  2101. * @description 添加背景色
  2102. */
  2103. function addBackgroundImg_run() {
  2104. try {
  2105. if (codeIsNotExcutable('addBackgroundImg', {
  2106. name: '添加背景图片',
  2107. feature: '使用浏览器查看在线图片或本地图片时,增加页面背景图,以便清晰显示当前图片轮廓',
  2108. includedUrls: []
  2109. }).notExcutable) return;
  2110. addBackgroundImg();
  2111. } catch (error) {
  2112. console.error(error);
  2113. }
  2114. }
  2115.  
  2116. /** @描述 添加背景色*/
  2117. function addBackgroundImg() {
  2118. var ua = navigator.userAgent.toLowerCase();
  2119. var doc = document.body || document.documentElement;
  2120. var isQQBrowser = ua.indexOf('qqbrowser/') > -1;
  2121. if (document.contentType.startsWith('image/')) {
  2122. if (isQQBrowser && doc.tagName !== 'svg') {
  2123. setTimeout(function () {
  2124. loaded();
  2125. }, 666);
  2126. } else {
  2127. loaded();
  2128. }
  2129. }
  2130. }
  2131. function loaded() {
  2132. var doc = document.body || document.documentElement;
  2133. var win = window;
  2134. // var bgImage = `data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI2NCIgaGVpZ2h0PSI2NCI+PHBhdGggZD0iTTAgMGgzMnYzMkgwem0zMiAzMmgzMnYzMkgzMnoiIGZpbGw9IiMzMzMiLz48cGF0aCBkPSJNMCAzMmgzMnYzMkgwek0zMiAwaDMydjMySDMyeiIgZmlsbD0iIzIyMiIvPjwvc3ZnPg==`
  2135.  
  2136. var bgCSS = "repeating-conic-gradient(#202020 0, #202020 25%, #303030 0, #303030 50%) 0 0/30px 30px !important";
  2137.  
  2138. /* .bgImage{
  2139. background: #202020;
  2140. background-image: linear-gradient(45deg, #303030 25%, transparent 0), linear-gradient(45deg, transparent 75%, #303030 0), linear-gradient(45deg, #303030 25%, transparent 0), linear-gradient(45deg, transparent 75%, #303030 0);
  2141. background-position: 0 0, 15px 15px, 15px 15px, 30px 30px;
  2142. background-size: 30px 30px;
  2143. } */
  2144.  
  2145. var docTagName = function (tag) {
  2146. var tagName = tag && tag.tagName.toLowerCase();
  2147. if (tagName) {
  2148. if (tagName == 'svg') {
  2149. return tagName;
  2150. }
  2151. if (tagName == 'body' && tag.children && tag.children.length) {
  2152. tagName = tag.children[0].tagName.toLowerCase();
  2153. if (tagName == 'img') {
  2154. return tagName;
  2155. } else {
  2156. tagName = document.querySelector('img');
  2157. return tagName && tagName.tagName && tagName.tagName.toLowerCase();
  2158. }
  2159. }
  2160. }
  2161. }(doc);
  2162. var isViewerMode = docTagName == 'svg' || docTagName == 'img';
  2163. var imgOutlineCss = "img:hover{outline: 0.5px dotted rgb(254 254 254 / 20%);}";
  2164. if (isViewerMode) {
  2165. if (document.head) {
  2166. var styleText = [];
  2167. if (isQQBrowserPS()) {
  2168. styleText.push("body{box-sizing: border-box;background-attachment: fixed !important;background-repeat: repeat !important;}");
  2169. // styleText.push(`body{background: url(${bgImage}) !important;}`)
  2170. styleText.push("body{background: ".concat(bgCSS, ";}"));
  2171. } else {
  2172. styleText.push("img{position: static !important;background-color: rgba(0, 0, 0, 0) !important;}".concat(imgOutlineCss));
  2173. }
  2174. if (document.body.innerText) {
  2175. createElement('style', {
  2176. randomType: 'newOne',
  2177. el: 'head',
  2178. type: 'text/css',
  2179. innerHTML: styleText.join('')
  2180. }, win);
  2181. } else {
  2182. // 本地图片文件
  2183. createElement('style', {
  2184. randomType: 'newOne',
  2185. el: 'head',
  2186. type: 'text/css',
  2187. innerHTML: "body{background: ".concat(bgCSS, ";}img{background-color: rgba(0, 0, 0, 0) !important;}").concat(imgOutlineCss)
  2188. }, win);
  2189. }
  2190. }
  2191. if (isQQBrowserPS()) {
  2192. doc.style.position = 'static';
  2193. doc.style.top = 'auto';
  2194. doc.style.left = 'auto';
  2195. doc.style.transform = 'none';
  2196. } else {
  2197. // doc.style.backgroundImage = `url(${bgImage})`
  2198. doc.style.background = bgCSS;
  2199. doc.style.backgroundAttachment = 'fixed';
  2200. doc.style.boxSizing = 'border-box';
  2201. doc.style.outline = '1px dashed #696767';
  2202. if (docTagName == 'svg') {
  2203. doc.style.position = 'absolute';
  2204. doc.style.top = '50%';
  2205. doc.style.left = '50%';
  2206. doc.style.transform = 'translate(-50%, -50%)';
  2207. doc.style.margin = '10px';
  2208. doc.style.width = 'auto';
  2209. doc.style.height = 'auto';
  2210. doc.style.maxWidth = '100%';
  2211. doc.style.maxHeight = '100%';
  2212. }
  2213. }
  2214. }
  2215. function isQQBrowserPS() {
  2216. return document && document.body && document.body.classList.contains('qb-picture-ps');
  2217. }
  2218. }
  2219. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
  2220. function _arrayLikeToArray(r, a) {
  2221. (null == a || a > r.length) && (a = r.length);
  2222. for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  2223. return n;
  2224. }
  2225.  
  2226. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
  2227.  
  2228. function _arrayWithoutHoles(r) {
  2229. if (Array.isArray(r)) return _arrayLikeToArray(r);
  2230. }
  2231.  
  2232. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/iterableToArray.js
  2233. function _iterableToArray(r) {
  2234. if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
  2235. }
  2236.  
  2237. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
  2238.  
  2239. function _unsupportedIterableToArray(r, a) {
  2240. if (r) {
  2241. if ("string" == typeof r) return _arrayLikeToArray(r, a);
  2242. var t = {}.toString.call(r).slice(8, -1);
  2243. 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;
  2244. }
  2245. }
  2246.  
  2247. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js
  2248. function _nonIterableSpread() {
  2249. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  2250. }
  2251.  
  2252. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/toConsumableArray.js
  2253.  
  2254.  
  2255.  
  2256.  
  2257. function _toConsumableArray(r) {
  2258. return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
  2259. }
  2260.  
  2261. ;// CONCATENATED MODULE: ./node_modules/.pnpm/@babel+runtime@7.25.6/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
  2262. function asyncGeneratorStep(n, t, e, r, o, a, c) {
  2263. try {
  2264. var i = n[a](c),
  2265. u = i.value;
  2266. } catch (n) {
  2267. return void e(n);
  2268. }
  2269. i.done ? t(u) : Promise.resolve(u).then(r, o);
  2270. }
  2271. function asyncToGenerator_asyncToGenerator(n) {
  2272. return function () {
  2273. var t = this,
  2274. e = arguments;
  2275. return new Promise(function (r, o) {
  2276. var a = n.apply(t, e);
  2277. function _next(n) {
  2278. asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
  2279. }
  2280. function _throw(n) {
  2281. asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
  2282. }
  2283. _next(void 0);
  2284. });
  2285. };
  2286. }
  2287.  
  2288. ;// CONCATENATED MODULE: ./src/tool/openUrlInText.js
  2289.  
  2290.  
  2291.  
  2292.  
  2293. /**
  2294. * @description 含有链接的文本,点击时跳转相应链接
  2295. * @export
  2296. */
  2297. function openUrlInText_run() {
  2298. try {
  2299. if (codeIsNotExcutable('openUrlInText', {
  2300. name: '单击打开文本中链接',
  2301. feature: '点击链接文本时,跳转相应链接,便于查看链接地址的内容',
  2302. includedUrls: []
  2303. }).notExcutable) return;
  2304. var openPlus = new OpenPlus();
  2305. window.addEventListener('click', /*#__PURE__*/function () {
  2306. var _ref = asyncToGenerator_asyncToGenerator(/*#__PURE__*/regenerator_default().mark(function _callee(e) {
  2307. var _innerTextsOfAllText$;
  2308. var dom, innerTextsOfAllText, url;
  2309. return regenerator_default().wrap(function _callee$(_context) {
  2310. while (1) switch (_context.prev = _context.next) {
  2311. case 0:
  2312. dom = e.target; // 非左击
  2313. if (!(e.button !== 0)) {
  2314. _context.next = 3;
  2315. break;
  2316. }
  2317. return _context.abrupt("return");
  2318. case 3:
  2319. if (!(dom.childElementCount && !_toConsumableArray(dom.childNodes).find(function (item) {
  2320. var _item$textContent$mat, _item$textContent;
  2321. return item.nodeName === '#text' && ((_item$textContent$mat = (_item$textContent = item.textContent).match) === null || _item$textContent$mat === void 0 ? void 0 : _item$textContent$mat.call(_item$textContent, /https?:\/\/[\S]{4,}/));
  2322. }))) {
  2323. _context.next = 5;
  2324. break;
  2325. }
  2326. return _context.abrupt("return");
  2327. case 5:
  2328. if (!(dom.tagName === 'A' && dom !== null && dom !== void 0 && dom.href)) {
  2329. _context.next = 7;
  2330. break;
  2331. }
  2332. return _context.abrupt("return");
  2333. case 7:
  2334. if (!isContentEditableOfDOM()) {
  2335. _context.next = 9;
  2336. break;
  2337. }
  2338. return _context.abrupt("return");
  2339. case 9:
  2340. if (!window.getSelection().toString()) {
  2341. _context.next = 11;
  2342. break;
  2343. }
  2344. return _context.abrupt("return");
  2345. case 11:
  2346. innerTextsOfAllText = dom.innerText;
  2347. url = innerTextsOfAllText === null || innerTextsOfAllText === void 0 || (_innerTextsOfAllText$ = innerTextsOfAllText.match) === null || _innerTextsOfAllText$ === void 0 ? void 0 : _innerTextsOfAllText$.call(innerTextsOfAllText, /https?:\/\/[\S]{4,}/);
  2348. if (url) {
  2349. /* openPlus.openPre(
  2350. async () => {
  2351. await awaitTime(100)
  2352. createLinkStyle(url[0], dom)
  2353. },
  2354. url[0],
  2355. url[0]
  2356. ) */
  2357. openPlus.open(url[0], url[0]);
  2358. }
  2359. case 14:
  2360. case "end":
  2361. return _context.stop();
  2362. }
  2363. }, _callee);
  2364. }));
  2365. return function (_x) {
  2366. return _ref.apply(this, arguments);
  2367. };
  2368. }(), {
  2369. capture: true //利用捕获阶段,解决【阻止冒泡】阻断事件传播
  2370. });
  2371. /* function createLinkStyle(url, element) {
  2372. if (!url) return
  2373. element.innerHTML = element.innerHTML.trim().split(url).join(`<a href='${url}' target='${url}'> ${url} </a>`)
  2374. } */
  2375. } catch (error) {
  2376. console.error(error);
  2377. }
  2378. }
  2379.  
  2380. /*
  2381. window.open打开已在的窗口(不同源)时只激活不刷新
  2382.  
  2383.  
  2384. 备注:
  2385.  
  2386.  
  2387.  
  2388. */
  2389. ;// CONCATENATED MODULE: ./src/tool/copySelectedText.js
  2390.  
  2391.  
  2392. /**
  2393. * @description 复制所选文字:鼠标选中文字后,0.5秒内松开左键,自动复制到剪贴板;超过 0.5秒后松开,不再进行复制;一键复制代码块:鼠标悬浮代码块后,点击显示的红色边框,复制到剪贴板
  2394. * @export
  2395. */
  2396. function copySelectedText_run() {
  2397. try {
  2398. var onEmitCopyHandle = function onEmitCopyHandle(e, is_mousemove) {
  2399. if (isContentEditableOfDOM()) return;
  2400. var dom = e.target;
  2401.  
  2402. // window.getSelection().toString() 双击空白处 会选中 \n
  2403. var selectedText = window.getSelection().toString().trim();
  2404. if (!is_mousemove) {
  2405. // 不是手动选择的,即双击选中的
  2406. if (selectedText.length <= 2) {
  2407. return; // 不复制
  2408. }
  2409. }
  2410.  
  2411. // || dom.tagName === 'BLOCKQUOTE'
  2412. // https://mp.weixin.qq.com/s/1iBEjoZeA7bUmpAA1KEYhA
  2413.  
  2414. /*
  2415. https://blog.csdn.net/Charissa2017/article/details/103863588
  2416. offsetWidth 盒子自身占据的空间 ,包含 边框
  2417. clientWidth 盒子自身容器拥有的空间 ,包含 padding,但 不包含边框
  2418. */
  2419. //
  2420.  
  2421. if (dom.tagName === 'PRE' && e.target.offsetWidth >= e.offsetX && e.target.clientWidth <= e.offsetX) {
  2422. var getCodesInnerText = function getCodesInnerText(dom, selector) {
  2423. var nodeList = dom.querySelectorAll('code');
  2424. if (nodeList.length) {
  2425. return _toConsumableArray(nodeList).reduce(function (pre, cur) {
  2426. return pre + cur.innerText + '\n';
  2427. }, '');
  2428. }
  2429. return '';
  2430. };
  2431. // dom.querySelector('code')?.innerText csdn 序号在pre标签里
  2432.  
  2433. // const willCopyText = selectedText || dom.querySelector('code')?.innerText || dom.innerText
  2434. // const willCopyText = selectedText || dom.innerText
  2435.  
  2436. var willCopyText = selectedText || getCodesInnerText(dom, 'code') || dom.innerText;
  2437. copyTextAndTip(e, willCopyText, selectedText);
  2438. } else if (selectedText) {
  2439. copyTextAndTip(e, '', selectedText);
  2440. }
  2441. }; // document.documentElement.addEventListener('click', onEmitCopyHandle, {
  2442. // capture: true, //利用捕获阶段,解决【阻止冒泡】阻断事件传播
  2443. // })
  2444. var copyTextAndTip = function copyTextAndTip(e, willCopyText, selectedText) {
  2445. setTimeout(function () {
  2446. createElementTip({
  2447. e: e,
  2448. content: selectedText ? '文字_复制成功' : '代码块_复制成功'
  2449. });
  2450. doCopy((willCopyText || selectedText).trim());
  2451. }, 500);
  2452. };
  2453. // const filename = 'copySelectedText'
  2454. var filename = "copySelectedText";
  2455. if (codeIsNotExcutable(filename, {
  2456. name: '复制所选文本',
  2457. feature: '1、复制所选文字:鼠标选中文字后,0.5秒 后松开左键后,自动复制到剪贴板,超过 0.5秒松开,不进行复制;2、一键复制代码块:鼠标悬浮代码块后,点击显示的红色边框,复制到剪贴板',
  2458. includedUrls: []
  2459. }).notExcutable) return;
  2460. createElement('style', {
  2461. el: 'head',
  2462. id: 'a_click_target',
  2463. randomType: 'newOne',
  2464. textContent: "\n\t\t/* \u5141\u8BB8\u590D\u5236 */\n\t\t* {\n\t\t\tuser-select: text !important;\n\t\t}\n\n\t\t/* fix https://developer.mozilla.org/zh-CN/play */\n\t\tpre, code{\n\t\t\tword-break: break-all;\n\t\t}\n\n\t\t/* \u4E00\u952E\u590D\u5236\u4EE3\u7801\uFF1A\u9F20\u6807\u60AC\u6D6E\u4EE3\u7801\uFF0C\u70B9\u51FB\u7EA2\u8272\u8FB9\u6846 */\n\t\t:not(blockquote, pre) > pre {\n\t\t\t/* border-left: 8px solid #6d6b6b45 !important; */\n\t\t\t/* border-left: 8px solid transparent !important; */\n\t\t\tborder-radius: 4px !important;\n\t\t\toverflow-x: auto !important;\n\t\t\twhite-space: pre-wrap !important;\n\t\t\tcursor: pointer;\n\t\t}\n\t\t:not(blockquote, pre) > pre:hover {\n\t\t\t/* border-left-color: #6709099c !important; */\n\t\t\tborder-right: 8px solid #6709099c !important;\n\t\t\tmargin-right: -8px;\n\t\t\tposition: relative;\n\t\t}\n\n\t\t/* :not(blockquote, pre) > pre:hover:after {\n\t\t\tcontent: '\u4E00\u952E\u590D\u5236';\n\t\t\tdisplay: inline-block;\n\t\t\twidth: 10px;\n\t\t\ttransform: translateX(-4px);\n\t\t\tfont-size: 10px;\n\t\t\tposition: absolute;\n\t\t\ttop: 0;\n\t\t\tright: -4px;\n\t\t\tcolor: #fff;\n\t\t\tline-height: 14px;\n\t\t\tbackground: #a26969;\n\t\t\tpadding: 0 0 6px 4px;\n\t\t\tborder-radius: 0 0 0 16px;\n\t\t} */\n\n\t\t/* \u6CE8\u91CA\u6587\u672C\u8FC7\u957F\u65F6\uFF0C\u6362\u884C */\n\t\t:not(blockquote, pre) > pre > * {\n\t\t\tborder-radius: 0 !important;\n\t\t\twhite-space: pre-wrap !important;\n\t\t\tcursor: auto;\n\t\t}\n\n\t\t:not(blockquote, pre) > pre code {\n\t\t\tdisplay: block !important;\n\t\t}\n"
  2465. });
  2466. var createElementTip = createElementTipFn();
  2467. var pre_done_time = 0;
  2468. var is_mousedown = false;
  2469. var is_mousemove = false; // 避免双击时,选中复制
  2470. document.documentElement.addEventListener('mousedown', function () {
  2471. is_mousedown = true;
  2472. pre_done_time = Date.now();
  2473. }, {
  2474. capture: true //利用捕获阶段,解决【阻止冒泡】阻断事件传播
  2475. });
  2476. document.documentElement.addEventListener('mousemove', function () {
  2477. if (is_mousedown) {
  2478. pre_done_time = Date.now();
  2479. is_mousemove = true;
  2480. }
  2481. }, {
  2482. capture: true //利用捕获阶段,解决【阻止冒泡】阻断事件传播
  2483. });
  2484. document.documentElement.addEventListener('mouseup', function (e) {
  2485. if (Date.now() - pre_done_time < 500) {
  2486. if (e.shiftKey) {
  2487. onEmitCopyHandle(e, true);
  2488. } else if (is_mousedown) {
  2489. onEmitCopyHandle(e, is_mousemove);
  2490. }
  2491. }
  2492. is_mousedown = false;
  2493. is_mousemove = false;
  2494. }, {
  2495. capture: true //利用捕获阶段,解决【阻止冒泡】阻断事件传播
  2496. });
  2497. } catch (error) {
  2498. console.error(error);
  2499. }
  2500. }
  2501. ;// CONCATENATED MODULE: ./src/tool/csdn.js
  2502.  
  2503. function csdn_run() {
  2504. try {
  2505. if (codeIsNotExcutable('csdn', {
  2506. name: 'csdn登录',
  2507. feature: 'CSDN:仅在主动触发登录时,显示登录弹层,以便减少不必要的登录',
  2508. includedUrls: ['csdn.net']
  2509. }).notExcutable) return;
  2510. createElement('style', {
  2511. el: 'head',
  2512. id: 'csdn-ui',
  2513. textContent: "\n /* csdn \u4EE3\u7801\u5185\u5BB9\u5168\u5C55\u793A */\n .hide-preCode-box{\n padding-top:0px !important;\n }\n\n /* \u9690\u85CF\u3010\u767B\u5F55\u540E\u590D\u5236\u3011\u6587\u6848*/\n .hljs-button.signin{\n opacity:0;\n }\n\n /* csdn\u767B\u5F55\u5F39\u5C42\u79FB\u81F3\u5DE6\u4E0B\u89D2\n .passport-login-container {\n top:calc(100vh - 485px) !important;\n width:410px !important;\n height: 520px !important;\n border-radius: 8px !important;\n box-shadow: -5px 5px 10px 5px #979393 !important;\n transform: scale(0.8) !important;\n left: -24px;\n }\n */\n "
  2514. });
  2515. createElement('style', {
  2516. el: 'head',
  2517. addPrefix: '',
  2518. id: 'csdn-ui-login',
  2519. randomType: 'single',
  2520. textContent: "\n /* \u9690\u85CF\u767B\u5F55\u5F39\u5C42 */\n .passport-login-container{\n display:none;\n }\n .passport-login-mark {\n display:none !important;\n }\n "
  2521. });
  2522. document.addEventListener('click', function (e) {
  2523. var _target$className, _target$className$inc;
  2524. var target = e.target;
  2525. if ((_target$className = target.className) !== null && _target$className !== void 0 && (_target$className$inc = _target$className.includes) !== null && _target$className$inc !== void 0 && _target$className$inc.call(_target$className, 'toolbar-btn-loginfun')) {
  2526. var _document$querySelect;
  2527. (_document$querySelect = document.querySelector('#csdn-ui-login')) === null || _document$querySelect === void 0 || _document$querySelect.remove();
  2528. }
  2529. });
  2530. } catch (error) {
  2531. console.error(error);
  2532. }
  2533. }
  2534. ;// CONCATENATED MODULE: ./src/tool/calibreUI.js
  2535.  
  2536. // 解压后的epub电子书 浏览器预览
  2537. function calibreUI_run() {
  2538. try {
  2539. if (location.href.toLocaleLowerCase().includes('/oebps/text/')) {
  2540. modifyUI();
  2541. }
  2542. } catch (error) {
  2543. console.error(error);
  2544. }
  2545. }
  2546. function modifyUI() {
  2547. createElement('style', {
  2548. id: 'calibreUI',
  2549. innerHTML: "\n\t\t\tbody {\n\t\t\t\tmax-width:700px;\n\t\t\t}\n\t\t\t"
  2550. }, window);
  2551. }
  2552. ;// CONCATENATED MODULE: ./src/ImgPreview.js
  2553.  
  2554. ImgPreview_run();
  2555. function ImgPreview_run() {
  2556. run();
  2557. addBackgroundImg_run();
  2558. openUrlInText_run();
  2559. copySelectedText_run();
  2560. csdn_run();
  2561. calibreUI_run();
  2562. }
  2563. })();
  2564.  
  2565. /******/ })()
  2566. ;