lcap_tools

提供一些网页小工具,低代码开发专用

目前为 2024-06-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name lcap_tools
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.6
  5. // @description 提供一些网页小工具,低代码开发专用
  6. // @author 袁龙辉
  7. // @match https://lcap.test.zte.com.cn/*
  8. // @match https://lcap.dev.zte.com.cn/*
  9. // @match https://lcap.uat.zte.com.cn/*
  10. // @match https://lcapst.test.zte.com.cn/*
  11. // @match https://lcappro.uat.zte.com.cn/*
  12. // @match https://lcappro.test.zte.com.cn/*
  13. // @match https://lcappro.dev.zte.com.cn/*
  14. // @match https://uactest.zte.com.cn/*
  15. // @match https://test55.ucs.zte.com.cn/*
  16. // @match http://local.zte.com.cn/*
  17. // @match https://local.zte.com.cn/*
  18. // @match http://127.0.0.1/*
  19. // @match https://lcap.opendn.com.cn/*
  20. // @match https://opendn.com.cn/*
  21. // @match https://dn.zte.com.cn/*
  22. // @match https://sdp.test.zte.com.cn/*
  23. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAbCAYAAACJISRoAAAABHNCSVQICAgIfAhkiAAAAQtJREFUSInt1c1Kw0AUhuFTF8kFTJnAFFwKYrHQUjE0Fq2iOxG8Bn/vQ8SbEMX+oLhQ9+raXom9g0lI8roQBDdmFi0q5FsOfOdZDIdTAZAZZ27WQImUyC8ju3v7Ug1q0tva+fZ+dn4h1aAmYacreZ7/PISCPL+8orRBacPbeAyAtZaFxTpKG27v7otGUIgAbGxuo7Th4OgEgMFwhNKGVjskTdPpIA+PTyhtCMw875MJ671PtD8YudTdkCzLWFmNUNpweHyK0oZGs02SJNNDAG76w6+/UdpweXXtWnVH4jim3mihtGFpuYm11hlx3hPP86S7FomISNQJxfd91+ofWcZ/g1SgPL8lUiIF+QCIeCJE+P0wYgAAAABJRU5ErkJggg==
  24. // @grant GM_cookie
  25. // @grant GM_addStyle
  26. // @grant GM_setValue
  27. // @grant GM_getValue
  28. // @grant GM_deleteValue
  29. // @grant GM_listValues
  30. // ==/UserScript==
  31.  
  32. (function () {
  33. 'use strict';
  34. GM_addStyle(
  35. `.y-panel {
  36. width: 150px;
  37. display: flex;
  38. flex-direction: column;
  39. position: fixed;
  40. top: 32px;
  41. right: -150px;
  42. background-color: #a1d4e2;
  43. border-radius: 3px;
  44. transition: all 0.3s;
  45. opacity: 1;
  46. z-index: 9999999999;
  47. }
  48. .y-panel:before {
  49. width: 24px;
  50. height: 48px;
  51. position: absolute;
  52. top: calc(50% - 24px);
  53. left: -24px;
  54. background-color: #a1d4e2;
  55. border-radius: 48px 0px 0px 48px;
  56. border-top: 1px solid #5ac6aa;
  57. border-left: 1px solid #5ac6aa;
  58. border-bottom: 1px solid #5ac6aa;
  59. content: \"\";
  60. opacity: 0.8;
  61. cursor: pointer;
  62. z-index: 9999999999;
  63. }
  64. .y-panel:hover {
  65. right: 0;
  66. }
  67. .y-panel > .y-panel-btn {
  68. position: relative;
  69. border: 1px solid #fff;
  70. border-radius: 3px;
  71. color: #283654 !important;
  72. cursor: pointer;
  73. line-height: normal !important;
  74. font-size: 13px !important;
  75. font-weight: bold;
  76. font-family: SimSun, STSong, 宋体, "Microsoft YaHei", Arial, sans-serif;
  77. margin: 4px 5px;
  78. padding: 2px 4px;
  79. text-align: center;
  80. user-select: none;
  81. background-color: #f0f0f0;
  82. z-index: 9999999999;
  83. }
  84. .y-panel-input {
  85. height: 24px;
  86. margin: 5px 4px;
  87. border-radius: 3px;
  88. }
  89. ::-webkit-input-placeholder {
  90. color: rgba(0, 0, 0, 0.5);
  91. font-size: 14px;
  92. }
  93. .y-panel-btn_delete {
  94. padding: 0px 3px;
  95. color: #000;
  96. position: absolute;
  97. right: 3px;
  98. top: 0px;
  99. background-color: #88befc;
  100. }
  101. .y-panel-btn_delete:hover {
  102. color: #fff;
  103. background-color: red;
  104. }`
  105. );
  106.  
  107. // 可以在这里配置常用工号,例如:
  108. const name_map = ['10331290', '00268638', '10286708']
  109. //const name_map = []
  110. // 本地存储的工号
  111. const stored_name_map = GM_listValues().map(item => GM_getValue(item))
  112.  
  113. function register(btns) {
  114. const yPanel = document.querySelector('.y-panel')
  115. if (yPanel) {
  116. yPanel.parentNode.removeChild(yPanel)
  117. }
  118. const container = document.createElement("div");
  119. container.className = "y-panel";
  120. document.body.appendChild(container);
  121.  
  122. btns.forEach(btn => {
  123. const button = document.createElement("button");
  124. button.textContent = btn.text;
  125. button.className = "y-panel-btn";
  126. button.onclick = btn.onclick;
  127. container.appendChild(button);
  128. if (btn.isStored) {
  129. const delete_btn = document.createElement("button");
  130. delete_btn.textContent = 'x';
  131. delete_btn.className = 'y-panel-btn_delete';
  132. delete_btn.onclick = (e) => {
  133. e.stopPropagation()
  134. GM_deleteValue(btn.text)
  135. refreshPanel()
  136. };
  137. button.appendChild(delete_btn);
  138. }
  139. if(btn.password) {
  140. button.title = btn?.password
  141. }
  142. button.style.backgroundColor = btn.type === 'function' && '#5ac6aa'
  143. });
  144.  
  145. // 添加跳转按钮
  146. addJumpBtn(container)
  147.  
  148. // 工号输入
  149. const name_input = document.createElement("input");
  150. name_input.className = 'y-panel-input'
  151. name_input.placeholder = '新增工号, Enter'
  152. container.appendChild(name_input);
  153. name_input.addEventListener('keydown', (event) => {
  154. if (event.key === 'Enter') {
  155. GM_setValue(name_input.value, name_input.value)
  156. login(name_input.value)
  157. refreshPanel()
  158. }
  159. });
  160. };
  161.  
  162. function clearCookies() {
  163. const cookies = document.cookie.split(';').map(cookie => cookie.trim().split('=')[0]);
  164. cookies.forEach(item => {
  165. GM_cookie.delete({ name: item });
  166. })
  167. location.reload();
  168. }
  169.  
  170. function login(name, password = '1') {
  171. const nameInput = document.getElementById('input-loginname')
  172. if (!nameInput) return
  173. const passwordInput = document.getElementById('input-password')
  174. const login_btn = document.getElementsByClassName("el-button login-btn el-button--primary")[0]
  175. var event = new Event('input', {
  176. bubbles: true,
  177. cancelable: true,
  178. });
  179. nameInput.value = name
  180. nameInput.dispatchEvent(event);
  181. passwordInput.value = password
  182. passwordInput.dispatchEvent(event);
  183. login_btn.click()
  184. }
  185.  
  186. function changeLang() {
  187. const currentUrl = new URL(window.location.href)
  188. const params = currentUrl.searchParams
  189. if(params.get('lang')) {
  190. params.set('lang', params.get('lang') === 'zh' ? 'en' : 'zh')
  191. window.history.replaceState({}, '', currentUrl)
  192. }
  193. const cookies = document.cookie.split(';').map(cookie => cookie.trim());
  194. cookies.forEach(cookie => {
  195. const [name, value] = cookie.trim().split('=')
  196. if (name.includes('Language')) {
  197. GM_cookie.delete({ name });
  198. GM.cookie.set({
  199. name,
  200. value: value === 'zh_CN' ? 'en_US' : 'zh_CN'
  201. })
  202. }
  203. })
  204. location.reload();
  205. }
  206.  
  207.  
  208. function getBtnMap(stored_name_map) {
  209. return [
  210. {
  211. text: '清空Cookie并刷新',
  212. type: 'function',
  213. onclick: () => clearCookies()
  214. },
  215. {
  216. text: '切换cookie的语言',
  217. type: 'function',
  218. onclick: () => changeLang()
  219. },
  220. // 可以添加自定义的工号和密码, password属性是为了悬浮显示的
  221. {
  222. text: '自定义工号',
  223. password: '123456@Zte',
  224. onclick: () => login('10331290','123456@Zte')
  225. },
  226. ...name_map.map(name => {
  227. return {
  228. text: name,
  229. password: '1',
  230. onclick: () => login(name)
  231. }
  232. }),
  233. ...stored_name_map.map(name => {
  234. return {
  235. text: name,
  236. isStored: true,
  237. password: '1',
  238. onclick: () => login(name)
  239. }
  240. })
  241. ]
  242. }
  243.  
  244. // 在name新增删除后刷新面板
  245. function refreshPanel() {
  246. const current_stored_name_map = GM_listValues().map(item => GM_getValue(item))
  247. const btn_map = getBtnMap(current_stored_name_map)
  248. register(btn_map)
  249. }
  250.  
  251. function addJumpBtn(container) {
  252. const { hostname, pathname, searchParams, hash } = new URL(window.location.href);
  253. const hashParts = hash.slice(2).split('/')
  254. const hashObject = {
  255. app: hashParts.indexOf('app') !== -1 ? hashParts[hashParts.indexOf('app') + 1] : null,
  256. bizObject: hashParts.indexOf('bizObject') !== -1 ? hashParts[hashParts.indexOf('bizObject') + 1] : null,
  257. page: hashParts.indexOf('page') !== -1 ? hashParts[hashParts.indexOf('page') + 1] : null
  258. }
  259. const layoutUrl = `https://${hostname}/zte-paas-lcap-frontendcli/layout-designer.html?lang=zh`
  260. const entityUrl = `https://${hostname}/zte-paas-lcap-frontendcli/entity-designer.html?lang=zh`
  261. const mainPageUrl = `https://${hostname}/zte-paas-lcap-frontendcli/index.html#/platform/applicationdevelopment`
  262. if (searchParams.get('bizObject') && searchParams.get('bizObject') !== 'null') {
  263. createBtn([
  264. {
  265. text: 'to->当前布局',
  266. title: '适用于表单页,列表页跳转之后需要切换一下布局',
  267. toUrl: `${layoutUrl}${hash}/bizObject/${searchParams.get('bizObject')}`
  268. },
  269. { text: 'to->当前实体', toUrl: `${entityUrl}#/app/${hashObject.app}/bizObject/${searchParams.get('bizObject')}` }
  270. ], container)
  271. }
  272. else if (searchParams.get('bizObject') === 'null') {
  273. createBtn([
  274. { text: 'to->当前页面设计', toUrl: `${layoutUrl}#/app/${hashObject.app}/page/${hashObject.page}` }
  275. ], container)
  276. }
  277. else if (pathname.includes('zte-paas-lcap-frontendcli/layout-designer.html') && hashObject.bizObject) {
  278. createBtn([
  279. { text: 'to->当前实体', toUrl: `${entityUrl}#/app/${hashObject.app}/bizObject/${hashObject.bizObject}` }
  280. ], container)
  281. }
  282. if (hashObject.app) {
  283. createBtn([
  284. { text: 'to->应用主页', toUrl: `${mainPageUrl}/${hashObject.app}` }
  285. ], container)
  286. }
  287. }
  288.  
  289. function createBtn(btns, container) {
  290. btns.forEach(btn => {
  291. const button = document.createElement("button");
  292. button.textContent = btn.text;
  293. button.className = "y-panel-btn";
  294. button.onclick = () => {
  295. window.open(btn.toUrl)
  296. };
  297. if(btn.title) {
  298. button.title = btn.title
  299. }
  300. container.appendChild(button);
  301. })
  302. }
  303.  
  304. (function init() {
  305. const initial_btn_map = getBtnMap(stored_name_map)
  306. register(initial_btn_map)
  307. })()
  308.  
  309. })();