复制任务为表格形式 - qq.com

2023/10/25 15:15:01

当前为 2023-10-25 提交的版本,查看 最新版本

// ==UserScript==
// @license MIT
// @name        复制任务为表格形式 - qq.com
// @namespace   Violentmonkey Scripts
// @match       https://codesign.qq.com/app/design/*
// @grant       none
// @version     1.0
// @author      -
// @description 2023/10/25 15:15:01
// ==/UserScript==

function createFloatMenu ({onClick, text}) {
    const id = 'ff-' + Math.floor(Math.random() * 10);
    var div = document.createElement('div');
    div.id = id;
    div.classList.add('ff-container');

    div.innerHTML = `
        <style>
            .ff-container {
              position: absolute;
              z-index: 1999;
              left: 10px;
              top: 10px;
              background-color: #f1f1f1;
              text-align: center;
              border-radius: 2px;
              font-size: 12px;
              overflow: hidden;
              box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05);
            }

            .ff-header {
              padding: 0 4px;
              cursor: move;
              z-index: 2999;
              background-color: #2196F3;
              display: flex;
              align-items: center;
              justify-content: center;
              color: #fff;
            }

            .ff-action {
            	padding:3px 5px;
                background:white;
                cursor:pointer;
            }
        </style>
        <div id="${id}header" class="ff-header">: :</div>
        <div class="ff-action">${text}</div>
    `;

    document.body.appendChild(div);
    div.querySelector('.ff-action').addEventListener('click', onClick);
    dragElement(div);

    function dragElement(elmnt) {
      var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
      if (document.getElementById(elmnt.id + "header")) {
        /* if present, the header is where you move the DIV from:*/
        document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
      } else {
        /* otherwise, move the DIV from anywhere inside the DIV:*/
        elmnt.onmousedown = dragMouseDown;
      }

      function dragMouseDown(e) {
        e = e || window.event;
        e.preventDefault();
        // get the mouse cursor position at startup:
        pos3 = e.clientX;
        pos4 = e.clientY;
        document.onmouseup = closeDragElement;
        // call a function whenever the cursor moves:
        document.onmousemove = elementDrag;
      }

      function elementDrag(e) {
        e = e || window.event;
        e.preventDefault();
        // calculate the new cursor position:
        pos1 = pos3 - e.clientX;
        pos2 = pos4 - e.clientY;
        pos3 = e.clientX;
        pos4 = e.clientY;
        // set the element's new position:
        elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
        elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
      }

      function closeDragElement() {
        /* stop moving when mouse button is released:*/
        document.onmouseup = null;
        document.onmousemove = null;
      }
    }
}

function copyToTable () {
  if (!document.querySelector('.board-screen-list__section')) {
    return alert('当前页面不适用该脚本');
  }
  var assignee = prompt('请输入默认指派人', '翟')
  if (assignee) {
      var estimateText = `ui: 0h, 联调: 0h(0个Api)`
      var taskNames = Array.from(document.querySelectorAll('.board-screen-list__section')).map(it => {
          const groupName = it.querySelector('.board-screen-list__section-name').innerText;
          var res = Array.from(it.querySelectorAll('.board-screen-list__item-container>div')).map(it => ` \t${it.innerText}\t${assignee}\t0\t${estimateText}`);
          res[0] = groupName + res[0];
          return res;
      }).flat().join('\n');

      var tx = document.createElement('textarea');
      tx.style = "max-height:0;"
      tx.value = taskNames;
      document.body.append(tx)
      tx.select();
      document.execCommand('copy');
      alert('复制成功')
      setTimeout(() => tx.remove(), 800)
  }
}

createFloatMenu({onClick: copyToTable, text: '复制成表格'})

QingJ © 2025

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