Greasy Fork is available in English.

TAPD 调整需求详情页面字段宽度、自动收起过滤条件、以及其他功能,具体看事件: addEventListener

用于在 TAPD 需求列表(查询过滤)页面,调整展示的字段宽度,默认的 ID 等字段列太宽。适应字段宽度,提高屏幕利用率

// ==UserScript==
// @name         TAPD 调整需求详情页面字段宽度、自动收起过滤条件、以及其他功能,具体看事件: addEventListener
// @namespace    hl_qiu163@163.com
// @version      0.1.6
// @description  用于在 TAPD 需求列表(查询过滤)页面,调整展示的字段宽度,默认的 ID 等字段列太宽。适应字段宽度,提高屏幕利用率
// @author       qiuhongliang
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tapd.cn
// @match        https://www.tapd.cn/tapd_fe/worktable/search*
// @grant        none
// @license      GPL
// ==/UserScript==

(function () {
  "use strict";

  let ops = document.body;
  ops.addEventListener("DOMNodeInserted", function (event) {
    // total++;
    // console.log("total" + total);

    let randInt = Math.floor(Math.random() * 100); // 返回 0 至 99 之间的数
    if (randInt > 50) {
      return;
    }
    
    // console.log("【TAPD 调整需求详情页面字段宽度、自动收起过滤条件】进入监听 DOMNodeInserted 事件");

    // 删除 story 标签
    removeStoryTag();

    // 修改字段列的值,删除无效的字符,减少空间占用
    modifyTableColumnValue();

    // 调整宽度
    adjustElementWidth();

    // 收起过滤条件
    foldFilterConditionArrowTop();

    // 修改页面的标题,使得标题栏展示过滤条件的名称
    changeTitle();
  });

  /**
   * 删除 story 标签
   */
  function removeStoryTag() {
    let story_icon_list = document.getElementsByClassName("workitem-icon");
    let size = story_icon_list.length;
    for (let i = size - 1; i >= 0; i--) {
      story_icon_list[i].remove();
    }
  }

  /**
   * 修改页面的标题,使得标题栏展示过滤条件的名称
   * @returns
   */
  function changeTitle() {
    // 当前的查询条件列表
    let view_list_ul = document.getElementsByClassName("view-list-ul")[0];
    if (!view_list_ul) {
      return;
    }

    // 当前的查询条件
    let current_view = view_list_ul.getElementsByClassName("current-view")[0];
    if (!current_view) {
      return;
    }

    // 覆写标题
    let queryName = current_view.textContent.trim();
    if (!queryName) {
      return;
    }

    document.title = queryName;
  }

  /**
   * 收起过滤条件
   */
  function foldFilterConditionArrowTop() {
    // 点击【收起过滤条件】按钮
    let btn = document.getElementsByClassName("filter-slide__itemicon tapd-icon-d-arrow-top")[0];
    if (btn) {
      btn.click();
    }
  }

  /**
   * 修改字段列的值,删除无效的字符,减少空间占用。比如:去掉 WMS 客户端迭代的“WMS”字样
   * 
   */
  function modifyTableColumnValue() {
    // todo 目前不能处理,出现数据串行的情况,第 n 行的数据复用了前面行的数据,应该是由于这个函数被多次执行导致的。可能要改成监控网络数据,处理接口返回数据。
    return;

    let table_head = document.getElementsByClassName("tapd-table__head--adjustable")[0];
    if (!table_head) {
      return;
    }

    // 序号从 0 开始
    // “迭代”字段列的列序号
    let index_of_iteration_id = -1;
    // “发布计划”字段列序号
    let index_of_release_id = -1;

    // 获取字段列序号 id
    table_head.getElementsByTagName("th").forEach(function (v, i) {
      if (v.getAttribute("field") == "iteration_id") {
        index_of_iteration_id = i;
      }
      if (v.getAttribute("field") == "release_id") {
        index_of_release_id = i;
      }
    });

    // 修改字段列的值
    let detailTable = document.getElementsByClassName("table-scroll__vertical-box--current")[0];
    if (!detailTable) {
      return;
    }

    // 遍历表格行
    detailTable.getElementsByTagName("tr").forEach(function (row, row_index) {
      // 通过表格行,直接定位到“迭代”字段的列
      let filed_col_element = null;
      let filed_value = "";

      // 删除迭代字段内的“WMS”字样 -----------------------------------------------------------------------------------------
      filed_col_element = row.getElementsByTagName("td")[index_of_iteration_id].getElementsByTagName("a")[0];
      if (filed_col_element == null) {
        return;
      }
      filed_value = filed_col_element.textContent.trim();
      if (filed_value.startsWith("WMS") || filed_value.startsWith("wms")) {
        filed_col_element.textContent = filed_value.substr(3);
      }

      // 删除发布计划字段内的“【接口计划】”字样 ----------------------------------------------------------------------------
      filed_col_element = row.getElementsByTagName("td")[index_of_release_id].getElementsByTagName("a")[0];
      if (filed_col_element == null) {
        return;
      }
      filed_value = filed_col_element.textContent.trim();
      if (filed_value.startsWith("【接口计划】")) {
        filed_col_element.textContent = filed_value.substr(6);
      }
    });
  }

  /**
   * 调整需求列表表格的部分字段宽度,提高使用率
   */
  function adjustElementWidth() {
    // 不要判断元素是否存在,当判断的时候,页面会展示未修改的间距,然后等几秒后再突变
    // let table = document.querySelector("#root > div > div.app > div > div > div.worktable-detail > div > div.search-detail-wrap > div.search-result.webkit-scrollbar.search-result-advance.overflow-table");
    // if (!table) {
    //   return
    // }

    // 字段名字:像素大小
    let list = {
      "col-field--id": "70px", // ID
      "col-field--name": "400px", // 标题
      "col-field--priority": "60px", // 优先级
      "col-field--iteration_id": "125px", // 迭代
      "col-field--status": "120px", // 状态
      "col-field--developer": "70px", // 开发人员
      "col-field--owner": "70px", // 处理人
      "col-field--release_id": "115px", // 发布计划
      "col-field--custom_field_卖家账号": "80px", // 卖家账号
      "col-field--custom_field_对客户的影响": "30px", // 对客户的影响
      "col-field--parent_id": "50px", // 父需求
      "col-field--custom_field_产品经理": "70px", // 父需求
    };

    for (let key in list) {
      Array.from(document.getElementsByClassName(key)).forEach(function (v, i) {
        v.style.width = list[key];
      });
    }
  }
})();