Github 快捷回复

小白社区开发者实用工具,快速在issue中插入申请开发/变更deadline等操作

As of 14. 09. 2018. See the latest version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Github 快捷回复
// @namespace    http://www.sibbay.ai/
// @version      0.1
// @description  小白社区开发者实用工具,快速在issue中插入申请开发/变更deadline等操作
// @author       github.com/Yidadaa
// @match        https://github.com/sibbay-ai/lt-miniapp-wepy/issues/586
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const buttons = document.getElementById('partial-new-comment-form-actions')
    if (!buttons) return

    // 工具函数
    const $$ = s => Array.from(document.querySelectorAll(s))
    const $ = s => document.querySelector(s)

    // 生成一个结点
    const createNode = (nodeType, content, className, id) => {
        const node = document.createElement(nodeType)
        className ? node.className = className : null
        id ? node.id = id : null
        const contentFn = {
            'string': (node, content) => { node.innerHTML = content },
            'object': (node, content) => { node.appendChild(content) }
        }
        const fn = contentFn[typeof content]
        fn && fn(node, content)
        return node
    }
    // 检查是否已经标记过ddl
    const checkDDL = () => {
        return $$('.timeline-comment-group .edit-comment-hide').some(node => {
            return /申请开发\ deadline/.test(node.innerText)
        })
    }

    // 生成模板
    const generateText = () => {
        const hasDDL = checkDDL()
        const date = new Date()
        const day = date.getDate()
        const month = day <= 15 ? date.getMonth() + 1 : date.getMonth() + 2
        const year = date.getFullYear()
        let text = `申请开发 deadline: ${year}-${month}-15 size: 0.1`
        if (hasDDL) text = `变更 deadline: ${year}-${month}-15`
        return text
    }

    // 生成按钮
    const applyBtn = createNode('div', checkDDL() ? 'Change deadline' : 'Wanna develop', 'btn')
    applyBtn.onclick = () => {
        const textarea = document.getElementById('new_comment_field')
        textarea.value += `${textarea.value && '\n'}` + generateText()
    }
    buttons.appendChild(applyBtn)
})();