Update content of files

This commit is contained in:
GitHub Action 2022-04-07 01:58:58 +00:00
parent 94b0e96bec
commit 1d71e3b8e9
28 changed files with 38 additions and 896 deletions

View file

@ -1,281 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="format-detection" content="telephone=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="MobileOptimized" content="176" />
<meta name="HandheldFriendly" content="True" />
<meta name="robots" content="noindex,nofollow" />
<script src="https://telegram.org/js/telegram-webview.js?9"></script>
<script>
function setThemeClass() {
document.documentElement.className = document.documentElement.style.getPropertyValue('--tg-theme-color-scheme');
}
Telegram.WebView.onEvent('theme_changed', setThemeClass);
setThemeClass();
</script>
<style>
body {
font-family: sans-serif;
background-color: var(--tg-theme-bg-color, #ffffff);
color: var(--tg-theme-text-color, #222222);
font-size: 16px;
margin: 0;
padding: 0;
color-scheme: var(--tg-theme-color-scheme);
}
a {
color: var(--tg-theme-link-color, #2678b6);
}
button {
display: block;
width: 100%;
font-size: 14px;
margin: 15px 0;
padding: 12px 20px;
border: none;
border-radius: 4px;
background-color: var(--tg-theme-button-color, #50a8eb);
color: var(--tg-theme-button-text-color, #ffffff);
cursor: pointer;
}
button[disabled] {
opacity: 0.6;
cursor: auto;
pointer-events: none;
}
button.close_btn {
/*position: fixed;*/
position: absolute;
left: 0;
right: 0;
bottom: 0;
border-radius: 0;
margin: 0;
padding: 16px 20px;
text-transform: uppercase;
}
section {
padding: 15px 15px 65px;
text-align: center;
}
p {
margin: 40px 0 15px;
}
ul {
text-align: left;
}
li {
color: var(--tg-theme-hint-color, #a8a8a8);
}
textarea {
width: 100%;
box-sizing: border-box;
padding: 7px;
}
pre {
background: rgba(0, 0, 0, .07);
border-radius: 4px;
padding: 4px;
margin: 7px 0;
word-break: break-all;
word-break: break-word;
white-space: pre-wrap;
text-align: left;
}
.dark pre {
background: rgba(255, 255, 255, .15);
}
.hint {
font-size: .8em;
color: var(--tg-theme-hint-color, #a8a8a8);
}
.ok {
color: green;
}
.err {
color: red;
}
#fixed_wrap {
position: fixed;
left: 0;
right: 0;
top: 0;
transform: translateY(100vh);
}
</style>
</head>
<body style="visibility: hidden;">
<section>
<button id="main_btn" onclick="sendMessage('');">Send «Hello, World!»</button>
<button id="with_webview_btn" onclick="sendMessage('', true);">Send «Hello, World!» with inline webview button</button>
<button id="data_btn" onclick="sendTime(true);">Send current time to bot (x10)</button>
<button onclick="webviewExpand();">Expand Webview</button>
<div id="btn_status" class="hint" style="display: none;">
</div>
<p>Test links:</p>
<ul>
<li><a id="regular_link" href="?nextpage=1">Regular link #1</a> (opens inside webview)</li>
<li><a href="https://telegram.org/" target="_blank">target="_blank" link</a> (opens outside webview)</li>
<li><a href="javascript:window.open('https://telegram.org/');">window.open() link</a> (opens outside webview)</li>
<li><a href="https://t.me/like">LikeBot t.me link</a> (opens inside Telegram app)</li>
<li><a href="tg://resolve?domain=vote">VoteBot tg:// link</a> (does not open)</li>
</ul>
<p>Test permissions:</p>
<ul>
<li><a href="javascript:;" onclick="return requestLocation(this);">Request Location</a> <span></span></li>
<li><a href="javascript:;" onclick="return requestVideo(this);">Request Video</a> <span></span></li>
<li><a href="javascript:;" onclick="return requestAudio(this);">Request Audio</a> <span></span></li>
</ul>
<pre><code id="webview_data"></code></pre>
<div class="hint">
Data passed to webview.
<span id="webview_data_status" style="display: none;">Checking hash...</span>
</div>
</section>
<script src="/js/jquery.min.js"></script>
<script>
var WebAppData = Telegram.WebApp.initData || {};
var WebAppDataRaw = Telegram.WebApp.initDataRaw || '';
function sendMessage(msg_id, with_webview) {
if (!WebAppData.query_id) {
alert('WebViewQueryId not defined');
return;
}
$('button').prop('disabled', true);
$('#btn_status').text('Sending...').removeClass('ok err').show();
$.ajax('/test_webview/sendMessage', {
type: 'POST',
data: {query_id: WebAppData.query_id, msg_id: msg_id || '', with_webview: !WebAppData.receiver && with_webview ? 1 : 0},
dataType: 'json',
success: function(result) {
$('button').prop('disabled', false);
if (result.response) {
if (result.response.ok) {
$('#btn_status').html('Message sent successfully!').addClass('ok').show();
} else {
$('#btn_status').text(result.response.description).addClass('err').show();
alert(result.response.description);
}
} else {
$('#btn_status').text('Unknown error').addClass('err').show();
alert('Unknown error');
}
},
error: function(xhr) {
$('button').prop('disabled', false);
$('#btn_status').text('Server error').addClass('err').show();
alert('Server error');
}
});
}
function byteLength(str) {
if (window.Blob) {
try { return new Blob([str]).size; } catch (e) {}
}
var s = str.length;
for (var i=str.length-1; i>=0; i--) {
var code = str.charCodeAt(i);
if (code > 0x7f && code <= 0x7ff) s++;
else if (code > 0x7ff && code <= 0xffff) s+=2;
if (code >= 0xDC00 && code <= 0xDFFF) i--;
}
return s;
}
function sendText(spam) {
var text = $('#text_field').val();
if (!text.length) {
return $('#text_field').focus();
}
if (byteLength(text) > 4096) {
return alert('Text is too long');
}
var repeat = spam ? 10 : 1;
for (var i = 0; i < repeat; i++) {
Telegram.WebApp.sendData(text);
}
}
function sendTime(spam) {
var repeat = spam ? 10 : 1;
for (var i = 0; i < repeat; i++) {
Telegram.WebApp.sendData(new Date().toString());
}
}
function webviewExpand() {
Telegram.WebApp.expand();
}
function webviewClose() {
Telegram.WebApp.close();
}
function requestLocation(el) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
$(el).next('span').html('(' + position.coords.latitude + ', ' + position.coords.longitude + ')').attr('class', 'ok');
});
} else {
$(el).next('span').html('Geolocation is not supported in this browser.').attr('class', 'err');
}
return false;
}
function requestVideo(el) {
if (navigator.mediaDevices) {
navigator.mediaDevices.getUserMedia({ audio: false, video: true }).then(function(stream) {
$(el).next('span').html('(Access granted)').attr('class', 'ok');
});
} else {
$(el).next('span').html('Media devices is not supported in this browser.').attr('class', 'err');
}
return false;
}
function requestAudio(el) {
if (navigator.mediaDevices) {
navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then(function(stream) {
$(el).next('span').html('(Access granted)').attr('class', 'ok');
});
} else {
$(el).next('span').html('Media devices is not supported in this browser.').attr('class', 'err');
}
return false;
}
$('#main_btn').toggle(!!WebAppData.query_id);
$('#with_webview_btn').toggle(!!WebAppData.query_id && !WebAppData.receiver);
// $('#data_btn').toggle(!WebAppData.query_id || !WebAppData.receiver);
$('#webview_data').html(JSON.stringify(WebAppData, null, 2));
$('#regular_link').attr('href', $('#regular_link').attr('href') + location.hash);
$('#text_field').focus();
if (WebAppData.query_id && WebAppDataRaw) {
$('#webview_data_status').show();
$.ajax('/test_webview/checkData', {
type: 'POST',
data: {data: WebAppDataRaw},
dataType: 'json',
success: function(result) {
if (result.ok) {
$('#webview_data_status').html('Hash is correct').addClass('ok');
} else {
$('#webview_data_status').html(result.error).addClass('err');
}
},
error: function(xhr) {
$('#webview_data_status').html('Server error').addClass('err');
}
});
}
$('body').css('visibility', '');
Telegram.WebApp.MainButton
.setText('CLOSE WEBVIEW')
.show()
.onClick(function(){ webviewClose(); });
</script>
</body>
</html>

View file

@ -198,9 +198,9 @@
<script src="/js/main-aj.js?57"></script>
<script src="/js/contest.js?25"></script>
<script src="/js/jquery-ui.min.js?1"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>ajInit({"version":386,"apiUrl":"\/api?hash=telegram-crawler","unauth":true});</script>
<script>ajInit({"version":387,"apiUrl":"\/api?hash=telegram-crawler","unauth":true});</script>
<script id="aj_script">Aj._useScrollHack=true;
Aj.onLoad(function(state) {
function requestConfirmation(event) {

View file

@ -271,7 +271,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitRetinaVideos();
mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":3,"unsupportedURL":"\/?notgs=1"});

View file

@ -271,7 +271,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitRetinaVideos();
mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":3,"unsupportedURL":"\/?notgs=1"});

View file

@ -288,7 +288,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -285,7 +285,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -283,7 +283,7 @@ This way you can quickly see how to [start a Secret Chat](/) on iOS or show one
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -298,7 +298,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -247,7 +247,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -250,7 +250,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -271,7 +271,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -270,7 +270,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -305,7 +305,7 @@ you can also download our Android app directly from [telegram.org](https://teleg
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -268,7 +268,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -264,7 +264,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -301,7 +301,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -310,7 +310,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -286,7 +286,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -329,7 +329,7 @@ TEST
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -340,7 +340,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -220,7 +220,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -259,7 +259,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -261,7 +261,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -297,7 +297,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":4});
initScrollVideos(true);

View file

@ -1,580 +0,0 @@
(function () {
var eventHandlers = {};
// Parse init params from location hash: for Android < 5.0, TDesktop
var locationHash = '';
try {
locationHash = location.hash.toString();
} catch (e) {}
var initParams = urlParseHashParams(locationHash);
var webAppDataRaw = '', webAppData = {};
if (initParams.tgWebAppData && initParams.tgWebAppData.length) {
webAppDataRaw = initParams.tgWebAppData;
webAppData = urlParseHashParams(webAppDataRaw);
delete webAppData._path;
for (var key in webAppData) {
var val = webAppData[key];
try {
if (val.substr(0, 1) == '{' && val.substr(-1) == '}' ||
val.substr(0, 1) == '[' && val.substr(-1) == ']') {
webAppData[key] = JSON.parse(val);
}
} catch (e) {}
}
}
var isIframe = false;
try {
isIframe = (window.parent != null && window != window.parent);
if (isIframe) {
window.addEventListener('message', function (event) {
if (event.source !== window.parent) return;
try {
var dataParsed = JSON.parse(event.data);
} catch (e) {
return;
}
if (!dataParsed || !dataParsed.eventType) {
return;
}
receiveEvent(dataParsed.eventType, dataParsed.eventData);
});
}
} catch (e) {}
function onThemeChanged(eventType, eventData) {
if (eventData.theme_params) {
setThemeParams(eventData.theme_params);
window.Telegram.WebApp.MainButton.setParams({});
}
}
document.write('<style>#tg-fixed-container{position:fixed;left:0;right:0;top:0;transform:translateY(100vh)}</style>');
function onViewportChanged(eventType, eventData) {
var el = document.getElementById('tg-fixed-container');
if (el && eventData.height) {
el.style.transform = 'translateY(' + eventData.height + 'px)';
}
}
function urlSafeDecode(urlencoded) {
try {
urlencoded = urlencoded.replace(/\+/g, '%20');
return decodeURIComponent(urlencoded);
} catch (e) {
return urlencoded;
}
}
function urlParseHashParams(locationHash) {
locationHash = locationHash.replace(/^#/, '');
var params = {};
if (!locationHash.length) {
return params;
}
if (locationHash.indexOf('=') < 0 && locationHash.indexOf('?') < 0) {
params._path = urlSafeDecode(locationHash);
return params;
}
var qIndex = locationHash.indexOf('?');
if (qIndex >= 0) {
var pathParam = locationHash.substr(0, qIndex);
params._path = urlSafeDecode(pathParam);
locationHash = locationHash.substr(qIndex + 1);
}
var locationHashParams = locationHash.split('&');
var i, param, paramName, paramValue;
for (i = 0; i < locationHashParams.length; i++) {
param = locationHashParams[i].split('=');
paramName = urlSafeDecode(param[0]);
paramValue = param[1] == null ? null : urlSafeDecode(param[1]);
params[paramName] = paramValue;
}
return params;
}
// Telegram apps will implement this logic to add service params (e.g. tgShareScoreUrl) to game URL
function urlAppendHashParams(url, addHash) {
// url looks like 'https://game.com/path?query=1#hash'
// addHash looks like 'tgShareScoreUrl=' + encodeURIComponent('tgb://share_game_score?hash=telegram-crawler_long_hash123')
var ind = url.indexOf('#');
if (ind < 0) {
// https://game.com/path -> https://game.com/path#tgShareScoreUrl=etc
return url + '#' + addHash;
}
var curHash = url.substr(ind + 1);
if (curHash.indexOf('=') >= 0 || curHash.indexOf('?') >= 0) {
// https://game.com/#hash=1 -> https://game.com/#hash=1&tgShareScoreUrl=etc
// https://game.com/#path?query -> https://game.com/#path?query&tgShareScoreUrl=etc
return url + '&' + addHash;
}
// https://game.com/#hash -> https://game.com/#hash?tgShareScoreUrl=etc
if (curHash.length > 0) {
return url + '?' + addHash;
}
// https://game.com/# -> https://game.com/#tgShareScoreUrl=etc
return url + addHash;
}
function postEvent(eventType, callback, eventData) {
if (!callback) {
callback = function () {};
}
if (eventData === undefined) {
eventData = '';
}
if (window.TelegramWebviewProxy !== undefined) {
TelegramWebviewProxy.postEvent(eventType, JSON.stringify(eventData));
console.log('[Telegram.WebView] postEvent via TelegramWebviewProxy', eventType, eventData);
callback();
}
else if (window.external && 'notify' in window.external) {
window.external.notify(JSON.stringify({eventType: eventType, eventData: eventData}));
console.log('[Telegram.WebView] postEvent via external.notify', eventType, eventData);
callback();
}
else if (isIframe) {
try {
var trustedTarget = 'https://web.telegram.org';
// For now we don't restrict target, for testing purposes
trustedTarget = '*';
window.parent.postMessage(JSON.stringify({eventType: eventType, eventData: eventData}), trustedTarget);
console.log('[Telegram.WebView] postEvent via postMessage', eventType, eventData);
callback();
} catch (e) {
callback(e);
}
}
else {
console.log('[Telegram.WebView] postEvent', eventType, eventData);
callback({notAvailable: true});
}
};
function receiveEvent(eventType, eventData) {
console.log('[Telegram.WebView] receiveEvent', eventType, eventData);
var curEventHandlers = eventHandlers[eventType];
if (curEventHandlers === undefined ||
!curEventHandlers.length) {
return;
}
for (var i = 0; i < curEventHandlers.length; i++) {
try {
curEventHandlers[i](eventType, eventData);
} catch (e) {}
}
}
function onEvent(eventType, callback) {
if (eventHandlers[eventType] === undefined) {
eventHandlers[eventType] = [];
}
var index = eventHandlers[eventType].indexOf(callback);
if (index === -1) {
eventHandlers[eventType].push(callback);
}
};
function offEvent(eventType, callback) {
if (eventHandlers[eventType] === undefined) {
return;
}
var index = eventHandlers[eventType].indexOf(callback);
if (index === -1) {
return;
}
eventHandlers[eventType].splice(index, 1);
};
var themeParams = {};
function setThemeParams(theme_params) {
var root = document.documentElement, color;
if (root && root.style && root.style.setProperty) {
for (var key in theme_params) {
if (color = parseColorToHex(theme_params[key])) {
themeParams[key] = color;
if (key == 'bg_color') {
var color_scheme = isColorDark(color) ? 'dark' : 'light'
themeParams.color_scheme = color_scheme;
root.style.setProperty('--tg-theme-color-scheme', color_scheme);
}
key = '--tg-theme-' + key.split('_').join('-');
root.style.setProperty(key, color);
}
}
}
}
function parseColorToHex(color) {
color += '';
var match;
if (/^#([0-9a-f]){6}$/i.test(color)) {
return color.toLowerCase();
}
else if (match = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(color)) {
return ('#' + match[1] + match[1] + match[2] + match[2] + match[3] + match[3]).toLowerCase();
}
return false;
}
function isColorDark(rgb) {
rgb = rgb.replace(/[\s#]/g, '');
if (rgb.length == 3) {
rgb = rgb[0] + rgb[0] + rgb[1] + rgb[1] + rgb[2] + rgb[2];
}
var r = parseInt(rgb.substr(0, 2), 16);
var g = parseInt(rgb.substr(2, 2), 16);
var b = parseInt(rgb.substr(4, 2), 16);
var hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b));
return hsp < 120;
}
function byteLength(str) {
if (window.Blob) {
try { return new Blob([str]).size; } catch (e) {}
}
var s = str.length;
for (var i=str.length-1; i>=0; i--) {
var code = str.charCodeAt(i);
if (code > 0x7f && code <= 0x7ff) s++;
else if (code > 0x7ff && code <= 0xffff) s+=2;
if (code >= 0xdc00 && code <= 0xdfff) i--;
}
return s;
}
function isParentEl(el, parentEl) {
var checkEl = el.parentNode;
while (checkEl) {
if (checkEl === parentEl) {
return true;
}
checkEl = checkEl.parentNode;
}
return false;
}
var MainButton = (function() {
var isVisible = false;
var isActive = true;
var isProgressVisible = false;
var buttonText = 'CONTINUE';
var buttonColor = false;
var buttonTextColor = false;
var onClickCallback = null;
var mainButton = {};
Object.defineProperty(mainButton, 'text', {
set: function(val){ mainButton.setParams({text: val}); },
get: function(){ return buttonText; },
enumerable: true
});
Object.defineProperty(mainButton, 'color', {
set: function(val){ mainButton.setParams({color: val}); },
get: function(){ return buttonColor || themeParams.button_color || '#2481cc'; },
enumerable: true
});
Object.defineProperty(mainButton, 'textColor', {
set: function(val){ mainButton.setParams({text_color: val}); },
get: function(){ return buttonTextColor || themeParams.button_text_color || '#ffffff'; },
enumerable: true
});
Object.defineProperty(mainButton, 'isVisible', {
set: function(val){ mainButton.setParams({is_visible: val}); },
get: function(){ return isVisible; },
enumerable: true
});
Object.defineProperty(mainButton, 'isProgressVisible', {
get: function(){ return isProgressVisible; },
enumerable: true
});
Object.defineProperty(mainButton, 'isActive', {
get: function(){ return isActive; },
enumerable: true
});
onEvent('main_button_pressed', onMainButtonPressed);
var debugBtn = null, debugBtnStyle = {};
if (initParams.tgDebug) {
debugBtn = document.createElement('tg-main-button');
debugBtnStyle = {
font: '600 14px/18px sans-serif',
display: 'none',
width: '100%',
height: '48px',
borderRadius: '0',
background: 'no-repeat right center',
position: 'fixed',
left: '0',
right: '0',
bottom: '0',
margin: '0',
padding: '15px 20px',
textAlign: 'center',
boxSizing: 'border-box',
zIndex: '10000'
};
for (var k in debugBtnStyle) {
debugBtn.style[k] = debugBtnStyle[k];
}
document.addEventListener('DOMContentLoaded', function onDomLoaded(event) {
document.removeEventListener('DOMContentLoaded', onDomLoaded);
document.body.appendChild(debugBtn);
debugBtn.addEventListener('click', onMainButtonPressed, false);
});
}
function onMainButtonPressed() {
if (isActive && onClickCallback) {
onClickCallback();
}
}
function updateButton() {
var color = mainButton.color;
var text_color = mainButton.textColor;
postEvent('web_app_setup_main_button', false, isVisible ? {
is_visible: true,
is_active: true,
is_progress_visible: isProgressVisible,
text: buttonText,
color: color,
text_color: text_color
} : {is_visible: false});
if (initParams.tgDebug) {
debugBtn.style.display = isVisible ? 'block' : 'none';
debugBtn.innerText = buttonText;
debugBtn.style.backgroundImage = isProgressVisible ? "url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20viewport%3D%220%200%2048%2048%22%20width%3D%2248px%22%20height%3D%2248px%22%3E%3Ccircle%20cx%3D%2250%25%22%20cy%3D%2250%25%22%20stroke%3D%22%23fff%22%20stroke-width%3D%222.25%22%20stroke-linecap%3D%22round%22%20fill%3D%22none%22%20stroke-dashoffset%3D%22106%22%20r%3D%229%22%20stroke-dasharray%3D%2256.52%22%20rotate%3D%22-90%22%3E%3Canimate%20attributeName%3D%22stroke-dashoffset%22%20attributeType%3D%22XML%22%20dur%3D%22360s%22%20from%3D%220%22%20to%3D%2212500%22%20repeatCount%3D%22indefinite%22%3E%3C%2Fanimate%3E%3CanimateTransform%20attributeName%3D%22transform%22%20attributeType%3D%22XML%22%20type%3D%22rotate%22%20dur%3D%221s%22%20from%3D%22-90%2024%2024%22%20to%3D%22630%2024%2024%22%20repeatCount%3D%22indefinite%22%3E%3C%2FanimateTransform%3E%3C%2Fcircle%3E%3C%2Fsvg%3E')" : 'none';
debugBtn.style.backgroundColor = color;
debugBtn.style.color = text_color;
var fixedContainer = document.getElementById('tg-fixed-container');
if (fixedContainer) {
fixedContainer.style.top = isVisible ? '-48px' : '0';
}
}
}
function setParams(params) {
var changed = false;
if (typeof params.text !== 'undefined') {
var text = params.text.toString().replace(/^\s+|\s+$/g, '');
if (!text.length) {
console.error('[Telegram.WebApp] Main button text is required', params.text);
throw Error('WebAppMainButtonParamInvalid');
}
if (text.length > 64) {
console.error('[Telegram.WebApp] Main button text is too long', text);
throw Error('WebAppMainButtonParamInvalid');
}
if (buttonText !== text) {
changed = true;
}
buttonText = text;
}
if (typeof params.color !== 'undefined') {
if (params.color === false ||
params.color === null) {
if (buttonColor !== false) {
changed = true;
}
buttonColor = false;
} else {
var color = parseColorToHex(params.color);
if (!color) {
console.error('[Telegram.WebApp] Main button color format is invalid', color);
throw Error('WebAppMainButtonParamInvalid');
}
if (buttonColor !== color) {
changed = true;
}
buttonColor = color;
}
}
if (typeof params.text_color !== 'undefined') {
if (params.text_color === false ||
params.text_color === null) {
if (buttonTextColor !== false) {
changed = true;
}
buttonTextColor = false;
} else {
var text_color = parseColorToHex(params.text_color);
if (!text_color) {
console.error('[Telegram.WebApp] Main button text color format is invalid', text_color);
throw Error('WebAppMainButtonParamInvalid');
}
if (buttonTextColor !== text_color) {
changed = true;
}
buttonTextColor = text_color;
}
}
if (typeof params.is_visible !== 'undefined') {
if (params.is_visible &&
!mainButton.text.length) {
console.error('[Telegram.WebApp] Main button text is required');
throw Error('WebAppMainButtonParamInvalid');
}
if (isVisible !== !!params.is_visible) {
changed = true;
}
isVisible = !!params.is_visible;
}
if (changed) {
updateButton();
}
return mainButton;
}
mainButton.setParams = setParams;
mainButton.setText = function(text) {
mainButton.text = text;
};
mainButton.onClick = function(callback) {
onClickCallback = callback;
};
mainButton.show = function() {
return mainButton.setParams({is_visible: true});
};
mainButton.hide = function() {
return mainButton.setParams({is_visible: false});
};
mainButton.showProgress = function(leaveActive) {
isActive = !!leaveActive;
isProgressVisible = true;
updateButton();
return mainButton;
};
mainButton.hideProgress = function() {
if (!mainButton.isActive) {
isActive = true;
}
isProgressVisible = false;
updateButton();
return mainButton;
}
return mainButton;
})();
function openProtoUrl(url) {
if (!url.match(/^(web\+)?tgb?:\/\/./)) {
return false;
}
var useIframe = navigator.userAgent.match(/iOS|iPhone OS|iPhone|iPod|iPad/i) ? true : false;
if (useIframe) {
var iframeContEl = document.getElementById('tgme_frame_cont') || document.body;
var iframeEl = document.createElement('iframe');
iframeContEl.appendChild(iframeEl);
var pageHidden = false;
var enableHidden = function () {
pageHidden = true;
};
window.addEventListener('pagehide', enableHidden, false);
window.addEventListener('blur', enableHidden, false);
if (iframeEl !== null) {
iframeEl.src = url;
}
setTimeout(function() {
if (!pageHidden) {
window.location = url;
}
window.removeEventListener('pagehide', enableHidden, false);
window.removeEventListener('blur', enableHidden, false);
}, 2000);
}
else {
window.location = url;
}
return true;
}
if (!window.Telegram) {
window.Telegram = {};
}
window.Telegram.WebView = {
initParams: initParams,
onEvent: onEvent,
offEvent: offEvent,
receiveEvent: receiveEvent,
};
window.Telegram.Games = {
shareScore: function() {
postEvent('share_score', function (error) {
if (error) {
var shareScoreUrl = initParams.tgShareScoreUrl;
if (shareScoreUrl) {
openProtoUrl(shareScoreUrl);
}
}
});
},
shareGame: function() {
postEvent('share_game');
}
};
window.Telegram.Payments = {
submitPaymentForm: function (formData) {
if (!formData ||
!formData.credentials ||
formData.credentials.type !== 'card' ||
!formData.credentials.token ||
!formData.credentials.token.match(/^[A-Za-z0-9\/=_\-]{4,512}$/) ||
!formData.title) {
console.error('[Telegram.Payments] Invalid form data submitted', formData);
throw Error('PaymentFormDataInvalid');
}
postEvent('payment_form_submit', false, formData);
}
};
window.Telegram.WebApp = {
initData: webAppData,
initDataRaw: webAppDataRaw,
onEvent: onEvent,
offEvent: offEvent,
MainButton: MainButton,
sendData: function (data) {
if (!data || !data.length) {
console.error('[Telegram.WebApp] Data is required', data);
throw Error('WebAppDataInvalid');
}
if (byteLength(data) > 4096) {
console.error('[Telegram.WebApp] Data is too long', data);
throw Error('WebAppDataInvalid');
}
postEvent('web_app_data_send', false, {data: data});
},
expand: function () {
postEvent('web_app_expand');
},
close: function () {
postEvent('web_app_close');
}
};
if (webAppData.theme_params) {
setThemeParams(webAppData.theme_params);
}
onEvent('theme_changed', onThemeChanged);
onEvent('viewport_changed', onViewportChanged);
// For Windows Phone app
window.TelegramGameProxy_receiveEvent = receiveEvent;
// Backward compatibility
window.TelegramGameProxy = {
initParams: initParams,
onEvent: onEvent,
receiveEvent: receiveEvent,
shareScore: window.Telegram.Games.shareScore,
paymentFormSubmit: window.Telegram.Payments.submitPaymentForm
};
})();

View file

@ -200,7 +200,7 @@ var RLottie = (function () {
}
rlPlayer.options = options;
rlPlayer.paused = options.noAutoPlay || false;
rlPlayer.forcePlayOnce = false;
rlPlayer.forcePlayFrames = 0;
rlPlayer.times = [];
rlPlayer.clamped = new Uint8ClampedArray(rlPlayer.width * rlPlayer.height * 4);
rlPlayer.imageData = new ImageData(rlPlayer.width, rlPlayer.height);
@ -298,8 +298,7 @@ var RLottie = (function () {
rlPlayer.frameQueue.push(frame);
var nextFrameNo = ++frameNo;
if (nextFrameNo >= rlPlayer.frameCount) {
if (!rlPlayer.options.playOnce &&
!rlPlayer.forcePlayOnce) {
if (!rlPlayer.options.playOnce) {
nextFrameNo = 0;
if (rlPlayer.times.length) {
// var avg = 0;
@ -310,11 +309,13 @@ var RLottie = (function () {
rlPlayer.times = [];
}
} else {
if (rlPlayer.forcePlayOnce) {
nextFrameNo = 0;
}
rlPlayer.paused = true;
rlPlayer.forcePlayOnce = false;
}
}
if (rlPlayer.forcePlayFrames > 0) {
rlPlayer.forcePlayFrames--;
if (!rlPlayer.forcePlayFrames) {
rlPlayer.paused = true;
}
}
if (rlPlayer.frameQueue.needsMore()) {
@ -357,9 +358,11 @@ var RLottie = (function () {
}
rlottie.playOnce = function(el) {
if (el && el.rlPlayer) {
if (el && el.rlPlayer &&
!el.rlPlayer.forcePlayFrames &&
el.rlPlayer.frameCount) {
el.rlPlayer.paused = false;
el.rlPlayer.forcePlayOnce = true;
el.rlPlayer.forcePlayFrames = el.rlPlayer.frameCount;
}
}

View file

@ -271,7 +271,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitRetinaVideos();
mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":3,"unsupportedURL":"\/?notgs=1"});

View file

@ -271,7 +271,7 @@
</div>
</div>
<script src="/js/main.js?44"></script>
<script src="/js/tgsticker.js?25"></script>
<script src="/js/tgsticker.js?26"></script>
<script>mainInitRetinaVideos();
mainInitTgStickers({"maxDeviceRatio":2,"cachingModulo":3,"unsupportedURL":"\/?notgs=1"});