discord-jadx/app/src/main/assets/hcaptcha-form.html
2021-08-03 09:33:18 +02:00

162 lines
5.2 KiB
HTML

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
<style>
* {
padding: 0;
margin: 0;
}
body {
display: table;
width: 100%;
height: 100%;
text-align: center;
}
#hcaptcha-container {
margin-top: 5px;
display: table-cell;
vertical-align: middle;
}
/* overwrite hCaptcha iframe overlay which adds a #FFF background with opacity 0.05 */
div > div:nth-child(2) {
opacity: 0 !important;
}
</style>
</head>
<body>
<div id="hcaptcha-container"></div>
<script type="text/javascript">
// Android will inject this bridge object as `JSInterface`
// Browser is missing it so we mock it
var BridgeObject = window.JSInterface || {
getConfig: function getConfig() {
return JSON.stringify({
siteKey: '10000000-ffff-ffff-ffff-000000000001',
locale: 'ro',
size: 'compact',
theme: 'dark',
sentry: true,
rqdata: null,
apiEndpoint: 'https://hcaptcha.com/1/api.js',
endpoint: null,
assethost: null,
imghost: null,
reportapi: null
});
},
onPass: function onPass(token) {
return console.log("pass: token ".concat(token));
},
onError: function onError(errCode) {
return console.log("error: code ".concat(errCode));
},
onLoaded: function onLoaded() {
return console.log('cb: challenge or checkbox is visible');
}
};
var bridgeConfig = JSON.parse(BridgeObject.getConfig());
function getRenderConfig() {
return {
sitekey: bridgeConfig.siteKey,
size: bridgeConfig.size,
theme: bridgeConfig.theme,
'callback': function callback(token) {
return BridgeObject.onPass(token);
},
'expired-callback': function expiredCallback() {
return BridgeObject.onError(15);
},
'chalexpired-callback': function chalexpiredCallback() {
return BridgeObject.onError(15);
},
'close-callback': function closeCallback() {
return BridgeObject.onError(30);
},
'error-callback': function errorCallback() {
return BridgeObject.onError(31);
},
'open-callback': function openCallback() {
return BridgeObject.onLoaded();
}
};
}
function onHcaptchaLoaded() {
try {
var renderConfig = getRenderConfig();
var rqdata = bridgeConfig.rqdata;
var hCaptchaID = hcaptcha.render('hcaptcha-container', renderConfig);
if (rqdata) {
hcaptcha.setData(hCaptchaID, {
rqdata: rqdata
});
}
if (renderConfig.size === 'invisible') {
hcaptcha.execute(hCaptchaID);
} else {
BridgeObject.onLoaded();
}
} catch (e) {
console.error(e);
BridgeObject.onError(29);
}
}
function addQueryParamIfDefined(url, queryName, queryValue) {
if (queryValue !== undefined && queryValue !== null) {
var link = url.indexOf('?') !== -1 ? '&' : '?';
return url + link + queryName + '=' + encodeURIComponent(queryValue);
}
return url;
}
function loadApi() {
var siteKey = bridgeConfig.siteKey;
var locale = bridgeConfig.locale;
var sentry = bridgeConfig.sentry;
var apiEndpoint = bridgeConfig.apiEndpoint;
var endpoint = bridgeConfig.endpoint;
var assethost = bridgeConfig.assethost;
var imghost = bridgeConfig.imghost;
var reportapi = bridgeConfig.reportapi;
var host = siteKey + '.android-sdk.hcaptcha.com';
var scriptSrc = apiEndpoint + '?render=explicit&onload=' + onHcaptchaLoaded.name;
scriptSrc = addQueryParamIfDefined(scriptSrc, 'recaptchacompat', 'off');
scriptSrc = addQueryParamIfDefined(scriptSrc, 'hl', locale);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'host', host);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'sentry', sentry);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'endpoint', endpoint);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'assethost', assethost);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'imghost', imghost);
scriptSrc = addQueryParamIfDefined(scriptSrc, 'reportapi', reportapi);
var script = document.createElement('script');
script.async = true;
script.src = scriptSrc;
script.onerror = function () {
// network issue
BridgeObject.onError(7);
};
document.head.appendChild(script);
}
document.body.onclick = function () {
if (window.hcaptcha) {
window.hcaptcha.close();
} else {
BridgeObject.onError(30);
}
};
loadApi();
</script>
</body>
</html>