Skip to content

Instantly share code, notes, and snippets.

@eugenesimakin
Last active June 28, 2022 15:35
Show Gist options
  • Select an option

  • Save eugenesimakin/029ecf0d448b524eade2a31c09dcbf5c to your computer and use it in GitHub Desktop.

Select an option

Save eugenesimakin/029ecf0d448b524eade2a31c09dcbf5c to your computer and use it in GitHub Desktop.

manifest.json

{
  "name": "Insert the first part of the PIN and check 'I have read...' checkbox",
  "version": "1.0",
  "manifest_version": 3,
  "action": {},
  "content_scripts": [
    {
      "matches": ["https://apps-idp.novartis.com/*"],
      "all_frames": true,
      "js": ["content-script.js"]
    }
  ]
}

content-script.js

const PIN = '<your pin>';

const loadingElem = document.querySelector('#loading-screen');
if (!loadingElem) {
	console.warn('loading div is not found');
} else {
	const mConfig = {
		attributesList: ["style"],
		attributeOldValue: true,
	}

	const mCallback = (mutationList, observer) => {
		const mutationRecord = mutationList.pop();
		if (mutationRecord.attributeName === 'style') {
			const target = mutationRecord.target;
			if (target.style.display === 'none') {
				doStuff();
			}
		}
	}

	const observer = new MutationObserver(mCallback);
	observer.observe(loadingElem, mConfig);
}

const doStuff = () => {
	const checkboxInput = document.querySelector('#eula-accept');
	if (checkboxInput) {
		checkboxInput.click();
	} else {
		console.error('The checkbox is not found on the page');
	}
	const psswdInput = document.querySelector('#passwd');
	if (psswdInput) {
		psswdInput.value = PIN;
		psswdInput.focus();
	} else {
		console.error('The password input is not found');
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment