Skip to content

Instantly share code, notes, and snippets.

@saade
Last active July 4, 2024 14:52
Show Gist options
  • Save saade/9b59ecd3c1dedcb1cea6f951d4a48c4a to your computer and use it in GitHub Desktop.
Save saade/9b59ecd3c1dedcb1cea6f951d4a48c4a to your computer and use it in GitHub Desktop.
Webview scripts
const observer = new MutationObserver(async () => {
if (window.location.pathname !== '/form') return;
const user = await window.flutter_inappwebview.callHandler("user");
if (!user) {
alert("Você não está logado.");
}
function getReactProps (el) {
return el[
Object.keys(el).find(key => key.includes('reactProps'))
];
}
if (document.querySelector('[data-testid="FNAME"]')) {
const FNAME = document.querySelector('[data-testid="FNAME"]');
getReactProps(FNAME).onChange({ target: { value: user.name } });
FNAME.setAttribute('readonly', true);
await new Promise(r => setTimeout(r, 100));
}
if (document.querySelector('[data-testid="EMAIL"]')) {
const EMAIL = document.querySelector('[data-testid="EMAIL"]');
getReactProps(EMAIL).onChange({ target: { value: user.email } });
EMAIL.setAttribute('readonly', true);
await new Promise(r => setTimeout(r, 100));
}
});
observer.observe(document.body, {
subtree: true,
childList: true,
});
(async function () {
if (window.location.pathname !== "/app/pages/login") {
return;
}
const user = await window.flutter_inappwebview.callHandler("user");
const webviewData = await window.flutter_inappwebview.callHandler("webviewData");
if (!user) {
alert("Você não está logado.");
}
const formData = new FormData();
formData.append("username", user.cpf.replace(/\D/g, ""));
formData.append("password", "");
fetch("https://web.votuporanga.sp.gov.br/api/auth/login?modulo=GovDigital", {
method: "POST",
headers: { "Authorization": "Bearer " + webviewData.token },
body: formData
})
.then(async (response) => {
const data = await response.json();
if (!data.token) {
return;
}
window.location.href = '/app/pages/debitos?access_token=' + data.token;
})
.catch(() => {
alert("Login automático falhou. Por favor, faça login manualmente.")
});
})()
const observer = new MutationObserver(async () => {
if (window.location.pathname !== '/form') return;
const user = await window.flutter_inappwebview.callHandler("user");
if (!user) {
alert("Você não está logado.");
}
function getReactProps (el) {
return el[
Object.keys(el).find(key => key.includes('reactProps'))
];
}
if (document.querySelector('[data-testid="Q7"]')) {
const Q7 = document.querySelector('[data-testid="Q7"]');
getReactProps(Q7).onChange({ target: { value: user.integrationId } });
Q7.setAttribute('readonly', true);
await new Promise(r => setTimeout(r, 100));
}
if (document.querySelector('[data-testid="FNAME"]')) {
const FNAME = document.querySelector('[data-testid="FNAME"]');
getReactProps(FNAME).onChange({ target: { value: user.name } });
FNAME.setAttribute('readonly', true);
await new Promise(r => setTimeout(r, 100));
}
if (document.querySelector('[data-testid="EMAIL"]')) {
const EMAIL = document.querySelector('[data-testid="EMAIL"]');
getReactProps(EMAIL).onChange({ target: { value: user.email } });
EMAIL.setAttribute('readonly', true);
await new Promise(r => setTimeout(r, 100));
}
});
observer.observe(document.body, {
subtree: true,
childList: true,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment