前言
因为经常需要在阿里云上部署云函数,正好前段时间学习了下王一之大佬编写的油猴脚本开发,所以想试试能不能写出个自动化的脚本来提高效率,但目前卡在了自动登录上,麻烦大佬指点迷津
问题
需要在阿里云首页点击登录,但随之会跳转到登录页面,然后脚本就熄火报错了,这里可以怎么解决呢
// ==UserScript==
// @name 云函数
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://cn.aliyun.com/
// @match https://www.aliyun.com/
// @match https://account.aliyun.com/login/login.htm?*
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAAEM5JREFUeF7tnQ2QJVV1x3/nDVJgLA2kBEXAUPEDC0Vld4EFC5dIKR8CggYtLWCp4LLTbxYBxUpiTNZIUsEKstbu6zdscINAPhQKEFRQNK4Rv6gZBBEjkFCEEjAYCIVGWGDfSXXPm2FmZ2bnvX739b19+3TV1MzW9j3nf37n/d/tfn27n2CbETACixIQY2MEjMDiBMwg9uowAjshYAaxl4cRMIPYa8AIFCNgM0gxbjaqJgTMIDVptJVZjIAZpBg3G1UTAmaQmjTayixGwAxSjJuNqgkBM0hNGm1lFiNgBinGzUbVhIAZpCaNtjKLETCDFONmo2pCwAxSk0ZbmcUImEGKcbNRNSFgBqlJo63MYgTMIMW42aiaEDCD1KTRVmYxAmaQYtxsVE0ImEFq0mgrsxgBM0gxbjaqJgTMIDVptJVZjIAZpBg3G1UTAmaQmjTayixGwAxSjJuNqgkBM0hNGm1lFiNgBinGzUbVhIAZpCaNtjKLETCDFONmo2pCwAxSk0ZbmcUImEGKcbNRNSFgBqlJo63MYgTMIMW42aiaEDCD1KTRVmYxAmaQYtxsVE0ImEFq0mgrsxiB0gyiH2FvtvFqGuwPvBq6v5WXFZMe8CjhUUn5YJkKdZS/Rzi7zJxDzPUc8Hj+ozyBdP/O/i38mBdxi2zgySHmnwk9VIPoWlbR4I8g/3l5GQUFkUP5qLT5bJlaNGEM2Fh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psgeMUlElJ83svSt8CeIxs6TUvkjA7xE3Zi3aRWWPu+52jknRqqXw2xdv9JNtZIZe9sGTaEeKdhtG1HEmj5otMlYdokNKgLRt5ygX3gWeQHUVokl9NPgZ4R+Wfi1SUsDIm7XLPBTThI8CGopIrPC570Ea2Bu77dEhlnMdc1uLcILPFdR8zmd24cyzCu1wKDzqWcpW0OaNMjZpwNfChMnN6zHVP/vxm+A7C96VFtlR9KNtQDbLA7LIfHfZnhP1Q9oeZ3/F96+12Tihr+Xv+iE8P3983lFdkFlTyb7N9AuEJNP95fObvXbhbNvKLoeXeIXCpBimrKMtjBFwRMIO4ImlxoiRgBomyrVaUKwJmEFckLU6UBMwgUbbVinJFwAziiqTFiZKAGSTKtlpRrgiYQVyRtDhREjCDRNlWK8oVATOIK5IWJ0oCZpAo22pFuSJgBnFF0uJEScAMEmVbrShXBMwgrkhanCgJmEGibKsV5YqAGcQVSYsTJQEzSJRttaJcETCDuCJpcaIkYAaJsq1WlCsCZhBXJC1OlATMIFG21YpyRcAM4oqkxYmSgBkkyrZaUa4ImEFckbQ4URIwg0TZVivKFQEziCuSFidKAmaQKNtqRbkiYAZxRdLiREnADBJlW60oVwTMIK5IWpwoCZhBomyrFeWKgBnEFUmLEyUBM0iUbbWiXBEwg7giaXGiJGAGibKtVpQrAmYQVyQtTpQEzCBRttWKckXg/wEK7+5cz9465wAAAABJRU5ErkJggg==
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Your code here...
// 检查类名的唯一性 可在consonle下执行document.querySelectorAll(".类名")
// 检查登录状态 未登录就执行登录代码
if(document.querySelector(".header-compatible")) {
// 模拟点击搜索框
document.querySelector(".aliyun-icon-search").click();
// 自动输入搜索内容
var input = document.querySelector(".default-input");
input.value = "云函数";
// 点击搜索
document.querySelector(".aliyun-common-search-button").click();
} else {
// 模拟点击登录
document.querySelector(".aliyun-register").click();
// 自动填写表单
document.getElementById("fm-login-id").value = "username";
document.getElementById("fm-login-password").value = "password";
document.querySelector(".password-login").click();
};
})();
看报错我知道了问题,但不知道咋解决,请大佬帮帮忙,指点一二,谢谢