icode commit

icode code review 脚本

当前为 2020-06-18 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         icode commit
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  icode code review 脚本
// @author       观主
// @match        http://icode.baidu.com/repos/baidu/*/reviews/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function start() {
        var l = document.querySelectorAll('[class^="diff-tree-modify-node-"] .ant-tree-title')
        var index = 0

        function commit() {
            index++
            var lines = Array.from(document.querySelectorAll('.diff-gutter-insert')).reverse()
            console.log(lines.length)
            if(lines.length < 200) {
            for(var i in lines){
                var node = lines[i]
                node.click()
                var textarea = document.querySelector('textarea')
                delete textarea.value;
                textarea.value = 'hao';

                var event = document.createEvent('HTMLEvents');
                event.initEvent('input', true, false);
                textarea.dispatchEvent(event);
                document.querySelector('[class^="comment-box-context-"] textarea + div').querySelector('a:nth-child(4)').click()
            }
                setTimeout(loop, lines.length/8*1e3)
            } else {
                setTimeout(loop, 2*1e3)
            }
        }

        function review() {
            document.querySelector('[class*="score-score-"]').click()
            var a = document.querySelectorAll('[class*="review-score-positive-"]')
            if(a.length) {
                document.querySelectorAll('[class*="review-score-positive-"]')[1].click()
                document.querySelector('button.ant-btn.etui-button-button.etui-button-size-s.etui-button-type-solid.etui-button-theme-primary').click()
            } else {
                document.querySelector('[class*="score-comment-footer-"] .etui-button-type-solid').click()
            }
        }

        function loop() {
            if(index < l.length) {
                l[index].click()
                setTimeout(commit, 800)
            } else {
                setTimeout(review, 5*1e3)
            }
        }

        loop()
    }

    var btn = document.createElement('button')
    btn.id = 'startBtn'
    btn.style.width = '129px'
    btn.style.height = '38px'
    btn.textContent = 'Start'
    btn.style.position = 'fixed'
    btn.style.right = 0
    btn.style.top = '49px'
    btn.onclick = start
    document.body.appendChild(btn)
})();