合同助手

在合同中心页面添加“合同刷新”和“合同截图”按钮,并设置全局按钮样式。点击“刷新”按钮后,每隔2秒钟自动刷新合同状态。

// ==UserScript==
// @name        合同助手
// @namespace   https://vinceofx.com/
// @version     1.0
// @homepage    https://vinceofx.com/
// @description 在合同中心页面添加“合同刷新”和“合同截图”按钮,并设置全局按钮样式。点击“刷新”按钮后,每隔2秒钟自动刷新合同状态。
// @icon        data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAFZJJREFUeF7t3XtwVFWeB/Dv7e6k835BEkiQ9xJEwoIIDD7J6ozAWuAOukx0SkedKYtRd4Wy3JqZqh3KP7ZwZmdl5A+0anRmx1VxR0UtQR2cEVZ0QF5CUB5hwGgIkIQknWcn6fTduh06E5ruvufce87te2//+h+o5JzfOf0755Nzz723bytI81f9Y9P9A76emrCifAsq5gDqdECpviItKo4AyimPoh4OA3tmFzb9WVmPUJqnz/VvX3H9O0zwBuvWVayGitUA/sloDhSoryuq57VrNp593WgMqmfvDKQVkPXr4bmro+IJVcFjACaIGhoFaFChbKp+5uyvRMWkOPbIQNoAqVtX8SBUrAdwlazUK8BXgLJ+9jNn/1tWGxTX2gy4HsjhxyoneDLUTVBxp3WpVd/w+EKPXvPLlvPWtUktyciAq4EceXzcMkXx/BZAuYzk6cQ8izAeqP51044UtE1NCsqAa4HUPV7xIBS8IChPxsOo6n3VG8+9ZDwA1UxlBlwJ5Mi68Q8rqvJcKhN7WdsqHqre2PSibfpDHWHOgOuAHH68otaj4BXmDFhUUFHUu2b/17k3LGqOmhGUAVcB+WLtuIVhePYKyo3wMB5VmXfNxrOfCw9MAaVlwFVAjq6tOKQCc6Vly2RgBepns585t8hkGKpuYQZcA+To4+N/pSrKOgtzZ6gpFdgw55mmnxiqTJUsz4AwID849Opkj8dzv+XvAMDVZw5WLt310o9EtO0v9iGrOBO+HC88PgXhkIpQ7xCCbYPo7xgU0QTeXfLAc/WT5zj+GsmC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w5clVpQgH+3ASEPZcuaIk4eAbRgLCly9HlyYc/MNHQPhz5sgaGo7+tq4KR3Y+hZ0WCeT/AVyX18j9dseDAAAAAElFTkSuQmCC
// @grant       none
// @supportURL  https://vinceofx.com/index.php/download/
// @match       http://oa.ccts.cn/*
// @include     http://oa.ccts.cn/*
// @license     MIT
// ==/UserScript==

(function () {
  'use strict';

  // 添加全局按钮样式
  const style = document.createElement('style');
  style.type = 'text/css';
  style.innerHTML = `
    a.contract-button {
      display: inline-block;
      padding: 5px 10px;
      margin-right: 10px;
      background-color: #2aae67;
      color: black;
      border: 1px solid black;
      border-radius: 5px;
      text-decoration: none;
      font-weight: bold;
    }

    a.contract-button:hover,
    a.contract-button.selected {
      background-color: white;
      color: black;
    }
  `;
  document.head.appendChild(style);

  const currentPageUrl = window.location.href;

  // 创建按钮的辅助函数
  function createButton(text, clickHandler) {
    const button = document.createElement('a');
    button.href = 'javascript:void(0);';
    button.textContent = text;
    button.classList.add('contract-button');
    button.addEventListener('click', clickHandler);
    return button;
  }

  //截图和刷新功能模块
  if (currentPageUrl.includes('http://oa.ccts.cn/Distributor/Contractcenter/index/ssq/1/p/') || currentPageUrl.includes('http://oa.ccts.cn/Distributor/Contractcenter/index/ssq/1.html')) {
    // 查找表格中的所有行
    const rows = document.querySelectorAll('tr');

    // 向每一行添加按钮
    rows.forEach(row => {
      const operationColumn = row.querySelector('.operation');
      if (operationColumn) {
        const refreshButton = createButton('刷新', handleRefreshClick);

        const screenshotButton = createButton('截图', handleScreenshotClick);

        operationColumn.parentNode.insertBefore(screenshotButton, operationColumn.nextSibling);
        operationColumn.parentNode.insertBefore(refreshButton, screenshotButton.nextSibling);
      }
    });

    // 处理截图按钮点击事件
    function handleScreenshotClick(event) {
      var signLink = document.querySelector('a[href^="javascript:signssq("]'); // 获取要点击的元素合同签约链接
      // 模拟点击链接
      if (signLink) {
        signLink.click();
      } else {
        console.log('找不到合同签约链接');
      }
    }

    // 处理刷新按钮点击事件
    function handleRefreshClick(event) {
      let isRefreshing = false;
      let signLink = null;
      const refreshLink = document.querySelector('a.watch.color1[onclick^="doupdate"]');

      const watchInterval = setInterval(() => {
        if (!isRefreshing) {
          refreshLink.click();
        } else if (signLink || (signLink = document.querySelector('a.watch.color1[onclick^="signssq"]'))) {
          signLink.click();
          clearInterval(watchInterval);
        }
        const signLink = document.querySelector('a.watch.color1[onclick^="signssq"]');
        if (signLink) {
          isRefreshing = true;
        }
      }, 2000);
    }
  }


  //常用编码功能模块
  if (currentPageUrl.includes('http://oa.ccts.cn/Distributor/Line/index.html')) {
    // 添加常用编码按钮
    const stateBox = document.querySelector('.stateBox');
    const commonCodesButton = document.createElement('a');
    commonCodesButton.href = 'javascript:void(0);';
    commonCodesButton.textContent = '常用编码';
    commonCodesButton.classList.add('common-codes-button');
    stateBox.appendChild(commonCodesButton);

    // 添加常用编码面板
    const commonCodesPanel = document.createElement('div');
    commonCodesPanel.classList.add('common-codes-panel');
    commonCodesPanel.innerHTML = `
    <ul>
      <li>编码1</li>
      <li>编码2</li>
      <li>编码3</li>
      <li>编码4</li>
      <li>编码5</li>
      <li>编码6</li>
      <li>编码7</li>
      <li>编码8</li>
      <li>编码9</li>
      <li>编码10</li>
    </ul>
  `;
    stateBox.appendChild(commonCodesPanel);

    // 监听常用编码按钮点击事件
    commonCodesButton.addEventListener('click', () => {
      commonCodesPanel.classList.toggle('show');
    });

    // 监听常用编码面板选项点击事件
    const searchForm = document.querySelector('#search_form');
    const wordInput = document.querySelector('form#search_word input[name="word"]');
    commonCodesPanel.querySelectorAll('li').forEach((item, index) => {
      item.addEventListener('click', () => {
        const code = item.textContent;
        wordInput.value = code;
        searchForm.submit();
      });
    });
  }



})();