Last active
March 28, 2019 04:22
-
-
Save roshanca/1a5977d7bea3e1fd423cb9ec62534e3a to your computer and use it in GitHub Desktop.
mogu autologin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set MOGU_URL to "https://www.mogujie.com/" | |
set LOGIN_URL to "https://portal.mogujie.com/user/newlogin" | |
global TOGGLE_SELECTOR | |
global USERNAME_SELECTOR | |
global PASSWORD_SELECTOR | |
global LOGIN_BTN_SELECTOR | |
set WELCOME_SELECTOR to "#header > div.wrap.header-wrap.clearfix > div.search-nav-content.clearfix > div.site-top-nav.J_sitenav > div > div.header-user-info.fr" | |
set TOGGLE_SELECTOR to "#qrcode-wrapper > div.toggle-regular" | |
set USERNAME_SELECTOR to "#signform > div > form > div.mod_box.lo_mod_box > div.ui-sign-item.ui-name-item.lg_item.lg_name > input" | |
set PASSWORD_SELECTOR to "#signform > div > form > div.mod_box.lo_mod_box > div.ui-sign-item.ui-sign-common-item.lg_item.lg_pass > input" | |
set LOGIN_BTN_SELECTOR to "#signform > div > form > div.lg_login.clearfix > input" | |
tell application "Finder" | |
display dialog "Login User?" default answer "offline" | |
set myName to text returned of result as text | |
end tell | |
tell application "Google Chrome" | |
activate | |
if (count of windows) is 0 then | |
tell application "System Events" | |
keystroke "n" using {command down} | |
end tell | |
end if | |
set theTitle to title of active tab of front window | |
if theTitle is "New Tab" then | |
set myTab to active tab of front window | |
else | |
set myTab to make new tab at end of tabs of front window | |
end if | |
set URL of myTab to MOGU_URL | |
repeat | |
if (loading of myTab) is false then exit repeat | |
end repeat | |
set notLogin to false | |
if (execute myTab javascript "document.querySelector('" & WELCOME_SELECTOR & "').innerText") is "登录" then set notLogin to true | |
if (notLogin) then | |
tell me to login:LOGIN_URL myTab:myTab myName:myName | |
else | |
set LOGOUT_SELECTOR to "#menu-personal > li:nth-child(3) > a" | |
execute myTab javascript "document.querySelector('" & LOGOUT_SELECTOR & "').click()" | |
tell me to login:LOGIN_URL myTab:myTab myName:myName | |
end if | |
end tell | |
on login:loginUrl myTab:myTab myName:myName | |
tell application "Google Chrome" | |
set URL of myTab to loginUrl | |
repeat | |
if (loading of myTab) is false then exit repeat | |
end repeat | |
execute myTab javascript "document.querySelector('" & TOGGLE_SELECTOR & "').click()" | |
execute myTab javascript "document.querySelector('" & USERNAME_SELECTOR & "').value = '" & myName & "';document.querySelector('" & PASSWORD_SELECTOR & "').value = '123456';document.querySelector('" & LOGIN_BTN_SELECTOR & "').click()" | |
end tell | |
end login:myTab:myName: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment