iCode Helper

一键复制iCafe单信息,形成Git Commit Msg

当前为 2018-09-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name iCode Helper
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description 一键复制iCafe单信息,形成Git Commit Msg
  6. // @author mzvast@gmail.com
  7. // @match http://newicafe.baidu.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Your code here...
  15. const makeCommitMsg = (issueId, fullTitle) => {
  16. let scope = '';
  17. let title = fullTitle;
  18. if (fullTitle.indexOf('【') !== -1 && fullTitle.indexOf('】') !== -1) {
  19. const matchedScope = fullTitle
  20. .match(/【(.*?)】/g)
  21. .map(t => t.match(/【(.*)】/)[1]);
  22. scope = `:(${matchedScope.join(',')})`;
  23. title = fullTitle.match(/【.*】(.*)/)[1];
  24. }
  25. return `fix${scope}:[${issueId}] ${title}`;
  26. };
  27. const copyText = text => {
  28. const el = document.createElement('textarea');
  29. el.value = text;
  30. document.body.appendChild(el);
  31. el.select();
  32. document.execCommand('copy');
  33. document.body.removeChild(el);
  34. console.log('copied:', text);
  35. };
  36. document.addEventListener(
  37. 'click',
  38. e => {
  39. // console.log(e.target);
  40. if (e.target) {
  41. if (e.target.matches('.titleValue.showIssueView.value')) {
  42. // console.log('.titleValue.showIssueView.value');
  43. const fullTitle = e.target.getAttribute('title');
  44. const issueId = e.target.getAttribute('data-issueid');
  45. const result = makeCommitMsg(issueId, fullTitle);
  46. copyText(result);
  47. } else if (e.target.matches('a.taskLink.titleLink')) {
  48. // console.log('a.taskLink.titleLink');
  49. const fullTitle = e.target.text;
  50. const issueId = e.target
  51. .getAttribute('href')
  52. .match(/issue\/(.*)\/show/)[1];
  53. const result = makeCommitMsg(issueId, fullTitle);
  54. copyText(result);
  55. }
  56. }
  57. },
  58. true
  59. );
  60.  
  61. })();

QingJ © 2025

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