一个码云自动代码检视的插件,当然用httpclient也能做
插件整体结构
打开chrome的开发者模式即可使用
manifest.json
插件的基本定义
{
"background": {
"page": "background.html"
},
// 需要注入的脚本
"content_scripts": [ {
"all_frames": true,
"js": [ "chrome-state-manager.js" ],
"matches": [ "http://mayun.kkkkkkk.cn/**/commits/master", "http://mayun.kkkkkkkk.cn/LS_JCYW_TEAM1/**/commit/**" ],
"run_at": "document_end"
} ],
"description": "码云自动commit",
// 插件图标
"icons": {
"128": "axurerp-128.png",
"48": "axurerp-48.png"
},
"manifest_version": 2,
"name": "my plugin Extension for Chrome",
"page_action": {
"default_icon": "axurerp-16.png"
},
// 需要进行跨域访问的地址
"permissions": [ "tabs" ],
// 插件更新地址
"update_url": "https://clients2.google.com/service/update2/crx",
"version": "0.0.1"
}
background.html
<html>
<head>
<script type="text/javascript"></script>
</head>
<body></body>
</html>
chrome-state-manager.js
具体的逻辑
(function() {
// commit列表页
var regex1 = new RegExp('.*/LS_JCYW_TEAM1/.*commits/master');
// 审批详情页
var regex2 = new RegExp('.*/LS_JCYW_TEAM1/.*commit/.*');
function init() {
var url = window.location.href;
// 审批列表页
if (regex1.test(url)){
// 所有没有审批的提交
var greyElemnts = document.getElementsByClassName('grey');
if (greyElemnts.length > 0) {
// 获取父级div
var commitDivParent = greyElemnts[0].parentNode;
// 跳转审批详情页的a标签
var aTag = commitDivParent.getElementsByClassName("commit_short_id")[0];
// 触发点击事件
aTag.click();
}
// 审批详情页,并且页面是未审批状态
} else if (regex2.test(url) && document.getElementsByClassName('grey').length > 0) {
// 审批通过按钮
var _btn = document.getElementById('codereview_complete');
// 去掉disabled样式。这里原来是 class = "...... disabled",并不是<button class="...." disabled="true"/>
_btn.classList.remove('disabled');
// 触发点击事件
_btn.click();
// 返回上一页并刷新
window.location.href=document.referrer;
}
}
// var interval1 = setInterval(init, 1000)
init();
})();
网友评论