爱蒙编辑器(vue,一键打开)

2021/11/18 下午3:32:59

  1. // ==UserScript==
  2. // @name 爱蒙编辑器(vue,一键打开)
  3. // @namespace Violentmonkey Scripts
  4. // @include http://localhost*
  5. // @include http://127.0.0.1*
  6. // @include http://0.0.0.0*
  7. // @include http://192.168.*
  8. // @include http://10.0.*
  9. // @include http://10.114.6.*
  10. // @exclude http://10.0.0.1/cgi-bin/*
  11. // @include http://172.16.*
  12. // @grant none
  13. // @version 0.6.9
  14. // @author -
  15. // @require https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js
  16. // @require https://cdn.jsdelivr.net/npm/jquery.hotkeys@0.1.0/jquery.hotkeys.min.js
  17. // @description 2021/11/18 下午3:32:59
  18. // ==/UserScript==
  19. document.addEventListener('click', event => {
  20. if (event.ctrlKey) {
  21. event.preventDefault();
  22. event.stopPropagation();
  23. const c = element => {
  24. if (!element) return false
  25. if (element?.__vnode?.props.__v_inspector) {
  26. return element?.__vnode?.props.__v_inspector;
  27. } else if (element.getAttribute('data-v-inspector')) {
  28. return element.getAttribute('data-v-inspector')
  29. } else {
  30. return c(element.parentNode);
  31. }
  32. };
  33. if (window.useNuxtApp) {
  34. const app = useNuxtApp();
  35. const rootDir = app.vueApp._component.__file.replace(/node_modules.*/, '');
  36. const src = c(event.srcElement);
  37. if (rootDir && src) {
  38. fetch(`/__open-in-editor?file=${rootDir + src}`).then(() => {
  39. highlight(event.srcElement);
  40. });
  41. }
  42. return false
  43. }
  44. if (window.__vite_plugin_ssr) {
  45. const rootDir =
  46. __VUE_DEVTOOLS_GLOBAL_HOOK__.apps[2].app._instance.subTree.type.__file.replace(
  47. /renderer\/.*/,
  48. '',
  49. );
  50. const src = c(event.srcElement);
  51. if (rootDir && src) {
  52. fetch(`/__open-in-editor?file=${rootDir + src}`.replace('src/src','src')).then(() => {
  53. highlight(event.srcElement);
  54. });
  55. }
  56. return false
  57. }
  58. if(window.__VUE_INSPECTOR__){
  59. const rootDir = __VUE_INSPECTOR__._.type.__file.replace(/node_modules.*/, '')
  60. const src = c(event.srcElement);
  61. if (rootDir && src) {
  62. fetch(`/__open-in-editor?file=${rootDir + src}`).then(() => {
  63. highlight(event.srcElement);
  64. });
  65. }
  66. return false
  67. }
  68. }
  69. });
  70.  
  71. document.addEventListener('keyup', event => {
  72. if (event.keyCode === 190 && event.target.tagName !== 'INPUT' && event.target.tagName !== 'TEXTAREA') {
  73. if (window.useNuxtApp) {
  74. const app = useNuxtApp();
  75. if (event.ctrlKey) {
  76. console.log(1);
  77. console.log(event.target);
  78. } else {
  79. fetch(
  80. `/__open-in-editor?file=${app._route.matched[app._route.matched.length - 1].components.default.__file
  81. }`,
  82. );
  83. }
  84.  
  85. return false;
  86. }
  87. if (window.__vite_plugin_ssr) {
  88. const baseSrc =
  89. __VUE_DEVTOOLS_GLOBAL_HOOK__.apps[2].app._instance.subTree.type.__file.replace(
  90. /renderer\/.*/,
  91. '',
  92. );
  93. let pathname = location.pathname + '/index';
  94. const list = __vite_plugin_ssr['setPageFiles.ts'].pageFilesAll;
  95. let fileUrl = '';
  96. console.log(list)
  97. console.log(pathname)
  98. if (pathname === '//index') {
  99. file = list.find(item => item.pageId === '/src/pages/index/index');
  100. fileUrl = file.filePath;
  101. } else {
  102. file = list.find(item => item.pageId.includes(pathname));
  103. fileUrl = file.filePath;
  104. }
  105. console.log(fileUrl);
  106. fetch(`/__open-in-editor?file=${baseSrc + fileUrl}`);
  107. return false;
  108. }
  109. if(typeof __VUE_DEVTOOLS_ROUTER__ !== 'undefined'){
  110. const matched = __VUE_DEVTOOLS_ROUTER__.currentRoute._value.matched
  111. const vue3Url = matched[matched.length - 1].components.default.__file
  112. if(vue3Url){
  113. console.log(vue3Url)
  114. fetch(`/__open-in-editor?file=${vue3Url}`)
  115. return
  116. }
  117.  
  118. }
  119. if (typeof app !== 'undefined') {
  120. const vue3Url = window?.__VUE_DEVTOOLS_GLOBAL_HOOK__.apps.find(item=>!!item.app?.config?.globalProperties.$route)?.app.config.globalProperties.$route.matched.slice(
  121. -1,
  122. )?.[0].components.default.__file;
  123. if (vue3Url) {
  124. console.log(vue3Url);
  125. fetch(`/__open-in-editor?file=${vue3Url}`);
  126. } else if (window.uni) {
  127. let app = window?.__VUE_DEVTOOLS_GLOBAL_HOOK__.apps?.[0];
  128. if(app.app){
  129. app = app.app
  130. }
  131. const baseSrc = app._component.__file.replace('/App.vue', '');
  132. const fileUrl = baseSrc + app.router.currentRoute.value.fullPath + '.vue';
  133. fetch(`/__open-in-editor?file=${fileUrl}`);
  134. } else if (app) {
  135. const vm = app.__vue__;
  136. const fileUrl = vm.$route.matched[vm.$route.matched.length - 1].components.default.__file;
  137. fetch(`/__open-in-editor?file=${fileUrl}`);
  138. }
  139. } else if (typeof getApp === 'function' && localStorage.getItem('custom-file-base-url')) {
  140. const url = localStorage.getItem('custom-file-base-url') + getApp()._route.fullPath + '.vue';
  141. console.log(url);
  142. fetch(`/__open-in-editor?file=${url}`);
  143. }
  144. }
  145. });
  146.  
  147. function highlight(clickedElement) {
  148. const rect = clickedElement.getBoundingClientRect();
  149. const frame = document.createElement('div');
  150. frame.style.position = 'absolute';
  151. frame.style.top = rect.top + window.scrollY + 'px';
  152. frame.style.left = rect.left + window.scrollX + 'px';
  153. frame.style.width = rect.width - 4 + 'px';
  154. frame.style.height = rect.height - 4 + 'px';
  155. frame.style.border = 'solid 2px gold';
  156. frame.style.borderRadius = '5px';
  157. frame.style.zIndex = '99999';
  158. frame.style.pointerEvents = 'none';
  159. document.body.appendChild(frame);
  160.  
  161. $(frame).fadeIn(300, 'swing').delay(500).fadeOut(500, 'swing');
  162. }

QingJ © 2025

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