You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

content.js 1.0 KiB

8 vuotta sitten
1234567891011121314151617181920212223242526272829303132333435363738
  1. import {getLoginForm, getFormInfo} from './form-parser';
  2. function _isThereALoginForm(formInfo) {
  3. return formInfo.passwordField !== null;
  4. }
  5. function fillFormFields(formInfo, data) {
  6. const event = new Event('input');
  7. formInfo.passwordField.value = data.password;
  8. formInfo.passwordField.dispatchEvent(event);
  9. if (formInfo.loginField !== null) {
  10. formInfo.loginField.value = data.login;
  11. formInfo.loginField.dispatchEvent(event);
  12. }
  13. }
  14. chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  15. const loginForm = getLoginForm(window.document);
  16. if (loginForm !== null) {
  17. const formInfo = getFormInfo(loginForm);
  18. if (message.type === 'isThereALoginForm') {
  19. return sendResponse({isThereALoginForm: _isThereALoginForm(formInfo)});
  20. }
  21. if (message.type === 'submitForm') {
  22. const data = {password: message.password, login: message.login};
  23. fillFormFields(formInfo, data);
  24. if (formInfo.button === null) {
  25. loginForm.submit();
  26. } else {
  27. formInfo.button.click();
  28. }
  29. }
  30. }
  31. });