kk-helper

个人开发常用帮助脚本

当前为 2023-09-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name kk-helper
  3. // @namespace https://greasyfork.org
  4. // @homepage https://greasyfork.org
  5. // @version 0.9.3
  6. // @description 个人开发常用帮助脚本
  7. // @author #stephenykk
  8. // @match https://juejin.cn/post/*
  9. // @match https://blog.csdn.net/*/article/details/*
  10. // @match https://www.jianshu.com/p/*
  11. // @match https://segmentfault.com/a/*
  12. // @match https://mp.weixin.qq.com/s*
  13. // @match https://zhuanlan.zhihu.com/p/*
  14. // @match https://sspai.com/post/*
  15. // @match *://www.news.cn/*/**/*.htm*
  16. // @match *://*.people.com.cn/*/**/*.htm*
  17. // @icon https://res.wx.qq.com/a/fed_upload/9300e7ac-cec5-4454-b75c-f92260dd5b47/logo-mp.ico
  18. // @grant none
  19. // @license MIT
  20. // ==/UserScript==
  21.  
  22. (function () {
  23. "use strict";
  24. function log(...args) {
  25. console.log("[KKCopy]", ...args);
  26. }
  27.  
  28. function checkEnable() {
  29. if (/qq\.com/.test(location.host)) {
  30. return false;
  31. }
  32. return true;
  33. }
  34.  
  35. if (!checkEnable()) return;
  36.  
  37. const autoClick = (ele, callback, seconds = 2) => {
  38. console.log('try auto click ele:', ele);
  39. ele.click()
  40. callback && setTimeout(callback, seconds * 1000)
  41. }
  42.  
  43. function autoClickPrereleaseBtn() {
  44. if (
  45. location.href.includes(
  46. "https://devops-cloud.bgy.com.cn/ext/@console-plugin/cd/5e787768cc788/deploy/host-deploy"
  47. )
  48. ) {
  49.  
  50. const autoClickNextBtn2 = () => {
  51. const btn = document.querySelector('.grid-card .steps + .btn')
  52. autoClick(btn, autoCheck2)
  53. }
  54.  
  55. const autoClickNextBtn3 = () => {
  56. const btn = document.querySelector('.grid-card .steps + .btn')
  57. autoClick(btn, autoClickNextBtn4)
  58. }
  59.  
  60. const autoClickNextBtn4 = () => {
  61. const btn = document.querySelector('.grid-card .steps + .btn')
  62. autoClick(btn)
  63. }
  64.  
  65. const autoClickNextBtn = () => {
  66. const btn = document.querySelector('.grid-card .steps + .btn')
  67. autoClick(btn, autoClickNextBtn2)
  68. }
  69.  
  70. const autoCheck1 = () => {
  71. const labelEle = document.querySelector('.cluster-info label')
  72. autoClick(labelEle, autoClickNextBtn, 1)
  73. }
  74.  
  75. const autoCheck2 = () => {
  76. const labelEle = document.querySelector('.package-grid .ui-checkbox')
  77. autoClick(labelEle, autoClickNextBtn3, 1)
  78. }
  79.  
  80. setTimeout(() => {
  81. const btnEle = document.querySelector(".cluster-type-btn-group .btn:nth-of-type(2)");
  82. btnEle && btnEle.textContent.includes('预发布') && autoClick(btnEle, autoCheck1)
  83. }, 3000);
  84. }
  85. }
  86.  
  87. autoClickPrereleaseBtn()
  88.  
  89. function autoClickHostDeploy() {
  90. if (
  91. // location.href.includes(
  92. // "https://devops-cloud.bgy.com.cn/ext/@console-plugin/cd/5e787768cc788/deploy"
  93. // )
  94. location.href === 'https://devops-cloud.bgy.com.cn/ext/@console-plugin/cd/5e787768cc788/deploy'
  95. ) {
  96. setTimeout(() => {
  97. const cardEle = document.querySelector(".manual-card-container .card:first-child");
  98. cardEle && autoClick(cardEle, autoClickPrereleaseBtn, 3)
  99. }, 3000);
  100. }
  101. }
  102.  
  103.  
  104. function createBtn(text, listener, style='') {
  105. // if (this.mybtn) return;
  106. const btn = document.createElement("button");
  107. btn.textContent = text || "Submit";
  108. btn.className = "mybtn";
  109. btn.setAttribute('data-txt', text);
  110. btn.style =
  111. "position: fixed; right: 520px; font-size: 30px; z-index: 100000; top: 0; border: 0; background: aliceblue; color: coral; padding: 0 20px; border-radius: 5px; cursor: pointer;" + style;
  112. document.body.appendChild(btn);
  113. btn.addEventListener('click', listener)
  114. console.log('createBtn: btn=', btn);
  115. // this.mybtn = btn;
  116. return btn;
  117. }
  118.  
  119. function addAutoDeployBtn(times) {
  120. if (times < 1) return;
  121. setTimeout(() => {
  122.  
  123. if (location.href === 'https://devops-cloud.bgy.com.cn/ext/@console-plugin/cd/5e787768cc788/deploy') {
  124. createBtn('autoDeploy', autoClickHostDeploy)
  125. } else {
  126. addAutoDeployBtn(times - 1)
  127. }
  128. }, 1000)
  129. }
  130.  
  131. addAutoDeployBtn(5)
  132.  
  133. // autoClickHostDeploy()
  134.  
  135. function autoClickLogin() {
  136. if (
  137. location.href.includes(
  138. "/auth/realms/bgy/protocol/openid-connect/auth?client_id"
  139. )
  140. ) {
  141. setTimeout(() => {
  142. const link = document.querySelector("#zocial-bgy");
  143. link && link.click();
  144. }, 2000);
  145. }
  146.  
  147.  
  148. // if(location.href.includes('https://loginuat.countrygarden.com.cn/idp/authcenter/ActionAuthChain')) {
  149. // setTimeout(() => {
  150. // const btn = document.querySelector(".loginBt");
  151. // btn && btn.click();
  152. // }, 4000);
  153. // }
  154. }
  155.  
  156. autoClickLogin();
  157.  
  158. function checkCopyEnable() {
  159. const disable = ["countrygarden", "localhost"].some((kw) =>
  160. location.href.includes(kw)
  161. );
  162. return !disable;
  163. }
  164.  
  165. function mycopy(text) {
  166. if (!checkCopyEnable()) return;
  167.  
  168. let input = document.querySelector("#myInputEle");
  169. if (!input) {
  170. const inpEle = document.createElement("input");
  171. inpEle.type = "text";
  172. document.body.insertBefore(inpEle, null);
  173. inpEle.style = "position: fixed; top: -100px; right: 0; z-index: 10000;";
  174. inpEle.setAttribute("id", "myInputEle");
  175. input = inpEle;
  176.  
  177. const btn = document.createElement("button");
  178. btn.id = "myCpBtn";
  179. // document.body.insertBefore(btn, inpEle)
  180. // btn.style = 'position: fixed; top: 0; left: 0; z-index: 1000'
  181. // btn.textContent = 'copy url'
  182. const doCopy = function () {
  183. input.select();
  184. input.setSelectionRange(0, input.value.length);
  185. document.execCommand("copy");
  186. log("copy done");
  187. };
  188.  
  189. document.body.addEventListener("dblclick", doCopy);
  190. }
  191.  
  192. input.value = text;
  193. }
  194.  
  195. // eslint-disable-next-line
  196. mycopy(`[${document.title}](${location.href})`);
  197.  
  198. function closeNoticeDialog(times = 1) {
  199. const maxtimes = 100;
  200. const button = document.querySelector(".notice_content + .footer button");
  201. if (button) {
  202. button.click();
  203. } else {
  204. setTimeout(closeNoticeDialog.bind(null, times + 1), 1000);
  205. }
  206. }
  207.  
  208. closeNoticeDialog();
  209.  
  210. function $(selector) {
  211. return document.querySelector(selector);
  212. }
  213.  
  214. class DevopsBuild {
  215. constructor(sysName, isProd) {
  216. const srmBuildUrl =
  217. "https://devops-cloud.bgy.com.cn/next/ci/project/5f6c900f4251e/build";
  218. const gysSrmBuildUrl =
  219. "https://devops-cloud.bgy.com.cn/next/ci/project/5f70e768c3590/build";
  220. const ispBuildUrl =
  221. "https://devops-cloud.bgy.com.cn/next/ci/project/5de90b7183a5b/build";
  222. const intBuildUrl = "https://devops-cloud.bgy.com.cn/next/ci/project/5f6a0872bfc2b/build"
  223. const urls = {
  224. srm: srmBuildUrl,
  225. isp: ispBuildUrl,
  226. int: intBuildUrl,
  227. 'gys-srm': gysSrmBuildUrl,
  228. };
  229.  
  230. const buildUrl = urls[sysName];
  231. if (!buildUrl) {
  232. alert("sysName not valid");
  233. }
  234.  
  235. this.isProd = isProd;
  236. this.sysName = sysName;
  237. this.buildUrl = buildUrl;
  238. }
  239.  
  240. start() {
  241. if (
  242. location.href.startsWith("https://devops-cloud.bgy.com.cn/") === false
  243. )
  244. return;
  245.  
  246. this.btn = this.createBtn();
  247. this.checkShouldShowBtn();
  248. this.decoratePushState();
  249. this.listenClickBtn();
  250.  
  251. this.constructor.prototype.pushStateCallbackList =
  252. this.constructor.prototype.pushStateCallbackList || [];
  253.  
  254. this.pushStateCallbackList.push(this.pushStateCallback.bind(this));
  255. }
  256.  
  257. listenClickBtn() {
  258. this.btn.addEventListener("click", () => {
  259. this.send();
  260. });
  261. }
  262.  
  263. createBtn() {
  264. if (this.btn) return;
  265. const btn = document.createElement("button");
  266. btn.textContent = this.sysName + ` build ${this.isProd ? 'prod' : 'uat'}`;
  267. btn.className = `build-${this.isProd ? 'prod' : 'uat'}-btn-` + this.sysName;
  268. const right = this.isProd ? '700px' : '250px';
  269. btn.style =
  270. `position: fixed; right: ${right}; font-size: 30px; z-index: 100; top: 0; border: 0; background: aliceblue; color: coral; padding: 0 20px; border-radius: 5px; cursor: pointer;`;
  271. document.body.appendChild(btn);
  272. return btn;
  273. }
  274.  
  275. pushStateCallback() {
  276. this.checkShouldShowBtn();
  277. }
  278.  
  279. decoratePushState() {
  280. if (!history.pushState.isMy) {
  281. const pushState = history.pushState;
  282.  
  283. // eslint-disable-next-line
  284. const self = this;
  285. history.pushState = function myPushState(...args) {
  286. // console.log('=====> pushState call', args, self.pushStateCallbackList)
  287. self.pushStateCallbackList.forEach((cb) => cb());
  288. pushState.apply(history, args);
  289. };
  290. history.pushState.isMy = true;
  291. }
  292. }
  293.  
  294. checkShouldShowBtn() {
  295. setTimeout(() => {
  296. const shouldShow = location.href.startsWith(this.buildUrl);
  297. this.btn.style.display = shouldShow ? "inline-block" : "none";
  298.  
  299. if (shouldShow) {
  300. setTimeout(() => this.clickFirstRow(), 3000);
  301. }
  302. }, 2000);
  303. }
  304.  
  305. sendForSRM() {
  306. fetch(
  307. "https://devops-cloud.bgy.com.cn/next/api/gateway/pipeline.pipeline.Execute/api/pipeline/v1/projects/5f6c900f4251e/pipelines/5f6c903b924f0/execute",
  308. {
  309. headers: {
  310. accept: "*/*",
  311. "accept-language": "zh-CN,zh;q=0.9",
  312. "cache-control": "no-cache",
  313. "content-type": "application/json",
  314. lang: "zh",
  315. pragma: "no-cache",
  316. "sec-ch-ua":
  317. '"Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"',
  318. "sec-ch-ua-mobile": "?0",
  319. "sec-ch-ua-platform": '"Windows"',
  320. "sec-fetch-dest": "empty",
  321. "sec-fetch-mode": "cors",
  322. "sec-fetch-site": "same-origin",
  323. },
  324. referrer:
  325. "https://devops-cloud.bgy.com.cn/next/ci/project/5f6c900f4251e/build",
  326. referrerPolicy: "strict-origin-when-cross-origin",
  327. body: `{"inputs":[{"name":"env_param","value":"${this.isProd ? 'prod' : 'uat'}"}],"branch":"${this.isProd ? 'prod' : 'uat'}"}`,
  328. method: "POST",
  329. mode: "cors",
  330. credentials: "include",
  331. }
  332. );
  333. const isBuildingDetail = /build\/\w+$/.test(location.href);
  334. setTimeout(() => {
  335. let buildListUrl = "";
  336. if (!isBuildingDetail) {
  337. buildListUrl = location.href;
  338. } else {
  339. buildListUrl = location.href.replace(/build\/\w+$/, "build");
  340. }
  341. location.href = buildListUrl + "?clickfirst=1";
  342. }, 1000);
  343. }
  344. sendForINT() {
  345. fetch("https://devops-cloud.bgy.com.cn/next/api/gateway/pipeline.pipeline.Execute/api/pipeline/v1/projects/5f6a0872bfc2b/pipelines/5f6a08ea27a78/execute", {
  346. "headers": {
  347. "accept": "*/*",
  348. "accept-language": "zh-CN,zh;q=0.9",
  349. "content-type": "application/json",
  350. "lang": "zh",
  351. "sec-ch-ua": "\"Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"115\", \"Chromium\";v=\"115\"",
  352. "sec-ch-ua-mobile": "?0",
  353. "sec-ch-ua-platform": "\"Windows\"",
  354. "sec-fetch-dest": "empty",
  355. "sec-fetch-mode": "cors",
  356. "sec-fetch-site": "same-origin"
  357. },
  358. "referrer": "https://devops-cloud.bgy.com.cn/next/ci/project/5f6a0872bfc2b/build",
  359. "referrerPolicy": "strict-origin-when-cross-origin",
  360. "body": "{\"inputs\":[{\"name\":\"env_param\",\"value\":\"uat\"}],\"branch\":\"uat\"}",
  361. "method": "POST",
  362. "mode": "cors",
  363. "credentials": "include"
  364. });
  365. const isBuildingDetail = /build\/\w+$/.test(location.href);
  366. setTimeout(() => {
  367. let buildListUrl = "";
  368. if (!isBuildingDetail) {
  369. buildListUrl = location.href;
  370. } else {
  371. buildListUrl = location.href.replace(/build\/\w+$/, "build");
  372. }
  373. location.href = buildListUrl + "?clickfirst=1";
  374. }, 1000);
  375. }
  376.  
  377. clickFirstRow() {
  378. const uparams = new URLSearchParams(location.search.replace(/^\?/, ""));
  379. if (!uparams.get("clickfirst")) return;
  380. const link = document.querySelector(
  381. ".ant-table-tbody tr:nth-child(2) a:first-child"
  382. );
  383. if (!link) {
  384. console.log("not found first row link");
  385. return;
  386. }
  387. link.click();
  388. }
  389.  
  390. sendForISP() {
  391. fetch(
  392. "https://devops-cloud.bgy.com.cn/next/api/gateway/pipeline.pipeline.Execute/api/pipeline/v1/projects/5de90b7183a5b/pipelines/5f1f7ed6f1977/execute",
  393. {
  394. headers: {
  395. accept: "*/*",
  396. "accept-language": "zh-CN,zh;q=0.9",
  397. "cache-control": "no-cache",
  398. "content-type": "application/json",
  399. lang: "zh",
  400. pragma: "no-cache",
  401. "sec-ch-ua":
  402. '"Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"',
  403. "sec-ch-ua-mobile": "?0",
  404. "sec-ch-ua-platform": '"Windows"',
  405. "sec-fetch-dest": "empty",
  406. "sec-fetch-mode": "cors",
  407. "sec-fetch-site": "same-origin",
  408. },
  409. referrer:
  410. "https://devops-cloud.bgy.com.cn/next/ci/project/5de90b7183a5b/build",
  411. referrerPolicy: "strict-origin-when-cross-origin",
  412. body: '{"inputs":[{"name":"env_param","value":"uat"}],"branch":"uat"}',
  413. method: "POST",
  414. mode: "cors",
  415. credentials: "include",
  416. }
  417. );
  418.  
  419. const isBuildingDetail = /build\/\w+$/.test(location.href);
  420. setTimeout(() => {
  421. let buildListUrl = "";
  422. if (!isBuildingDetail) {
  423. buildListUrl = location.href;
  424. } else {
  425. buildListUrl = location.href.replace(/build\/\w+$/, "build");
  426. }
  427. location.href = buildListUrl + "?clickfirst=1";
  428. }, 1000);
  429. }
  430.  
  431. sendForGysSrm() {
  432. fetch("https://devops-cloud.bgy.com.cn/next/api/gateway/pipeline.pipeline.Execute/api/pipeline/v1/projects/5f70e768c3590/pipelines/5f70e769f11f9/execute", {
  433. "headers": {
  434. "accept": "*/*",
  435. "accept-language": "zh-CN,zh;q=0.9",
  436. "cache-control": "no-cache",
  437. "content-type": "application/json",
  438. "lang": "zh",
  439. "pragma": "no-cache",
  440. "sec-ch-ua": "\"Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"115\", \"Chromium\";v=\"115\"",
  441. "sec-ch-ua-mobile": "?0",
  442. "sec-ch-ua-platform": "\"Windows\"",
  443. "sec-fetch-dest": "empty",
  444. "sec-fetch-mode": "cors",
  445. "sec-fetch-site": "same-origin"
  446. },
  447. "referrer": "https://devops-cloud.bgy.com.cn/next/ci/project/5f70e768c3590/build",
  448. "referrerPolicy": "strict-origin-when-cross-origin",
  449. "body": "{\"inputs\":[{\"name\":\"env_param\",\"value\":\"uat\"}],\"branch\":\"uat\"}",
  450. "method": "POST",
  451. "mode": "cors",
  452. "credentials": "include"
  453. });
  454.  
  455. const isBuildingDetail = /build\/\w+$/.test(location.href);
  456. setTimeout(() => {
  457. let buildListUrl = "";
  458. if (!isBuildingDetail) {
  459. buildListUrl = location.href;
  460. } else {
  461. buildListUrl = location.href.replace(/build\/\w+$/, "build");
  462. }
  463. location.href = buildListUrl + "?clickfirst=1";
  464. }, 1000);
  465. }
  466.  
  467. send() {
  468. const sends = {
  469. srm: this.sendForSRM,
  470. isp: this.sendForISP,
  471. int: this.sendForINT,
  472. 'gys-srm': this.sendForGysSrm,
  473. };
  474.  
  475. const send = sends[this.sysName];
  476. if (send) {
  477. send.call(this);
  478. }
  479. }
  480. }
  481.  
  482. const srmBuild = new DevopsBuild("srm");
  483. srmBuild.start();
  484. const srmProdBuild = new DevopsBuild("srm", true);
  485. srmProdBuild.start();
  486. const ispBuild = new DevopsBuild("isp");
  487. ispBuild.start();
  488. const intBuild = new DevopsBuild("int");
  489. intBuild.start();
  490. const gyssrmBuild = new DevopsBuild("gys-srm");
  491. gyssrmBuild.start();
  492.  
  493. // isp uat 登录自动填充
  494. class FormFiller {
  495. constructor(enableUrl, values, btn) {
  496. this.url = enableUrl;
  497. this.values = values;
  498. this.btn = btn;
  499. }
  500.  
  501. element(selector) {
  502. return document.querySelector(selector);
  503. }
  504.  
  505. fill() {
  506. const inputSelectors = Object.keys(this.values);
  507. const inputValues = Object.values(this.values);
  508. inputSelectors.forEach((inpSelctor, i) => {
  509. const input = this.element(inpSelctor);
  510. if (input) {
  511. input.value = inputValues[i];
  512. } else {
  513. console.log("not found element for", inpSelctor);
  514. }
  515. });
  516. }
  517.  
  518. submit() {
  519. if (this.btn.selector) {
  520. const submitBtn = this.element(this.btn.selector);
  521. submitBtn?.click();
  522. return;
  523. }
  524.  
  525. console.log("not found submitBtn cancel", this.btn); // debug only
  526. }
  527.  
  528. createBtn() {
  529. // if (this.mybtn) return;
  530. const btn = document.createElement("button");
  531. btn.textContent = this.btn.text || "Submit";
  532. btn.className = "mybtn";
  533. btn.style =
  534. "position: fixed; right: 250px; font-size: 30px; z-index: 100; top: 0; border: 0; background: aliceblue; color: coral; padding: 0 20px; border-radius: 5px; cursor: pointer;";
  535. document.body.appendChild(btn);
  536. // this.mybtn = btn;
  537. return btn;
  538. }
  539.  
  540. start() {
  541. if (location.href.includes(this.url) === false) return;
  542.  
  543. this.mybtn = this.createBtn();
  544. this.mybtn.addEventListener("click", () => {
  545. this.fill();
  546. this.submit();
  547. });
  548. }
  549. }
  550.  
  551. const ISPUatFormFiller = new FormFiller(
  552. "https://ssploginuat.",
  553. {
  554. "#j_username": "gys_zengzhaohua",
  555. "#j_password": "0Jqg0eny",
  556. },
  557. {
  558. selector: ".loginBt",
  559. text: "zengzhaohua Login",
  560. }
  561. );
  562.  
  563. ISPUatFormFiller.start();
  564.  
  565.  
  566. const SRMUatFormFiller = new FormFiller(
  567. "https://loginuat.countrygarden.com.cn/idp/authcenter",
  568. {
  569. "#j_username": "penghaitao01",
  570. "#j_password": "password",
  571. },
  572. {
  573. selector: ".loginBt",
  574. text: "penghaitao Login",
  575. }
  576. );
  577.  
  578. SRMUatFormFiller.start()
  579.  
  580. const SRMProdFormFiller = new FormFiller(
  581. "/idp/authcenter/ActionAuth",
  582. {
  583. "#j_username": "gys_zengzhaohua",
  584. },
  585. {
  586. selector: ".loginBt",
  587. text: "zengzhaohua Login",
  588. }
  589. );
  590. //SRMProdFormFiller.start()
  591.  
  592. // 选择供应商
  593. class SupplierSelector {
  594. constructor(enableUrl, values, submitBtnSelector, selectSelector) {
  595. this.url = enableUrl;
  596. this.values = values;
  597. this.submitBtnSelector = submitBtnSelector
  598. this.selectSelector = selectSelector;
  599. }
  600.  
  601. element(selector) {
  602. return document.querySelector(selector);
  603. }
  604.  
  605. fill(val) {
  606. this.element(this.selectSelector).value = val;
  607. }
  608.  
  609. submit() {
  610. this.element(this.submitBtnSelector).click();
  611. }
  612.  
  613. createBtns() {
  614. // if (this.mybtn) return;
  615. const actionDiv = document.createElement("div");
  616. actionDiv.className = "actions";
  617. actionDiv.style =
  618. "position: fixed; left: 550px; z-index: 100000; top: 0;";
  619.  
  620. const btnStyle =
  621. "font-size: 20px; border: 0; background: aliceblue; color: coral; padding: 0 20px; border-radius: 5px; cursor: pointer; margin: 0 10px;";
  622. this.values.forEach((option) => {
  623. const btn = document.createElement("button");
  624. btn.className = "mybtn" + option.val;
  625. btn.textContent = option.text;
  626. btn.style = btnStyle;
  627. actionDiv.appendChild(btn);
  628. btn.addEventListener("click", () => {
  629. this.fill(option.val);
  630. this.submit();
  631.  
  632. actionDiv.style.display = 'none'
  633. });
  634. });
  635. document.body.appendChild(actionDiv);
  636. }
  637.  
  638. start() {
  639. if (typeof this.url === 'string' && location.href.includes(this.url) === false) return;
  640. if (this.url instanceof RegExp && this.url.test(location.href) === false) return;
  641.  
  642. this.createBtns();
  643. }
  644. }
  645.  
  646. const supplierAutoSelector = new SupplierSelector(
  647. /sispuat.countrygarden.com.cn\/[^?]*?\?access_token=/,
  648. [
  649. { val: "1566579841157664769", text: "中建三局" },
  650. { val: "1566700513699684354", text: "广东腾越" },
  651. { val: "1572034947512098817", text: "测试供应商001" },
  652. { val: "1566761465878519810", text: "四川建设" },
  653. { val: "1566723359788359681", text: "佛山科达机电" },
  654. ],
  655. ".el-message-box__btns .el-button",
  656. "#supplierSselect"
  657. );
  658.  
  659. supplierAutoSelector.start();
  660.  
  661. function redirectToISPUATTenderList(canTryTimes) {
  662. if (!canTryTimes) return
  663. if (location.href === 'https://sispuat.countrygarden.com.cn/#/Home') {
  664. setTimeout(() => {
  665. location.href = 'https://sispuat.countrygarden.com.cn/#/isp/tender-list'
  666. }, 1000)
  667. } else {
  668. setTimeout(() => redirectToISPUATTenderList(canTryTimes - 1), 1000);
  669. }
  670. }
  671.  
  672. redirectToISPUATTenderList(100)
  673. })();
  674.  
  675.  
  676. (function () {
  677. function clearStorageAndCookie(isrefresh = true) {
  678. [sessionStorage, localStorage].forEach((storage) => storage.clear());
  679. clearCookies();
  680. console.log(document.cookie, "done!!");
  681. isrefresh && setTimeout(location.reload.bind(location), 1000);
  682. }
  683.  
  684. function pick(data, keys) {
  685. return keys.reduce((ret, key) => {
  686. ret[key] = data[key];
  687. return ret;
  688. }, {});
  689. }
  690.  
  691. function setLocalStorage(data) {
  692. Object.keys(data).forEach((key) => {
  693. localStorage[key] = data[key];
  694. });
  695.  
  696. console.log("done", localStorage);
  697. }
  698.  
  699. function getCookies() {
  700. return document.cookie.match(/[\w-]+(?=\=[^;]+)/g) || [];
  701. }
  702.  
  703. function clearCookies() {
  704. getCookies().forEach((cname) => {
  705. delCookie(cname);
  706. });
  707. }
  708.  
  709. function setCookie(cname, cvalue, exdays) {
  710. const d = new Date();
  711. d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
  712. const expires = "; Expires=" + d.toUTCString();
  713. // document.cookie = cname + "=" + cvalue + expires + "; Path=/";
  714. document.cookie = cname + "=" + cvalue + expires;
  715. }
  716.  
  717. function delCookie(cname) {
  718. console.log("del cookie:", cname);
  719. setCookie(cname, "", -1);
  720. }
  721.  
  722. function copy(str) {
  723. const el = document.createElement("textarea");
  724. el.value = str;
  725. el.setAttribute("readonly", "");
  726. el.style.position = "absolute";
  727. el.style.left = "-9999px";
  728. document.body.appendChild(el);
  729. el.select();
  730. document.execCommand("copy");
  731. document.body.removeChild(el);
  732. }
  733.  
  734. function setDebugSwitch(key, val = 1) {
  735. // localStorage.debug = localStorage.debug + 'schema;domain;zxhbEdit=1'
  736. const debugval = localStorage.debug || ''
  737. const pairs = debugval.split(';').map(pair => pair.includes('=') ? pair.split('=') : (pair + '=true').split('='))
  738. const conf = Object.fromEntries(pairs)
  739. conf[key] = val
  740. console.log('new conf:', conf)
  741. const entriesVal = Object.entries(conf).map(pair => pair.join('=')).join(';')
  742. localStorage.debug = entriesVal
  743. }
  744. function debugDomainSchema() {
  745. setDebugSwitch('domain')
  746. setDebugSwitch('schema')
  747. }
  748.  
  749. function copyISPSupplierInfo() {
  750. copy(
  751. `localStorage.gys_cur_supplier_info = ${JSON.stringify(
  752. localStorage.gys_cur_supplier_info
  753. )}; setTimeout(() => location.reload(), 1000);`
  754. );
  755. console.log("copy done");
  756. }
  757.  
  758. function getSchema(data = {}) {
  759. const result = Object.keys(data)
  760. .sort()
  761. .reduce((ret, key) => {
  762. return ret + `${key} ${data[key].title}\n`;
  763. }, "");
  764. console.log(result);
  765. copy(result);
  766. }
  767.  
  768. function toUnicode(str) {
  769. const ls = str.split("");
  770. const result = ls
  771. .map((c) => {
  772. if (/\w/.test(c)) return c;
  773.  
  774. return "\\u" + c.charCodeAt(0).toString(16).toUpperCase();
  775. })
  776. .join("");
  777.  
  778. copy(result);
  779. console.log("copy done");
  780. return result;
  781. }
  782.  
  783.  
  784. function getk2Params() {
  785. return Object.assign({}, window.KStarForm.vmFormData.vmFormContent);
  786. }
  787.  
  788. function isPlainObject(val) {
  789. return Object.prototype.toString.call(val).slice(8, -1) === "Object";
  790. }
  791.  
  792. function getTableTypeDefines(vm) {
  793. const { tableData, schema } = vm.props ?? {};
  794. if (!tableData) {
  795. console.warn("not tableData found:", vm.props);
  796. return;
  797. }
  798.  
  799. return getTypeDefines(tableData[0], schema);
  800. }
  801.  
  802. function getTypeDefines(obj = {}, schema = false, level = 10) {
  803. // if (Array.isArray(obj)) {
  804. // if (obj.length === 0) {
  805. // return 'Array<any>'
  806. // }
  807. // return `Array<${getTypeDefines(obj[0], schema, level - 1)}>`
  808. // }
  809. if (Array.isArray(obj)) {
  810. obj = obj[0];
  811. }
  812.  
  813. const getPrimativeType = (key, val) => {
  814. let type = typeof val;
  815. let text = "";
  816.  
  817. if (!schema) {
  818. return { type, text };
  819. }
  820.  
  821. const props = schema.properties ?? {};
  822. if (props[key]) {
  823. type = props[key].type;
  824. text = props[key].title;
  825. }
  826.  
  827. return { type, text };
  828. };
  829. let ret = "{\n";
  830. Object.keys(obj).forEach((key) => {
  831. if (key.startsWith("_")) return;
  832. const val = obj[key];
  833. const isPrimative = !isPlainObject(val) && !Array.isArray(val);
  834. let title = "";
  835. let valType;
  836. if (isPrimative) {
  837. const { type, text } = getPrimativeType(key, val);
  838. valType = type;
  839. title = text;
  840. } else {
  841. valType = getTypeDefines(val, schema);
  842. }
  843.  
  844. const keyDefine = `${key}: ${valType};${title ? " // " + title : ""}\n`;
  845. ret += keyDefine;
  846. });
  847. ret += "\n}";
  848.  
  849. copy(ret);
  850. console.log("copy done!");
  851. return ret;
  852. }
  853.  
  854. window.my = {
  855. getTableTypeDefines,
  856. getk2Params,
  857. toUnicode,
  858. getSchema,
  859. copyISPSupplierInfo,
  860. setLocalStorage,
  861. pick,
  862. clearStorageAndCookie,
  863. setDebugSwitch,
  864. debugDomainSchema,
  865. }
  866. })();