Skip to content

Instantly share code, notes, and snippets.

@xgqfrms
Last active September 5, 2023 10:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgqfrms/134e1308ed028bf7a2936bf361cd66d4 to your computer and use it in GitHub Desktop.
Save xgqfrms/134e1308ed028bf7a2936bf361cd66d4 to your computer and use it in GitHub Desktop.
企业微信 robot & Jira (js 版)

企业微信 robot & Jira (js 版)

const wxRobot = () => {
  const url = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=555a887d-c247-4808-a850-xyz`;
  const fetchPOST = (url, obj) => {
    return fetch(
        url,
        {
            method: "POST",
            mode: "no-cors",
            headers: {
                "Content-Type": "application/json",
            },
            body: JSON.stringify(obj),
        },
    )
    .then(res => res.json())
    .then(
        (json) => {
            return json;
        }
    ).catch(err => console.log(`fetch error`, err));
  };
  // loop
  // const trs = [...document.querySelector('[class="issue-table"]')?.lastElementChild?.children] ?? [];
  const trs = [...(document.querySelector('[class="issue-table"]') ?? [])]?.lastElementChild?.children ?? [];
  for (const tr of trs) {
    const link = tr?.firstElementChild?.firstElementChild ?? '';
    const text = tr?.firstElementChild?.firstElementChild?.dataset?.issueKey ?? '';
    const obj = {
      msgtype: "markdown",
      markdown: {
        content: `
> 分配给我的问题:\n
[${text}](${link})\n
        `,
      },
    };
    if(text && link) {
      fetchPOST(url, obj);
    }
  }
}

// 半小时
const timer = 1000 * 60 * 30
setInterval(() => {
  wxRobot();
}, timer);
@xgqfrms
Copy link
Author

xgqfrms commented Mar 31, 2021

@xgqfrms
Copy link
Author

xgqfrms commented Mar 31, 2021

@xgqfrms
Copy link
Author

xgqfrms commented Mar 31, 2021

@xgqfrms
Copy link
Author

xgqfrms commented Mar 31, 2021

jira 页面自动刷新 bug ???

  1. 不刷新,不更新
  2. 刷新后,js 方法丢失

@xgqfrms
Copy link
Author

xgqfrms commented Mar 31, 2021

@xgqfrms
Copy link
Author

xgqfrms commented Mar 31, 2021

const wxRobot = () => {
  const url = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=555a887d-c247-4808-a850-xyz`;
  const fetchPOST = (url, obj) => {
    return fetch(
        url,
        {
            method: "POST",
            mode: "no-cors",
            headers: {
                "Content-Type": "application/json",
            },
            body: JSON.stringify(obj),
        },
    )
    .then(res => res.json())
    .then(
        (json) => {
            return json;
        }
    ).catch(err => console.log(`fetch error`, err));
  };
  // loop
  // const trs = [...document.querySelector('[class="issue-table"]')?.lastElementChild?.children] ?? [];
  const trs = [...(document.querySelector('[class="issue-table"]') ?? [])]?.lastElementChild?.children ?? [];
  for (const tr of trs) {
    const link = tr?.firstElementChild?.firstElementChild ?? '';
    const text = tr?.firstElementChild?.firstElementChild?.dataset?.issueKey ?? '';
    const obj = {
      msgtype: "markdown",
      markdown: {
        content: `
> 分配给我的问题: \n
[🔖 ${text}](${link})\n
        `,
      },
    };
    if(text && link) {
      fetchPOST(url, obj);
    }
  }
};

wxRobot();

image

@xgqfrms
Copy link
Author

xgqfrms commented Mar 31, 2021

> 引用文字

@xgqfrms
Copy link
Author

xgqfrms commented Mar 31, 2021

trs = [...document.querySelector('[class="issue-table"]')?.lastElementChild?.children] ?? [];
VM133:1 Uncaught TypeError: (intermediate value) is not iterable
    at <anonymous>:1:1
(anonymous) @ VM133:1
...document.querySelector('[class="issue-table"]')
VM146:1 Uncaught SyntaxError: Unexpected token '...'
[...document.querySelector('[class="issue-table"]')]
VM175:1 Uncaught TypeError: document.querySelector is not a function or its return value is not iterable
    at <anonymous>:1:14
(anonymous) @ VM175:1
document.querySelector('[class="issue-table"]')
null
[...(document.querySelector('[class="issue-table"]' ?? [])]
VM201:1 Uncaught SyntaxError: Unexpected token ']'
[...(document.querySelector('[class="issue-table"]' ?? '')]
VM216:1 Uncaught SyntaxError: Unexpected token ']'
[...(document.querySelector('[class="issue-table"]') ?? [])]
[]

image

[...(document.querySelector('[class="issue-table"]') ?? [])]

@xgqfrms
Copy link
Author

xgqfrms commented Mar 31, 2021

[...(document.querySelector('[class="issue-table"]') ?? [])];
// []

[...(document.querySelector('[class="issue-table"]') ?? [])]?.lastElementChild?.children ?? [];
// []

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment