options.js 960 B

12345678910111213141516171819202122232425262728293031
  1. const serverUrl = 'http://127.0.0.1:8005'
  2. // 登录按钮点击
  3. document.getElementsByClassName('login-button')[0].onclick = function () {
  4. const username = document.getElementById('username').value
  5. const password = document.getElementById('password').value
  6. if (!username || !password) {
  7. chrome.notifications.create(null, {
  8. type: 'basic',
  9. iconUrl: 'img/48.png',
  10. title: '运行方案',
  11. message: '用户名或密码不能为空!'
  12. })
  13. return
  14. }
  15. fetch(`${serverUrl}/login?username=${username}&password=${password}`).then(data => data.json()).then(data => {
  16. if (data.err === 0) {
  17. localStorage.setItem('userInfo', JSON.stringify({
  18. gold: data.data.gold,
  19. userName: username,
  20. password: password
  21. }))
  22. } else {
  23. chrome.notifications.create(null, {
  24. type: 'basic',
  25. iconUrl: 'img/48.png',
  26. title: '运行方案',
  27. message: data.message
  28. })
  29. }
  30. })
  31. }