Greasy Fork is available in English.

vue-router-tool

vue项目路由切换工具

  1. // ==UserScript==
  2. // @name vue-router-tool
  3. // @namespace npm/vue-router-tool
  4. // @version 0.0.1
  5. // @author shixiaoshi
  6. // @license MIT
  7. // @description vue项目路由切换工具
  8. // @icon https://vitejs.dev/logo.svg
  9. // @match https://*/*
  10. // @match http://*/*
  11. // @require https://cdn.jsdelivr.net/npm/vue@3.3.4/dist/vue.global.prod.js
  12. // @connect localhost
  13. // @grant GM_deleteValue
  14. // @grant GM_getValue
  15. // @grant GM_listValues
  16. // @grant GM_registerMenuCommand
  17. // @grant GM_setValue
  18. // @grant unsafeWindow
  19. // @noframes
  20. // ==/UserScript==
  21.  
  22. (a=>{const e=document.createElement("style");e.dataset.source="vite-plugin-monkey",e.textContent=a,document.head.append(e)})(' .monkey-box-wrap[data-v-a5e7cb6f]{position:fixed;z-index:9999;background:rgba(255,255,255,.9);box-shadow:0 4px 8px #07111b33;border-radius:8px}.monkey-box-wrap[data-v-a5e7cb6f]:before{content:"";display:block;width:8px;height:8px;background:#fff;z-index:1900;position:absolute;transform:rotate(45deg);left:20px}.belowPart[data-v-a5e7cb6f]:before{bottom:-4px}.upPart[data-v-a5e7cb6f]:before{top:-4px}.router-wrap[data-v-8fdc01fd]{width:100%;padding:4px;max-height:200px;min-height:20px;overflow-y:auto;overflow-x:hidden;cursor:pointer}.router-wrap .no-data[data-v-8fdc01fd]{text-align:center;font-size:14px;line-height:30px;color:gray}.router-wrap .router-item[data-v-8fdc01fd]{border-radius:3px;padding:4px;align-items:center;justify-content:space-between;display:flex;transition:all .1s linear}.router-wrap .router-item .left[data-v-8fdc01fd]{width:20px;height:20px;border-radius:5px;background:#fff;display:flex;justify-content:center;align-items:center;padding:2px;overflow:hidden;transition:padding .1s linear}.router-wrap .router-item .left[data-v-8fdc01fd]:hover{padding:5px;transition:padding .1s linear}.router-wrap .router-item .right[data-v-8fdc01fd]{flex:1;display:flex;flex-flow:column;justify-content:space-between;margin-left:4px;height:28px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.router-wrap .router-item .right .path-wrap[data-v-8fdc01fd]{line-height:14px;display:block;font-size:12px;color:#303133;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.router-wrap .router-item .right .name-wrap[data-v-8fdc01fd]{font-size:12px;line-height:12px;color:#c3c7cb}.router-wrap .router-item[data-v-8fdc01fd]:hover{transform:translate(3px);background:#EBEDF0;box-shadow:0 4px 8px #07111b1a}.monkey-wrap[data-v-2c3d75a0]{position:fixed;cursor:pointer;z-index:9999;-webkit-user-select:none;user-select:none;background:rgba(255,255,255,.5);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px);box-shadow:0 4px 8px #07111b1a;border-radius:8px;display:flex;align-items:center;padding:2px 5px;height:32px;right:auto}.monkey-wrap .v-drag-handle[data-v-2c3d75a0]{cursor:move}.monkey-wrap .icon[data-v-2c3d75a0]{width:16px;height:16px;display:inline-block;display:flex;justify-content:center;align-items:center;overflow:hidden;margin:0 5px}.monkey-wrap .icon img[data-v-2c3d75a0]{width:16px}.monkey-wrap .monkey-home-wrap[data-v-2c3d75a0]{overflow:hidden;display:flex;height:25px;align-items:center;border-radius:15px;color:#0065b3;background-color:#e1f2ff}.monkey-wrap .monkey-home-wrap .monkey-name-wrap[data-v-2c3d75a0]{display:flex;min-width:80px;align-items:center}.monkey-wrap .monkey-home-wrap .monkey-name-wrap .monkey-arrow[data-v-2c3d75a0]{width:10px;height:10px;display:flex;justify-content:center;align-items:center;transform:rotate(180deg);margin:2px 10px 0 5px;transition:transform .3s}.monkey-wrap .monkey-home-wrap .monkey-name-wrap .monkey-arrow img[data-v-2c3d75a0]{width:10px}.monkey-wrap .monkey-home-wrap .monkey-name-wrap .monkey-name[data-v-2c3d75a0]{text-align:center;display:inline-block;margin:5px;font-size:13px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.monkey-wrap .monkey-home-wrap .monkey-name-wrap:hover .monkey-arrow[data-v-2c3d75a0]{transform:rotate(0);transition:transform .3s}.monkey-wrap .monkey-menu-wrap[data-v-2c3d75a0]{display:flex;align-items:center;margin-left:10px}.proxy .monkey-home-wrap[data-v-2c3d75a0]{background-color:#ffe6e6}.name-wrap-enter-active[data-v-2c3d75a0]{transition:all .2s ease-out}.name-wrap-leave-active[data-v-2c3d75a0]{transition:all .2s ease-in}.name-wrap-enter-from[data-v-2c3d75a0]{transform:scale(.9);width:100%;opacity:0}.name-wrap-leave-to[data-v-2c3d75a0]{transform:scale(.9);width:50%;opacity:0}.btn-wrap-enter-active[data-v-2c3d75a0]{transition:all .2s ease-out}.btn-wrap-leave-active[data-v-2c3d75a0]{transition:all .2s ease-in}.btn-wrap-enter-from[data-v-2c3d75a0],.btn-wrap-leave-to[data-v-2c3d75a0]{transform:translate(5px);opacity:0} ');
  23.  
  24. (function (vue) {
  25. 'use strict';
  26.  
  27. var _GM_deleteValue = /* @__PURE__ */ (() => typeof GM_deleteValue != "undefined" ? GM_deleteValue : void 0)();
  28. var _GM_getValue = /* @__PURE__ */ (() => typeof GM_getValue != "undefined" ? GM_getValue : void 0)();
  29. var _GM_listValues = /* @__PURE__ */ (() => typeof GM_listValues != "undefined" ? GM_listValues : void 0)();
  30. var _GM_registerMenuCommand = /* @__PURE__ */ (() => typeof GM_registerMenuCommand != "undefined" ? GM_registerMenuCommand : void 0)();
  31. var _GM_setValue = /* @__PURE__ */ (() => typeof GM_setValue != "undefined" ? GM_setValue : void 0)();
  32. var _unsafeWindow = /* @__PURE__ */ (() => typeof unsafeWindow != "undefined" ? unsafeWindow : void 0)();
  33. const GM_setObject = function(name, value) {
  34. _GM_setValue(name, JSON.stringify(value));
  35. };
  36. let mkApi = {};
  37. const keyList = [
  38. {
  39. key: "DEVTOOL_VISIBLE",
  40. default: false,
  41. name: "开发工具可见性"
  42. /* DEVTOOL_VISIBLE */
  43. },
  44. {
  45. key: "BOX_TOP",
  46. default: 20,
  47. name: "弹框距离顶部距离"
  48. /* BOX_TOP */
  49. },
  50. {
  51. key: "BOX_LEFT",
  52. default: 50,
  53. name: "弹框距离左侧距离"
  54. /* BOX_LEFT */
  55. },
  56. {
  57. key: "ERROR_COUNT",
  58. default: 0,
  59. name: "项目报错次数"
  60. /* ERROR_COUNT */
  61. }
  62. ];
  63. keyList.forEach((item) => {
  64. mkApi[item.key] = {};
  65. mkApi[item.key].get = function() {
  66. let value = _GM_getValue(item.key, void 0);
  67. try {
  68. if (value == void 0)
  69. return item.default;
  70. return JSON.parse(value);
  71. } catch (e) {
  72. return item.default;
  73. }
  74. };
  75. mkApi[item.key].set = function(value) {
  76. _GM_setValue(item.key, JSON.stringify(value));
  77. };
  78. });
  79. mkApi.registerMenuCommand = function() {
  80. let dev = mkApi.DEVTOOL_VISIBLE.get();
  81. let tip = dev ? "Show in localhost" : "Display on all pages";
  82. _GM_registerMenuCommand(tip, function() {
  83. mkApi.DEVTOOL_VISIBLE.set(!dev);
  84. _unsafeWindow.location.reload();
  85. });
  86. _GM_registerMenuCommand("Reset script", function() {
  87. const list = _GM_listValues();
  88. if (list.length > 0)
  89. list.forEach((res) => _GM_deleteValue(res));
  90. _unsafeWindow.location.reload();
  91. });
  92. };
  93. const _imports_0 = "data:image/svg+xml;base64,PHN2ZyB0PSIxNjY5Mjc4MzIzMDU2IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMzAgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjEzODkzIiB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCI+PHBhdGggZD0iTTk5Ni43MTA0IDQ0MS45Nzg4OCA2MDkuNDMzNiAzOC44MDk2QzU4NS4zNjQ0OCAxMy43Nzc5MiA1NTMuMjAwNjQgMCA1MTguNzIyNTYgMFM0NTIuMDgwNjQgMTMuNzc3OTIgNDI4LjAxNjY0IDM4LjgwOTZMNDAuNzM5ODQgNDQxLjk3ODg4Yy0zOS45NjE2IDQxLjYxNTM2LTM0L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4wNDggNTE5LjE2OCAzNjEuMzQ0IDUxOS4xNjhjMi4wNDgtMTM2LjE5MiAyLjA0OC0zMDkuMzEyIDI0MC43MDQtNDQ3LjU1MiA2LjE0NC00LjA5NiAzLjA3Mi0xMy4zMTItNC4wOTYtMTIuMjg4QzE0MS4xMiAxMjkuOTg0IDEwNC4yNTYgNDM3LjI0OCAxMDMuMjMyIDUxOC4xNDRMMjcuNDU2IDUxOC4xNDRjLTIyLjUyOCAwLTM1Ljg0IDI2LjYyNC0yMS41MDQgNDQuMDMybDE4NS4zNDQgMjMzLjUzNmMyMC40OCAyNS42IDU4LjM2OCAyNS42IDc4Ljg0OCAwbDE4NS40MDgtMjMzLjUzNkM0NjguODY0IDU0NS43OTIgNDU2LjU3NiA1MTkuMTY4IDQzNC4wNDggNTE5LjE2OEw0MzQuMDQ4IDUxOS4xNjh6TTQzNC4wNDggNTE5LjE2OCIgcC1pZD0iMjM1MjMiIGZpbGw9IiNDN0NCQ0YiPjwvcGF0aD48L3N2Zz4=";
  96. const _sfc_main$2 = /* @__PURE__ */ vue.defineComponent({
  97. __name: "index",
  98. props: ["top", "left", "width", "bottom", "upperPart", "name"],
  99. emits: ["destroy"],
  100. setup(__props, { emit }) {
  101. const props = __props;
  102. const boxWrap = vue.ref();
  103. const styles = vue.computed(
  104. () => {
  105. return {
  106. left: props.left,
  107. width: props.width,
  108. bottom: props.upperPart ? "" : props.bottom,
  109. top: props.upperPart ? props.top : ""
  110. };
  111. }
  112. );
  113. const customClass = vue.computed(() => {
  114. return props.upperPart ? "upPart" : "belowPart";
  115. });
  116. let visible = vue.ref(false);
  117. function beforeUnload() {
  118. if (props.name === "router") {
  119. emit("destroy");
  120. }
  121. }
  122. vue.onMounted(() => {
  123. visible.value = true;
  124. boxWrap.value.addEventListener("click", (e) => {
  125. e.stopPropagation();
  126. });
  127. });
  128. return (_ctx, _cache) => {
  129. return vue.openBlock(), vue.createElementBlock("div", {
  130. onAfterLeave: beforeUnload,
  131. onMouseleave: beforeUnload
  132. }, [
  133. vue.withDirectives(vue.createElementVNode("div", {
  134. class: vue.normalizeClass(["monkey-box-wrap", customClass.value]),
  135. style: vue.normalizeStyle(styles.value),
  136. ref_key: "boxWrap",
  137. ref: boxWrap
  138. }, [
  139. vue.renderSlot(_ctx.$slots, "default", {}, void 0, true)
  140. ], 6), [
  141. [vue.vShow, vue.unref(visible)]
  142. ])
  143. ], 32);
  144. };
  145. }
  146. });
  147. const _export_sfc = (sfc, props) => {
  148. const target = sfc.__vccOpts || sfc;
  149. for (const [key, val] of props) {
  150. target[key] = val;
  151. }
  152. return target;
  153. };
  154. const boxWrapComponent = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-a5e7cb6f"]]);
  155. let vm;
  156. const bodyHight = document.documentElement.clientHeight;
  157. const container = document.createElement("div");
  158. const createBoxWarp = (dragBox, component) => {
  159. if (!component) {
  160. return vue.render(null, container);
  161. }
  162. const centerLinePosition = dragBox.offsetTop + dragBox.clientHeight / 2;
  163. const upperPart = bodyHight / 2 - centerLinePosition > 0 ? true : false;
  164. const left = dragBox.offsetLeft + "px";
  165. const width = dragBox.offsetWidth + "px";
  166. const name = component.__name;
  167. if (vm) {
  168. vue.render(null, container);
  169. }
  170. const props = {
  171. upperPart,
  172. top: dragBox.offsetTop + dragBox.offsetHeight + 10 + "px",
  173. bottom: bodyHight - dragBox.offsetTop + 10 + "px",
  174. width,
  175. left,
  176. name,
  177. onDestroy: () => {
  178. vue.render(null, container);
  179. }
  180. };
  181. vm = vue.createVNode(boxWrapComponent, props, () => vue.h(component));
  182. vue.render(vm, container);
  183. document.body.appendChild(container.firstElementChild);
  184. //!表示一定有
  185. };
  186. function compare(eleName, reverse = true) {
  187. return function(value1, value2) {
  188. let v1 = value1[eleName];
  189. let v2 = value2[eleName];
  190. return reverse === true ? v2 - v1 : v1 - v2;
  191. };
  192. }
  193. const routerApi = {
  194. appInfo: [
  195. {
  196. name: "vue2",
  197. technical: "vue",
  198. mountDomProName: "__vue__",
  199. getAppInfo: (mountDom) => {
  200. var _a, _b, _c, _d;
  201. const vue2App = mountDom.__vue__;
  202. return {
  203. rawBaseUrl: ((_b = (_a = vue2App.$router) == null ? void 0 : _a.options) == null ? void 0 : _b.base) ?? "",
  204. routerList: (_d = (_c = vue2App == null ? void 0 : vue2App.$router) == null ? void 0 : _c.options) == null ? void 0 : _d.routes
  205. };
  206. }
  207. },
  208. {
  209. name: "vue3",
  210. technical: "vue",
  211. mountDomProName: "__vue_app__",
  212. getAppInfo: (mountDom) => {
  213. var _a, _b, _c, _d, _e, _f, _g, _h, _i;
  214. const vue3App = mountDom.__vue_app__;
  215. return {
  216. rawBaseUrl: ((_e = (_d = (_c = (_b = (_a = vue3App == null ? void 0 : vue3App.config) == null ? void 0 : _a.globalProperties) == null ? void 0 : _b.$router) == null ? void 0 : _c.options) == null ? void 0 : _d.history) == null ? void 0 : _e.base) ?? "",
  217. routerList: ((_i = (_h = (_g = (_f = vue3App == null ? void 0 : vue3App.config) == null ? void 0 : _f.globalProperties) == null ? void 0 : _g.$router) == null ? void 0 : _h.options) == null ? void 0 : _i.routes) || []
  218. };
  219. }
  220. }
  221. ],
  222. // 获取dom上的路由信息
  223. getRouterDomInfo() {
  224. let routerInfo = { baseUrl: "", routerList: [] };
  225. const mountDom = document.body.querySelector("div");
  226. if (!mountDom)
  227. return routerInfo;
  228. let appItem = this.appInfo.find((res) => {
  229. return mountDom.hasOwnProperty(res.mountDomProName);
  230. });
  231. if (!appItem)
  232. return routerInfo;
  233. let { rawBaseUrl, routerList } = appItem.getAppInfo(mountDom);
  234. let baseUrl = rawBaseUrl == null ? void 0 : rawBaseUrl.replaceAll("//", "/");
  235. if (rawBaseUrl == null ? void 0 : rawBaseUrl.startsWith("/"))
  236. baseUrl = baseUrl.substring(1);
  237. if (rawBaseUrl == null ? void 0 : rawBaseUrl.endsWith("/"))
  238. baseUrl = baseUrl.substring(0, baseUrl.length - 1);
  239. routerInfo.baseUrl = baseUrl;
  240. if ((routerList == null ? void 0 : routerList.length) > 0) {
  241. routerInfo.routerList = routerList.filter((res) => !res.path.includes(":"));
  242. }
  243. return routerInfo;
  244. },
  245. // 获取包装好的路由信息
  246. getRouterArrayInfo() {
  247. const { baseUrl, routerList } = this.getRouterDomInfo();
  248. const routerArray = (routerList == null ? void 0 : routerList.map((res) => {
  249. var _a, _b;
  250. const path = res.path ? res.path.replaceAll("//", "/") : "";
  251. const pathName = `/${baseUrl}${path}`.replaceAll("//", "/");
  252. let url = `${location.protocol}//${location.host}${pathName}`;
  253. return {
  254. path: path || "/",
  255. name: pathName === "/" ? "web-homepage" : res.title ?? ((_a = res == null ? void 0 : res.meta) == null ? void 0 : _a.title) ?? ((_b = res == null ? void 0 : res.meta) == null ? void 0 : _b.name) ?? (res == null ? void 0 : res.name) ?? path,
  256. fulUrl: url,
  257. pathName,
  258. select: pathName === location.pathname,
  259. port: (location == null ? void 0 : location.port) || "80"
  260. };
  261. })) || [];
  262. return routerArray.sort(compare("select"));
  263. },
  264. // 获取当前激活的路由名称
  265. getActiveName() {
  266. const routerList = this.getRouterArrayInfo();
  267. let routerItem = routerList.find((res) => res.select);
  268. return routerItem ? routerItem.name ? routerItem.name : "---/---" : "---/---";
  269. }
  270. };
  271. const _withScopeId$1 = (n) => (vue.pushScopeId("data-v-8fdc01fd"), n = n(), vue.popScopeId(), n);
  272. const _hoisted_1$1 = { class: "router-wrap" };
  273. const _hoisted_2$1 = { class: "left" };
  274. const _hoisted_3$1 = /* @__PURE__ */ _withScopeId$1(() => /* @__PURE__ */ vue.createElementVNode("svg", {
  275. t: "1669605726745",
  276. class: "icon",
  277. viewBox: "0 0 1024 1024",
  278. version: "1.1",
  279. xmlns: "http://www.w3.org/2000/svg",
  280. "p-id": "3188",
  281. width: "18",
  282. height: "18"
  283. }, [
  284. /* @__PURE__ */ vue.createElementVNode("path", {
  285. d: "M512 504L764.8 68.8h-134.4L512 275.2 393.6 70.4h-134.4L512 504zM819.2 70.4L512 600 204.8 68.8H0l512 886.4L1024 70.4H819.2z",
  286. fill: "#C7CBCF",
  287. "p-id": "3189"
  288. })
  289. ], -1));
  290. const _hoisted_4$1 = [
  291. _hoisted_3$1
  292. ];
  293. const _hoisted_5$1 = { class: "left" };
  294. const _hoisted_6$1 = /* @__PURE__ */ _withScopeId$1(() => /* @__PURE__ */ vue.createElementVNode("svg", {
  295. xmlns: "http://www.w3.org/2000/svg",
  296. "xmlns:xlink": "http://www.w3.org/1999/xlink",
  297. "aria-hidden": "true",
  298. role: "img",
  299. class: "iconify iconify--logos",
  300. width: "37.07",
  301. height: "36",
  302. preserveAspectRatio: "xMidYMid meet",
  303. viewBox: "0 0 256 198"
  304. }, [
  305. /* @__PURE__ */ vue.createElementVNode("path", {
  306. fill: "#41B883",
  307. d: "M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"
  308. }),
  309. /* @__PURE__ */ vue.createElementVNode("path", {
  310. fill: "#41B883",
  311. d: "m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"
  312. }),
  313. /* @__PURE__ */ vue.createElementVNode("path", {
  314. fill: "#35495E",
  315. d: "M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"
  316. })
  317. ], -1));
  318. const _hoisted_7$1 = [
  319. _hoisted_6$1
  320. ];
  321. const _hoisted_8$1 = ["onClick"];
  322. const _hoisted_9 = { class: "path-wrap" };
  323. const _hoisted_10 = { class: "name-wrap" };
  324. const _hoisted_11 = { class: "no-data" };
  325. const _sfc_main$1 = /* @__PURE__ */ vue.defineComponent({
  326. __name: "router",
  327. setup(__props) {
  328. const vTitle = {
  329. mounted(el) {
  330. el.onmouseenter = (e) => {
  331. const { clientWidth, scrollWidth, title } = el;
  332. if (!title && scrollWidth > clientWidth)
  333. el.title = el.innerText;
  334. };
  335. }
  336. };
  337. const routerArray = routerApi.getRouterArrayInfo();
  338. const jump = (urlInfo) => {
  339. location.href = urlInfo.fulUrl;
  340. };
  341. function getName(url) {
  342. if (!url || url === "/")
  343. return "/";
  344. if (url.startsWith("/")) {
  345. return url.substring(1);
  346. } else {
  347. return url;
  348. }
  349. }
  350. return (_ctx, _cache) => {
  351. return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$1, [
  352. (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(vue.unref(routerArray), (item, index) => {
  353. return vue.openBlock(), vue.createElementBlock("div", {
  354. class: "router-item",
  355. key: index
  356. }, [
  357. vue.withDirectives(vue.createElementVNode("div", _hoisted_2$1, _hoisted_4$1, 512), [
  358. [vue.vShow, !item.select]
  359. ]),
  360. vue.withDirectives(vue.createElementVNode("div", _hoisted_5$1, _hoisted_7$1, 512), [
  361. [vue.vShow, item.select]
  362. ]),
  363. vue.createElementVNode("div", {
  364. class: "right",
  365. onClick: ($event) => jump(item)
  366. }, [
  367. vue.withDirectives((vue.openBlock(), vue.createElementBlock("div", _hoisted_9, [
  368. vue.createTextVNode(vue.toDisplayString(getName(item.path)), 1)
  369. ])), [
  370. [vTitle]
  371. ]),
  372. vue.withDirectives((vue.openBlock(), vue.createElementBlock("div", _hoisted_10, [
  373. vue.createTextVNode(vue.toDisplayString(getName(item.name)), 1)
  374. ])), [
  375. [vTitle]
  376. ])
  377. ], 8, _hoisted_8$1)
  378. ]);
  379. }), 128)),
  380. vue.withDirectives(vue.createElementVNode("div", _hoisted_11, "No data", 512), [
  381. [vue.vShow, vue.unref(routerArray).length === 0]
  382. ])
  383. ]);
  384. };
  385. }
  386. });
  387. const routerComponent = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-8fdc01fd"]]);
  388. let realWidth = vue.ref();
  389. const position = vue.computed(() => {
  390. var _a;
  391. const bodyWidth = ((_a = document == null ? void 0 : document.body) == null ? void 0 : _a.clientWidth) ?? 0;
  392. const bodyHight2 = document.documentElement.clientHeight;
  393. let boxTop = mkApi.BOX_TOP.get();
  394. let boxLeft = mkApi.BOX_LEFT.get();
  395. if (realWidth.value && realWidth.value + boxLeft - bodyWidth > 0) {
  396. return {
  397. boxTop: boxTop + "px",
  398. boxLeft: bodyWidth - realWidth.value + "px"
  399. };
  400. }
  401. if (boxTop < 0 || boxTop > bodyWidth || boxTop > bodyHight2 || boxTop < 0) {
  402. return {
  403. boxTop: "20px",
  404. boxLeft: "20px"
  405. };
  406. }
  407. return {
  408. boxTop: boxTop + "px",
  409. boxLeft: boxLeft + "px"
  410. };
  411. });
  412. const _withScopeId = (n) => (vue.pushScopeId("data-v-2c3d75a0"), n = n(), vue.popScopeId(), n);
  413. const _hoisted_1 = { class: "monkey-home-wrap" };
  414. const _hoisted_2 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ vue.createElementVNode("img", { src: _imports_0 }, null, -1));
  415. const _hoisted_3 = [
  416. _hoisted_2
  417. ];
  418. const _hoisted_4 = { class: "monkey-name" };
  419. const _hoisted_5 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ vue.createElementVNode("span", { class: "monkey-arrow" }, [
  420. /* @__PURE__ */ vue.createElementVNode("img", { src: _imports_1 })
  421. ], -1));
  422. const _hoisted_6 = {
  423. key: 0,
  424. class: "monkey-menu-wrap"
  425. };
  426. const _hoisted_7 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ vue.createElementVNode("img", { src: _imports_2 }, null, -1));
  427. const _hoisted_8 = [
  428. _hoisted_7
  429. ];
  430. const _sfc_main = /* @__PURE__ */ vue.defineComponent({
  431. __name: "App",
  432. setup(__props) {
  433. const routerName = vue.ref("---/---");
  434. const box = vue.ref();
  435. vue.onMounted(() => {
  436. realWidth.value = box.value.clientWidth;
  437. routerName.value = routerApi.getActiveName();
  438. });
  439. document.addEventListener("click", () => {
  440. createBoxWarp(box.value, null);
  441. });
  442. const clearStorage = () => {
  443. localStorage.clear();
  444. sessionStorage.clear();
  445. let keys = document.cookie.match(/[^ =;]+(?=\=)/g);
  446. if (keys) {
  447. for (var i = keys.length; i--; ) {
  448. document.cookie = keys[i] + "=0;path=/;expires=" + (/* @__PURE__ */ new Date(0)).toUTCString();
  449. document.cookie = keys[i] + "=0;path=/;domain=" + document.domain + ";expires=" + (/* @__PURE__ */ new Date(0)).toUTCString();
  450. }
  451. }
  452. location.href = location.href;
  453. };
  454. const nameWrapVisible = vue.ref(false);
  455. const mouseenterMoveBtn = () => {
  456. createBoxWarp(box.value, null);
  457. nameWrapVisible.value = true;
  458. };
  459. return (_ctx, _cache) => {
  460. const _directive_drag = vue.resolveDirective("drag");
  461. return vue.withDirectives((vue.openBlock(), vue.createElementBlock("div", {
  462. class: "monkey-wrap",
  463. ref_key: "box",
  464. ref: box,
  465. style: vue.normalizeStyle({ top: vue.unref(position).boxTop, left: vue.unref(position).boxLeft }),
  466. onMouseleave: _cache[2] || (_cache[2] = ($event) => nameWrapVisible.value = false)
  467. }, [
  468. vue.createElementVNode("div", _hoisted_1, [
  469. vue.createElementVNode("span", {
  470. class: "icon v-drag-handle",
  471. onMouseenter: _cache[0] || (_cache[0] = ($event) => mouseenterMoveBtn())
  472. }, _hoisted_3, 32),
  473. vue.createVNode(vue.Transition, { name: "name-wrap" }, {
  474. default: vue.withCtx(() => [
  475. nameWrapVisible.value ? (vue.openBlock(), vue.createElementBlock("div", {
  476. key: 0,
  477. class: "monkey-name-wrap",
  478. onMouseenter: _cache[1] || (_cache[1] = ($event) => vue.unref(createBoxWarp)(box.value, routerComponent))
  479. }, [
  480. vue.createElementVNode("span", _hoisted_4, vue.toDisplayString(routerName.value), 1),
  481. _hoisted_5
  482. ], 32)) : vue.createCommentVNode("", true)
  483. ]),
  484. _: 1
  485. })
  486. ]),
  487. vue.createVNode(vue.Transition, { name: "btn-wrap" }, {
  488. default: vue.withCtx(() => [
  489. nameWrapVisible.value ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_6, [
  490. vue.createElementVNode("span", {
  491. class: "icon",
  492. onClick: clearStorage
  493. }, _hoisted_8)
  494. ])) : vue.createCommentVNode("", true)
  495. ]),
  496. _: 1
  497. })
  498. ], 36)), [
  499. [_directive_drag]
  500. ]);
  501. };
  502. }
  503. });
  504. const App = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-2c3d75a0"]]);
  505. const monkeyTool = {
  506. // 是否注入脚本
  507. inject() {
  508. let devToolVisible = mkApi.DEVTOOL_VISIBLE.get();
  509. const localhostUrl = location.href.includes("localhost");
  510. return devToolVisible || localhostUrl;
  511. },
  512. // 如果无路由信息或项目报错,不显示脚本
  513. isPageHaveError() {
  514. let error = document.body.querySelector("#webpack-dev-server-client-overlay");
  515. if (error)
  516. return true;
  517. let count = mkApi.ERROR_COUNT.get();
  518. if (count > 1) {
  519. mkApi.ERROR_COUNT.set(0);
  520. return true;
  521. }
  522. mkApi.ERROR_COUNT.set(count + 1);
  523. setTimeout(() => {
  524. mkApi.ERROR_COUNT.set(0);
  525. }, 1e3);
  526. },
  527. registerMenuCommand() {
  528. mkApi.registerMenuCommand();
  529. }
  530. };
  531. const directive$1 = {
  532. beforeMount(el) {
  533. const dragBox = el;
  534. const dragArea = el.getElementsByClassName("v-drag-handle").length > 0 ? el.getElementsByClassName("v-drag-handle")[0] : el;
  535. const bodyWidth = document.body.clientWidth;
  536. const bodyHight2 = document.documentElement.clientHeight;
  537. dragArea.onmousedown = (e) => {
  538. let domLeft = dragBox.offsetLeft;
  539. let domTop = dragBox.offsetTop;
  540. e.preventDefault();
  541. e.stopPropagation();
  542. let mouseX = e.clientX - domLeft;
  543. let mouseY = e.clientY - domTop;
  544. const domWidth = dragBox.offsetWidth;
  545. const domHeight = dragBox.offsetHeight;
  546. document.onmousemove = (e2) => {
  547. let domCenterLeft = e2.clientX - mouseX;
  548. let domCenterTop = e2.clientY - mouseY;
  549. dragBox.style.left = domCenterLeft + "px";
  550. dragBox.style.top = domCenterTop + "px";
  551. domLeft = dragBox.offsetLeft;
  552. domTop = dragBox.offsetTop;
  553. let domRight = bodyWidth - domLeft - domWidth;
  554. let domBottom = bodyHight2 - domHeight - domTop;
  555. if (domRight <= 0) {
  556. dragBox.style.left = bodyWidth - domWidth + "px";
  557. }
  558. if (domBottom < 0) {
  559. dragBox.style.top = bodyHight2 - domHeight + "px";
  560. }
  561. if (domLeft < 0) {
  562. dragBox.style.left = 0;
  563. }
  564. if (domTop < 0) {
  565. dragBox.style.top = 0;
  566. }
  567. };
  568. document.onmouseup = (e2) => {
  569. e2.preventDefault();
  570. document.onmousemove = null;
  571. document.onmouseup = null;
  572. GM_setObject("BOX_LEFT", dragBox.offsetLeft);
  573. GM_setObject("BOX_TOP", dragBox.offsetTop);
  574. };
  575. };
  576. }
  577. };
  578. const drag = {
  579. install: function(app) {
  580. app.directive("drag", directive$1);
  581. }
  582. };
  583. const directive = {
  584. install: function(app) {
  585. app.use(drag);
  586. }
  587. };
  588. monkeyTool.registerMenuCommand();
  589. const injectTool = monkeyTool.inject();
  590. if (injectTool) {
  591. _unsafeWindow.addEventListener("load", () => {
  592. const pageError = monkeyTool.isPageHaveError();
  593. if (pageError)
  594. return console.error("[vite-plugin-monkey]Please resolve the error on the current page and continue to use this plug-in");
  595. vue.createApp(App).use(directive).mount(
  596. (() => {
  597. const el = document.createElement("div");
  598. document.body.append(el);
  599. return el;
  600. })()
  601. );
  602. });
  603. }
  604.  
  605. })(Vue);