自动登录chrome扩展

时间:2018-03-12 20:27:30

标签: javascript html css google-chrome-extension login

我一直在尝试学习一些javaScript,并且我正在尝试自动登录到我的学生网站,编写一个简单的chrome扩展。它似乎不起作用,你知道我错了吗? TY !!

<script>
            if (window.location.host =="MY_STUDENTS_HOST_SITE"){
                var button = document.getElementsByClassName("loginurl")
                button[0].click();
            }
            if (window.location.host == "MY_STUDENTS_LOGIN_HOST_SITE"){
                var username = document.getElementById("username")
                var password = document.getElementById("password")
                username.write("MY_USERNAME")
                password.write("MY_PASSWORD")
                var button = document.getElementsById("loginbutton")
                button.click();
            }
        </script>

1 个答案:

答案 0 :(得分:1)

要“写”用户名和密码,您可以使用value属性。您可以像这样更改<input>元素的值(我假设usernamepassword元素是输入):

var username = document.getElementById("username");
var password = document.getElementById("password");
username.value = "MY_USERNAME";
password.value = "MY_PASSWORD";