百度 icode 自动+1

百度内部 icode 自动+1 code review 脚本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         百度 icode 自动+1
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  百度内部 icode 自动+1 code review 脚本
// @author       观主
// @match        http://icode.baidu.com/repos/baidu/*/reviews/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function start() {
        var l = document.querySelectorAll('[class^="file-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 < 100) {
            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)
})();