chrome 脚本学习

# 编写可复用的代码段(snippet)教程
https://jingyan.baidu.com/article/67508eb423d2929ccb1ce45b.html

# chrome 脚本开发手册
https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference

 

 

常用的api

 

1、$() === document.querySelector() 

$('j_username').value='admin';

 

2、$$() === document.querySelectorAll()

$$('[name="j_password"]')[0].value='admin';

 

3、$x()  xpath选择器

 

 

$x('//*[@id="ecp_app_1"]/td/input')[0].setAttribute('checked', true);

 

实战:

// 如果没有登录的话,跳转到登录界面
if ($x('//*[@id="header"]/div[2]/span/a[1]/b')[0] === false && $x('//*[@id="header"]/div[2]/span/a[1]/b')[0].innerText != "管理员") {
    window.location.href = 'http://172.16.200.111:8080/login'
// 如果当前在登录界面的话,输入账号密码然后点击登录
} else if (window.location.href.indexOf('login') >= 0) {
    $('j_username').value='admin';
    $$('[name="j_password"]')[0].value='admin';
    $('yui-gen1-button').click()
// 如果现在正在编译界面的话,那么进行编译
} else if (window.location.href.indexOf('/wx-deploy/build') >= 0) {
    $x('//*[@id="main-panel"]/form/table/tbody[1]/tr[1]/td[3]/div/select')[0].value = 'sit';
    $x('//*[@id="ecp_app_1"]/td/input')[0].setAttribute('checked', true);
    $('yui-gen3-button').click();
// 如果现在在别的界面的话,那么进入编译界面
} else {
    window.location.href = '/job/wx-deploy/build?delay=0sec'
}

 

 

 

 

 

posted @ 2018-04-01 10:14  贝尔塔猫  阅读(349)  评论(0编辑  收藏  举报