TAPD link clickable

tapd 链接可点击

  1. // ==UserScript==
  2. // @name TAPD link clickable
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description tapd 链接可点击
  6. // @author liuzp01
  7. // @match https://www.tapd.cn/*
  8. // @grant none
  9. // @requir https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
  10. // ==/UserScript==
  11.  
  12. /*jshint esversion: 6 */
  13. (function() {
  14. 'use strict';
  15.  
  16. // Your code here...
  17. const needArr = ['分支链接','Jira链接','CodeReview链接', 'ykUpgrader链接'];
  18. var $ = window.jQuery;
  19.  
  20. function init() {
  21. let arr = Array.from($(".left_3_col"));
  22. if (arr.length > 0) {
  23. // 处理链接
  24. arr.forEach(item => {
  25. // 创建 new-wrap 作为隔离区域
  26. let wrap = $(item).children(".new-wrap");
  27. if (wrap.length == 0) {
  28. $(item).append(`<div class="new-wrap"></div>`);
  29. wrap = $(item).children(".new-wrap")
  30. } else {
  31. $(wrap[0]).empty();
  32. }
  33.  
  34. let label = $(item).children(".tapd-view-title")[0].innerText;
  35. if (needArr.includes(label)) {
  36. let value = $(item).find(".editable-value")[0].innerText;
  37. let reg = /\s/g;
  38. let valueArr = [];
  39.  
  40. if (reg.test(value)) {
  41. valueArr = value.split(/\s/g);
  42. } else {
  43. valueArr = [value];
  44. }
  45.  
  46. valueArr.forEach((child, index) => {
  47. if (child !== '--') {
  48. $(wrap[0]).append(`<a style="padding: 3px;display: inline-block;border: 1px solid #3582fb;border-radius: 5px;margin-bottom:5px;" href="${child}">Jump to ${label} ${index + 1}</a>`);
  49. }
  50. })
  51.  
  52. };
  53. // 处理粘贴
  54. if (label === '分支名称') {
  55. let value = $(item).find(".editable-value")[0].innerText;
  56. $(wrap[0]).append(`<div style="padding: 3px;display: inline-block;cursor:pointer;border: 1px solid #3582fb;border-radius: 5px;color:#3582fb;font-size:12px;" id="copyBtn">Copy ${label}</div>`);
  57. $('#copyBtn').click(() => {
  58. copy(value);
  59. });
  60. }
  61. })
  62. }
  63. }
  64.  
  65.  
  66. function copy(value) {
  67. const input = document.createElement('input');
  68. document.body.appendChild(input);
  69. input.setAttribute('value', value);
  70. input.select();
  71. if (document.execCommand('copy')) {
  72. document.execCommand('copy');
  73. console.log('复制成功');
  74. }
  75. document.body.removeChild(input);
  76. }
  77.  
  78. // 监听右侧输入框失去焦点事件,重新执行init() 函数。
  79. $('#base_information').on('blur','input',function () {
  80. setTimeout(() => {
  81. init();
  82. },1000)
  83. })
  84.  
  85.  
  86. init();
  87.  
  88. })();