Greasy Fork is available in English.

Force Enable Vue Devtools

Force enable Vue Devtools for any Vue2 or Vue3 production build.

Από την 13/08/2021. Δείτε την τελευταία έκδοση.

  1. // ==UserScript==
  2. // @name Force Enable Vue Devtools
  3. // @version 0.2.2
  4. // @author Huang-Huang Bao <eh5@sokka.cn> (https://github.com/EHfive)
  5. // @description Force enable Vue Devtools for any Vue2 or Vue3 production build.
  6. // @homepage https://github.com/EHfive/userscripts/tree/master/userscripts/enbale-vue-devtools
  7. // @supportURL https://github.com/EHfive/userscripts/issues
  8. // @namespace https://eh5.me
  9. // @name:zh-CN 强制开启Vue Devtools
  10. // @name:zh-TW 強制開啓Vue Devtools
  11. // @description:zh-CN 为生产构建的Vue2或Vue3应用强制开启Vue Devtools
  12. // @description:zh-TW 爲生產構建的Vue2或Vue3應用強制開啓Vue Devtools
  13. // @license MIT
  14. // @run-at document-start
  15. // @noframes
  16. // @include /^.*$/
  17. // @grant unsafeWindow
  18. // @grant GM_info
  19. // @grant GM.info
  20. // ==/UserScript==
  21.  
  22. /******/ (function(modules) { // webpackBootstrap
  23. /******/ // The module cache
  24. /******/ var installedModules = {};
  25. /******/
  26. /******/ // The require function
  27. /******/ function __webpack_require__(moduleId) {
  28. /******/
  29. /******/ // Check if module is in cache
  30. /******/ if(installedModules[moduleId]) {
  31. /******/ return installedModules[moduleId].exports;
  32. /******/ }
  33. /******/ // Create a new module (and put it into the cache)
  34. /******/ var module = installedModules[moduleId] = {
  35. /******/ i: moduleId,
  36. /******/ l: false,
  37. /******/ exports: {}
  38. /******/ };
  39. /******/
  40. /******/ // Execute the module function
  41. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  42. /******/
  43. /******/ // Flag the module as loaded
  44. /******/ module.l = true;
  45. /******/
  46. /******/ // Return the exports of the module
  47. /******/ return module.exports;
  48. /******/ }
  49. /******/
  50. /******/
  51. /******/ // expose the modules object (__webpack_modules__)
  52. /******/ __webpack_require__.m = modules;
  53. /******/
  54. /******/ // expose the module cache
  55. /******/ __webpack_require__.c = installedModules;
  56. /******/
  57. /******/ // define getter function for harmony exports
  58. /******/ __webpack_require__.d = function(exports, name, getter) {
  59. /******/ if(!__webpack_require__.o(exports, name)) {
  60. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  61. /******/ }
  62. /******/ };
  63. /******/
  64. /******/ // define __esModule on exports
  65. /******/ __webpack_require__.r = function(exports) {
  66. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  67. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  68. /******/ }
  69. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  70. /******/ };
  71. /******/
  72. /******/ // create a fake namespace object
  73. /******/ // mode & 1: value is a module id, require it
  74. /******/ // mode & 2: merge all properties of value into the ns
  75. /******/ // mode & 4: return value when already ns object
  76. /******/ // mode & 8|1: behave like require
  77. /******/ __webpack_require__.t = function(value, mode) {
  78. /******/ if(mode & 1) value = __webpack_require__(value);
  79. /******/ if(mode & 8) return value;
  80. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  81. /******/ var ns = Object.create(null);
  82. /******/ __webpack_require__.r(ns);
  83. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  84. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  85. /******/ return ns;
  86. /******/ };
  87. /******/
  88. /******/ // getDefaultExport function for compatibility with non-harmony modules
  89. /******/ __webpack_require__.n = function(module) {
  90. /******/ var getter = module && module.__esModule ?
  91. /******/ function getDefault() { return module['default']; } :
  92. /******/ function getModuleExports() { return module; };
  93. /******/ __webpack_require__.d(getter, 'a', getter);
  94. /******/ return getter;
  95. /******/ };
  96. /******/
  97. /******/ // Object.prototype.hasOwnProperty.call
  98. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  99. /******/
  100. /******/ // __webpack_public_path__
  101. /******/ __webpack_require__.p = "https://localhost:9000/";
  102. /******/
  103. /******/
  104. /******/ // Load entry module and return exports
  105. /******/ return __webpack_require__(__webpack_require__.s = 1);
  106. /******/ })
  107. /************************************************************************/
  108. /******/ ([
  109. /* 0 */
  110. /***/ (function(module, exports) {
  111.  
  112. !function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t);n(1);(function(){"object"==typeof unsafeWindow&&unsafeWindow&&(unsafeWindow.GM=this.GM)}).call(window)},function(e,t){(function(){"undefined"==typeof GM&&(this.GM={}),"undefined"==typeof GM_addStyle&&(this.GM_addStyle=e=>{"use strict";let t=document.getElementsByTagName("head")[0];if(t){let n=document.createElement("style");return n.setAttribute("type","text/css"),n.textContent=e,t.appendChild(n),n}return null}),"undefined"==typeof GM_registerMenuCommand&&(this.GM_registerMenuCommand=(e,t,n)=>{if(!document.body)return void("loading"===document.readyState&&document.documentElement&&"html"===document.documentElement.localName?new MutationObserver((o,r)=>{document.body&&(r.disconnect(),GM_registerMenuCommand(e,t,n))}).observe(document.documentElement,{childList:!0}):console.error("GM_registerMenuCommand got no body."));let o=document.body.getAttribute("contextmenu"),r=o?document.querySelector("menu#"+o):null;r||(r=document.createElement("menu"),r.setAttribute("id","gm-registered-menu"),r.setAttribute("type","context"),document.body.appendChild(r),document.body.setAttribute("contextmenu","gm-registered-menu"));let u=document.createElement("menuitem");u.textContent=e,u.addEventListener("click",t,!0),r.appendChild(u)}),"undefined"==typeof GM_getResourceText&&(this.GM_getResourceText=e=>{"use strict";return GM.getResourceUrl(e).then(e=>fetch(e)).then(e=>e.text()).catch((function(e){return GM.log("Request failed",e),null}))}),Object.entries({log:console.log.bind(console),info:GM_info}).forEach(([e,t])=>{t&&void 0===GM[e]&&(GM[e]=t)}),Object.entries({GM_addStyle:"addStyle",GM_deleteValue:"deleteValue",GM_getResourceURL:"getResourceUrl",GM_getValue:"getValue",GM_listValues:"listValues",GM_notification:"notification",GM_openInTab:"openInTab",GM_registerMenuCommand:"registerMenuCommand",GM_setClipboard:"setClipboard",GM_setValue:"setValue",GM_xmlhttpRequest:"xmlHttpRequest",GM_getResourceText:"getResourceText"}).forEach(([e,t])=>{let n=this[e];n&&void 0===GM[t]&&(GM[t]=function(...e){return new Promise((t,o)=>{try{t(n.apply(this,e))}catch(e){o(e)}})})})}).call(window)}]);
  113.  
  114. /***/ }),
  115. /* 1 */
  116. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  117.  
  118. "use strict";
  119. // ESM COMPAT FLAG
  120. __webpack_require__.r(__webpack_exports__);
  121.  
  122. // EXTERNAL MODULE: /home/eh5/Projects/userscripts/packages/polyfills/dist/index.js
  123. var dist = __webpack_require__(0);
  124.  
  125. // CONCATENATED MODULE: /home/eh5/Projects/userscripts/.yarn/cache/consola-npm-2.15.0-71e35f623c-9a20844425.zip/node_modules/consola/src/logLevels.js
  126. const LogLevel = {};
  127. LogLevel[LogLevel.Fatal = 0] = 'Fatal';
  128. LogLevel[LogLevel.Error = 0] = 'Error';
  129. LogLevel[LogLevel.Warn = 1] = 'Warn';
  130. LogLevel[LogLevel.Log = 2] = 'Log';
  131. LogLevel[LogLevel.Info = 3] = 'Info';
  132. LogLevel[LogLevel.Success = 3] = 'Success';
  133. LogLevel[LogLevel.Debug = 4] = 'Debug';
  134. LogLevel[LogLevel.Trace = 5] = 'Trace';
  135. LogLevel[LogLevel.Silent = -Infinity] = 'Silent';
  136. LogLevel[LogLevel.Verbose = Infinity] = 'Verbose';
  137. // CONCATENATED MODULE: /home/eh5/Projects/userscripts/.yarn/cache/consola-npm-2.15.0-71e35f623c-9a20844425.zip/node_modules/consola/src/types.js
  138.  
  139. /* harmony default export */ var src_types = ({
  140. // Silent
  141. silent: {
  142. level: -1
  143. },
  144. // Level 0
  145. fatal: {
  146. level: LogLevel.Fatal
  147. },
  148. error: {
  149. level: LogLevel.Error
  150. },
  151. // Level 1
  152. warn: {
  153. level: LogLevel.Warn
  154. },
  155. // Level 2
  156. log: {
  157. level: LogLevel.Log
  158. },
  159. // Level 3
  160. info: {
  161. level: LogLevel.Info
  162. },
  163. success: {
  164. level: LogLevel.Success
  165. },
  166. // Level 4
  167. debug: {
  168. level: LogLevel.Debug
  169. },
  170. // Level 5
  171. trace: {
  172. level: LogLevel.Trace
  173. },
  174. // Verbose
  175. verbose: {
  176. level: LogLevel.Trace
  177. },
  178. // Legacy
  179. ready: {
  180. level: LogLevel.Info
  181. },
  182. start: {
  183. level: LogLevel.Info
  184. }
  185. });
  186. // CONCATENATED MODULE: /home/eh5/Projects/userscripts/.yarn/cache/consola-npm-2.15.0-71e35f623c-9a20844425.zip/node_modules/consola/src/utils/index.js
  187. function isPlainObject(obj) {
  188. return Object.prototype.toString.call(obj) === '[object Object]';
  189. } // TODO: remove for consola@3
  190.  
  191. function isLogObj(arg) {
  192. // Should be plain object
  193. if (!isPlainObject(arg)) {
  194. return false;
  195. } // Should contains either 'message' or 'args' field
  196.  
  197.  
  198. if (!arg.message && !arg.args) {
  199. return false;
  200. } // Handle non-standard error objects
  201.  
  202.  
  203. if (arg.stack) {
  204. return false;
  205. }
  206.  
  207. return true;
  208. }
  209. // CONCATENATED MODULE: /home/eh5/Projects/userscripts/.yarn/cache/consola-npm-2.15.0-71e35f623c-9a20844425.zip/node_modules/consola/src/consola.js
  210.  
  211.  
  212. let paused = false;
  213. const queue = [];
  214.  
  215. class consola_Consola {
  216. constructor(options = {}) {
  217. this._reporters = options.reporters || [];
  218. this._types = options.types || src_types;
  219. this.level = options.level !== undefined ? options.level : 3;
  220. this._defaults = options.defaults || {};
  221. this._async = options.async !== undefined ? options.async : undefined;
  222. this._stdout = options.stdout;
  223. this._stderr = options.stderr;
  224. this._mockFn = options.mockFn;
  225. this._throttle = options.throttle || 1000;
  226. this._throttleMin = options.throttleMin || 5; // Create logger functions for current instance
  227.  
  228. for (const type in this._types) {
  229. this[type] = this._wrapLogFn(Object.assign({
  230. type
  231. }, this._types[type], this._defaults));
  232. } // Use _mockFn if is set
  233.  
  234.  
  235. if (this._mockFn) {
  236. this.mockTypes();
  237. } // Keep serialized version of last log
  238.  
  239.  
  240. this._lastLogSerialized = undefined;
  241. this._lastLog = undefined;
  242. this._lastLogTime = undefined;
  243. this._lastLogCount = 0;
  244. this._throttleTimeout = undefined;
  245. }
  246.  
  247. get stdout() {
  248. return this._stdout || console._stdout; // eslint-disable-line no-console
  249. }
  250.  
  251. get stderr() {
  252. return this._stderr || console._stderr; // eslint-disable-line no-console
  253. }
  254.  
  255. create(options) {
  256. return new consola_Consola(Object.assign({
  257. reporters: this._reporters,
  258. level: this.level,
  259. types: this._types,
  260. defaults: this._defaults,
  261. stdout: this._stdout,
  262. stderr: this._stderr,
  263. mockFn: this._mockFn
  264. }, options));
  265. }
  266.  
  267. withDefaults(defaults) {
  268. return this.create({
  269. defaults: Object.assign({}, this._defaults, defaults)
  270. });
  271. }
  272.  
  273. withTag(tag) {
  274. return this.withDefaults({
  275. tag: this._defaults.tag ? this._defaults.tag + ':' + tag : tag
  276. });
  277. }
  278.  
  279. addReporter(reporter) {
  280. this._reporters.push(reporter);
  281.  
  282. return this;
  283. }
  284.  
  285. removeReporter(reporter) {
  286. if (reporter) {
  287. const i = this._reporters.indexOf(reporter);
  288.  
  289. if (i >= 0) {
  290. return this._reporters.splice(i, 1);
  291. }
  292. } else {
  293. this._reporters.splice(0);
  294. }
  295.  
  296. return this;
  297. }
  298.  
  299. setReporters(reporters) {
  300. this._reporters = Array.isArray(reporters) ? reporters : [reporters];
  301. return this;
  302. }
  303.  
  304. wrapAll() {
  305. this.wrapConsole();
  306. this.wrapStd();
  307. }
  308.  
  309. restoreAll() {
  310. this.restoreConsole();
  311. this.restoreStd();
  312. }
  313.  
  314. wrapConsole() {
  315. for (const type in this._types) {
  316. // Backup original value
  317. if (!console['__' + type]) {
  318. // eslint-disable-line no-console
  319. console['__' + type] = console[type]; // eslint-disable-line no-console
  320. } // Override
  321.  
  322.  
  323. console[type] = this[type]; // eslint-disable-line no-console
  324. }
  325. }
  326.  
  327. restoreConsole() {
  328. for (const type in this._types) {
  329. // Restore if backup is available
  330. if (console['__' + type]) {
  331. // eslint-disable-line no-console
  332. console[type] = console['__' + type]; // eslint-disable-line no-console
  333.  
  334. delete console['__' + type]; // eslint-disable-line no-console
  335. }
  336. }
  337. }
  338.  
  339. wrapStd() {
  340. this._wrapStream(this.stdout, 'log');
  341.  
  342. this._wrapStream(this.stderr, 'log');
  343. }
  344.  
  345. _wrapStream(stream, type) {
  346. if (!stream) {
  347. return;
  348. } // Backup original value
  349.  
  350.  
  351. if (!stream.__write) {
  352. stream.__write = stream.write;
  353. } // Override
  354.  
  355.  
  356. stream.write = data => {
  357. this[type](String(data).trim());
  358. };
  359. }
  360.  
  361. restoreStd() {
  362. this._restoreStream(this.stdout);
  363.  
  364. this._restoreStream(this.stderr);
  365. }
  366.  
  367. _restoreStream(stream) {
  368. if (!stream) {
  369. return;
  370. }
  371.  
  372. if (stream.__write) {
  373. stream.write = stream.__write;
  374. delete stream.__write;
  375. }
  376. }
  377.  
  378. pauseLogs() {
  379. paused = true;
  380. }
  381.  
  382. resumeLogs() {
  383. paused = false; // Process queue
  384.  
  385. const _queue = queue.splice(0);
  386.  
  387. for (const item of _queue) {
  388. item[0]._logFn(item[1], item[2]);
  389. }
  390. }
  391.  
  392. mockTypes(mockFn) {
  393. this._mockFn = mockFn || this._mockFn;
  394.  
  395. if (typeof this._mockFn !== 'function') {
  396. return;
  397. }
  398.  
  399. for (const type in this._types) {
  400. this[type] = this._mockFn(type, this._types[type]) || this[type];
  401. }
  402. }
  403.  
  404. _wrapLogFn(defaults) {
  405. function logFn() {
  406. if (paused) {
  407. queue.push([this, defaults, arguments]);
  408. return;
  409. }
  410.  
  411. return this._logFn(defaults, arguments);
  412. }
  413.  
  414. return logFn.bind(this);
  415. }
  416.  
  417. _logFn(defaults, args) {
  418. if (defaults.level > this.level) {
  419. return this._async ? Promise.resolve(false) : false;
  420. } // Construct a new log object
  421.  
  422.  
  423. const logObj = Object.assign({
  424. date: new Date(),
  425. args: []
  426. }, defaults); // Consume arguments
  427.  
  428. if (args.length === 1 && isLogObj(args[0])) {
  429. Object.assign(logObj, args[0]);
  430. } else {
  431. logObj.args = Array.from(args);
  432. } // Aliases
  433.  
  434.  
  435. if (logObj.message) {
  436. logObj.args.unshift(logObj.message);
  437. delete logObj.message;
  438. }
  439.  
  440. if (logObj.additional) {
  441. if (!Array.isArray(logObj.additional)) {
  442. logObj.additional = logObj.additional.split('\n');
  443. }
  444.  
  445. logObj.args.push('\n' + logObj.additional.join('\n'));
  446. delete logObj.additional;
  447. } // Normalize type and tag to lowercase
  448.  
  449.  
  450. logObj.type = typeof logObj.type === 'string' ? logObj.type.toLowerCase() : '';
  451. logObj.tag = typeof logObj.tag === 'string' ? logObj.tag.toLowerCase() : ''; // Resolve log
  452.  
  453. /**
  454. * @param newLog false if the throttle expired and
  455. * we don't want to log a duplicate
  456. */
  457.  
  458. const resolveLog = (newLog = false) => {
  459. const repeated = this._lastLogCount - this._throttleMin;
  460.  
  461. if (this._lastLog && repeated > 0) {
  462. const args = [...this._lastLog.args];
  463.  
  464. if (repeated > 1) {
  465. args.push(`(repeated ${repeated} times)`);
  466. }
  467.  
  468. this._log({ ...this._lastLog,
  469. args
  470. });
  471.  
  472. this._lastLogCount = 1;
  473. } // Log
  474.  
  475.  
  476. if (newLog) {
  477. this._lastLog = logObj;
  478.  
  479. if (this._async) {
  480. return this._logAsync(logObj);
  481. } else {
  482. this._log(logObj);
  483. }
  484. }
  485. }; // Throttle
  486.  
  487.  
  488. clearTimeout(this._throttleTimeout);
  489. const diffTime = this._lastLogTime ? logObj.date - this._lastLogTime : 0;
  490. this._lastLogTime = logObj.date;
  491.  
  492. if (diffTime < this._throttle) {
  493. try {
  494. const serializedLog = JSON.stringify([logObj.type, logObj.tag, logObj.args]);
  495. const isSameLog = this._lastLogSerialized === serializedLog;
  496. this._lastLogSerialized = serializedLog;
  497.  
  498. if (isSameLog) {
  499. this._lastLogCount++;
  500.  
  501. if (this._lastLogCount > this._throttleMin) {
  502. // Auto-resolve when throttle is timed out
  503. this._throttleTimeout = setTimeout(resolveLog, this._throttle);
  504. return; // SPAM!
  505. }
  506. }
  507. } catch (_) {// Circular References
  508. }
  509. }
  510.  
  511. resolveLog(true);
  512. }
  513.  
  514. _log(logObj) {
  515. for (const reporter of this._reporters) {
  516. reporter.log(logObj, {
  517. async: false,
  518. stdout: this.stdout,
  519. stderr: this.stderr
  520. });
  521. }
  522. }
  523.  
  524. _logAsync(logObj) {
  525. return Promise.all(this._reporters.map(reporter => reporter.log(logObj, {
  526. async: true,
  527. stdout: this.stdout,
  528. stderr: this.stderr
  529. })));
  530. }
  531.  
  532. } // Legacy support
  533.  
  534.  
  535. consola_Consola.prototype.add = consola_Consola.prototype.addReporter;
  536. consola_Consola.prototype.remove = consola_Consola.prototype.removeReporter;
  537. consola_Consola.prototype.clear = consola_Consola.prototype.removeReporter;
  538. consola_Consola.prototype.withScope = consola_Consola.prototype.withTag;
  539. consola_Consola.prototype.mock = consola_Consola.prototype.mockTypes;
  540. consola_Consola.prototype.pause = consola_Consola.prototype.pauseLogs;
  541. consola_Consola.prototype.resume = consola_Consola.prototype.resumeLogs; // Export class
  542.  
  543. /* harmony default export */ var consola = (consola_Consola);
  544. // CONCATENATED MODULE: /home/eh5/Projects/userscripts/.yarn/cache/consola-npm-2.15.0-71e35f623c-9a20844425.zip/node_modules/consola/src/reporters/browser.js
  545. class BrowserReporter {
  546. constructor(options) {
  547. this.options = Object.assign({}, options);
  548. this.defaultColor = '#7f8c8d'; // Gray
  549.  
  550. this.levelColorMap = {
  551. 0: '#c0392b',
  552. // Red
  553. 1: '#f39c12',
  554. // Yellow
  555. 3: '#00BCD4' // Cyan
  556.  
  557. };
  558. this.typeColorMap = {
  559. success: '#2ecc71' // Green
  560.  
  561. };
  562. }
  563.  
  564. log(logObj) {
  565. const consoleLogFn = logObj.level < 1 // eslint-disable-next-line no-console
  566. ? console.__error || console.error : // eslint-disable-next-line no-console
  567. logObj.level === 1 && console.warn ? console.__warn || console.warn : console.__log || console.log; // Type
  568.  
  569. const type = logObj.type !== 'log' ? logObj.type : ''; // Tag
  570.  
  571. const tag = logObj.tag ? logObj.tag : ''; // Styles
  572.  
  573. const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor;
  574. const style = `
  575. background: ${color};
  576. border-radius: 0.5em;
  577. color: white;
  578. font-weight: bold;
  579. padding: 2px 0.5em;
  580. `;
  581. const badge = `%c${[tag, type].filter(Boolean).join(':')}`; // Log to the console
  582.  
  583. if (typeof logObj.args[0] === 'string') {
  584. consoleLogFn(`${badge}%c ${logObj.args[0]}`, style, // Empty string as style resets to default console style
  585. '', ...logObj.args.slice(1));
  586. } else {
  587. consoleLogFn(badge, style, ...logObj.args);
  588. }
  589. }
  590.  
  591. }
  592. // CONCATENATED MODULE: ./src/logger.js
  593.  
  594.  
  595. const pkgName = "enable-vue-devtools";
  596. const logger = new consola({
  597. reporters: [new BrowserReporter()],
  598. defaults: {
  599. tag: pkgName
  600. }
  601. });
  602. /* harmony default export */ var src_logger = (logger);
  603. // CONCATENATED MODULE: ./src/main.js
  604. /* harmony default export */ var main = (main_main);
  605.  
  606.  
  607. const _global = typeof unsafeWindow === 'object' && unsafeWindow || globalThis; // devtool hook should be ready when <body> exists
  608.  
  609.  
  610. const _devtoolHook = _global.__VUE_DEVTOOLS_GLOBAL_HOOK__;
  611.  
  612. function main_main() {
  613. if (!_devtoolHook) {
  614. src_logger.warn('No Vue Devtools hook found', _global.location);
  615. return;
  616. }
  617.  
  618. observeVueRoot(function (app, disconnect) {
  619. emitDevtoolVue2Hooks(app);
  620. }, function (app, disconnect) {
  621. emitDevtoolVue3Hooks(app);
  622. });
  623. }
  624.  
  625. function emitDevtoolVue2Hooks(app) {
  626. let Vue = app.constructor;
  627. const store = app.$store;
  628.  
  629. while (Vue.super) {
  630. // find base Vue
  631. Vue = Vue.super;
  632. }
  633.  
  634. Vue.config.devtools = true;
  635. src_logger.info('enabling devtools for Vue instance', app); // must re-emit 'init' if this Vue is different with other Vue(s)
  636. // otherwise this `Vue`'s root instance would not be added to Devtools store
  637. // https://github.com/vuejs/vue-devtools/blob/933063fd06860464be4bfd8c83ba09d7fc2c753e/packages/app-backend/src/index.js#L218-L225
  638.  
  639. _devtoolHook.emit('init', Vue); // TODO validate Vuex instance
  640.  
  641.  
  642. if (store) {
  643. src_logger.info('enabling devtools for Vuex instance', store);
  644. devtoolStorePlugin(store, _devtoolHook);
  645. }
  646. }
  647.  
  648. function emitDevtoolVue3Hooks(app) {
  649. if (!Array.isArray(_devtoolHook.apps)) return;
  650. if (_devtoolHook.apps.includes(app)) return;
  651. let version = app.version;
  652.  
  653. if (!version) {
  654. src_logger.warn('no Vue version detected, fallback to "3.0.0"');
  655. version = '3.0.0';
  656. }
  657.  
  658. src_logger.info('enabling devtools for Vue 3 instance', app); // FIXME: impossible to get those Symbols,
  659. // https://github.com/vuejs/vue-next/blob/410e7abbbb78e83989ad2e5a1793c290129dfdc7/packages/runtime-core/src/devtools.ts#L38
  660.  
  661. const types = {
  662. Fragment: undefined,
  663. Text: undefined,
  664. Comment: undefined,
  665. Static: undefined
  666. };
  667.  
  668. _devtoolHook.emit('app:init', app, version, types);
  669.  
  670. const unmount = app.unmount.bind(app);
  671.  
  672. app.unmount = function () {
  673. _devtoolHook.emit('app:unmount', app);
  674.  
  675. unmount();
  676. };
  677. }
  678.  
  679. function checkVue2Instance(target) {
  680. const vue = target && target.__vue__;
  681. return !!(vue && typeof vue === 'object' && vue._isVue && typeof vue.constructor === 'function');
  682. }
  683.  
  684. function checkVue3Instance(target) {
  685. const app = target && target.__vue_app__;
  686. return !!app;
  687. }
  688.  
  689. function noop() {}
  690.  
  691. function observeVueRoot(callbackVue2, callbackVue3) {
  692. if (typeof callbackVue2 !== 'function') {
  693. callbackVue2 = noop;
  694. }
  695.  
  696. if (typeof callbackVue3 !== 'function') {
  697. callbackVue3 = noop;
  698. }
  699.  
  700. const vue2RootSet = new WeakSet();
  701. const vue3RootSet = new WeakSet();
  702. const observer = new MutationObserver((mutations, observer) => {
  703. const disconnect = observer.disconnect.bind(observer);
  704.  
  705. for (const {
  706. target
  707. } of mutations) {
  708. if (!target) {
  709. return;
  710. } else if (checkVue2Instance(target)) {
  711. const inst = target.__vue__;
  712. const root = inst.$parent ? inst.$root : inst;
  713.  
  714. if (vue2RootSet.has(root)) {
  715. // already callback, continue loop
  716. continue;
  717. }
  718.  
  719. vue2RootSet.add(root);
  720. callbackVue2(root, disconnect);
  721. } else if (checkVue3Instance(target)) {
  722. const app = target.__vue_app__;
  723.  
  724. if (vue3RootSet.has(app)) {
  725. // already callback, continue loop
  726. continue;
  727. }
  728.  
  729. vue3RootSet.add(app);
  730. callbackVue3(app, disconnect);
  731. }
  732. }
  733. });
  734. observer.observe(document.documentElement, {
  735. attributes: true,
  736. subtree: true,
  737. childList: true
  738. });
  739. return observer;
  740. }
  741.  
  742. function devtoolStorePlugin(store, devtoolHook) {
  743. store._devtoolHook = devtoolHook;
  744. devtoolHook.emit('vuex:init', store);
  745. devtoolHook.on('vuex:travel-to-state', targetState => {
  746. store.replaceState(targetState);
  747. });
  748. store.subscribe((mutation, state) => {
  749. devtoolHook.emit('vuex:mutation', mutation, state);
  750. });
  751. }
  752. // CONCATENATED MODULE: ./src/index.js
  753.  
  754.  
  755.  
  756.  
  757. try {
  758. main();
  759.  
  760. if (false) {}
  761. } catch (e) {
  762. src_logger.error(e);
  763. }
  764.  
  765. /***/ })
  766. /******/ ]);