mirror of
https://github.com/MarshalX/telegram-crawler.git
synced 2024-12-29 15:59:13 +01:00
Update content of files
This commit is contained in:
parent
4219b4c1e6
commit
1eb2909d2b
3 changed files with 568 additions and 0 deletions
|
@ -0,0 +1,6 @@
|
|||
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Telegram Beta</title><link>/v0.1/public/sparkle/apps/6ed2ac30-49e1-4073-87c2-f1ffcb74e81f</link><item><title>Version 8.6.1 (229175)</title><description><div><p>[&quot;bug fixes&quot;]</p>
|
||||
</div></description><pubDate>Tue, 29 Mar 2022 16:41:39 GMT</pubDate><enclosure sparkle:version="229175" sparkle:shortVersionString="8.6.1" sparkle:dsaSignature="MCwCFHHz1Qn1WKdA60mkdJgqaQBU18P8AhRK8FPtr0ehqb1yUGUC11MVBSR20g==" url="https://appcenter-filemanagement-distrib1ede6f06e.azureedge.net/1c9cbd3b-2e32-4857-8c21-67a70d3587f3/Telegram-8.6.1.229175.app.zip?sv=2019-02-02&sr=c&sig=uuGqxCQk5XgP5LzvpH57nscMqBHXe6Hbt0ar5rr1M7A%3D&se=2022-03-30T16%3A42%3A27Z&sp=r" length="81647990" type="application/octet-stream"></enclosure><sparkle:minimumSystemVersion>10.11</sparkle:minimumSystemVersion></item><item><title>Version 8.6.1 (229130)</title><description><div><p>[&quot;bug fixes&quot;]</p>
|
||||
</div></description><pubDate>Mon, 28 Mar 2022 16:02:45 GMT</pubDate><enclosure sparkle:version="229130" sparkle:shortVersionString="8.6.1" sparkle:dsaSignature="MCwCFBBBAWyoaoWsBDF7Tk8I3AUfqCWCAhQ9NdlKn4hpXTRwkyy8fBoR/cQaJw==" url="https://appcenter-filemanagement-distrib2ede6f06e.azureedge.net/ba1c3e26-6209-4a2c-95e0-478e04982e0e/Telegram-8.6.1.229130.app.zip?sv=2019-02-02&sr=c&sig=oJTrQarj3XfwZBlg%2FlHOWgSgDgugKKfgNAFIiqpEdqs%3D&se=2022-03-31T01%3A40%3A46Z&sp=r" length="81628601" type="application/octet-stream"></enclosure><sparkle:minimumSystemVersion>10.11</sparkle:minimumSystemVersion></item><item><title>Version 8.6.1 (229037)</title><description><div><p>[&quot;bug fixes&quot;]</p>
|
||||
</div></description><pubDate>Thu, 24 Mar 2022 17:40:39 GMT</pubDate><enclosure sparkle:version="229037" sparkle:shortVersionString="8.6.1" sparkle:dsaSignature="MCwCFHcs4yNEp+UQMdDgqR4YOaAe2veJAhQNP4l9h0y2JmzVxfn4kE5BsSTRFQ==" url="https://appcenter-filemanagement-distrib2ede6f06e.azureedge.net/26a57a5b-ac7c-4b07-b214-f81a7c1726b1/Telegram-8.6.1.229037.app.zip?sv=2019-02-02&sr=c&sig=LnoAPkUGICuJYFbfSjfRnUb%2B%2FKDECeTs%2FO1xhSGfBMs%3D&se=2022-03-31T01%3A40%3A46Z&sp=r" length="81231041" type="application/octet-stream"></enclosure><sparkle:minimumSystemVersion>10.11</sparkle:minimumSystemVersion></item><item><title>Version 8.6.1 (229007)</title><description><div><p>[&quot;bug fixes&quot;]</p>
|
||||
</div></description><pubDate>Thu, 24 Mar 2022 11:35:10 GMT</pubDate><enclosure sparkle:version="229007" sparkle:shortVersionString="8.6.1" sparkle:dsaSignature="MC0CFHF4Y0SjzerCWAR1ttxLXCdzsagYAhUAibZqQkle32gNxZk5fXRlUVyNTO0=" url="https://appcenter-filemanagement-distrib2ede6f06e.azureedge.net/6d150c75-72b3-4551-a8eb-e81ce3e95406/Telegram-8.6.1.229007.app.zip?sv=2019-02-02&sr=c&sig=Py%2FKpuygskxmPWP%2FKCj%2BQ5gVAcgFSycca6PdQcGoEBs%3D&se=2022-03-31T01%3A40%3A46Z&sp=r" length="81214282" type="application/octet-stream"></enclosure><sparkle:minimumSystemVersion>10.11</sparkle:minimumSystemVersion></item><item><title>Version 8.6.1 (228975)</title><description><div><p>[&quot;bug fixes&quot;]</p>
|
||||
</div></description><pubDate>Tue, 22 Mar 2022 17:40:55 GMT</pubDate><enclosure sparkle:version="228975" sparkle:shortVersionString="8.6.1" sparkle:dsaSignature="MC0CFDRbtCrmTaERe+4vmz5gx+yCNe1jAhUAiA7dqfA9ZhMC07ZAaG/Kf65f1QY=" url="null" length="81213332" type="application/octet-stream"></enclosure><sparkle:minimumSystemVersion>10.11</sparkle:minimumSystemVersion></item></channel></rss>
|
215
data/comments.app/test_webview.html
Normal file
215
data/comments.app/test_webview.html
Normal file
|
@ -0,0 +1,215 @@
|
|||
<!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;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
</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();">Send current time to bot</button>
|
||||
<button id="spam_btn" onclick="sendTime(true);">Send current time to bot (x100)</button>
|
||||
<button class="close_btn" onclick="webviewClose()">Close Webview</button>
|
||||
<div id="btn_status" class="hint" style="display: none;">
|
||||
</div>
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="https://telegram.org/" target="_blank">Morbi lacus</a>.</p>
|
||||
<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 ? 100 : 1;
|
||||
for (var i = 0; i < repeat; i++) {
|
||||
Telegram.WebApp.sendData(text);
|
||||
}
|
||||
}
|
||||
function sendTime(spam) {
|
||||
var repeat = spam ? 100 : 1;
|
||||
for (var i = 0; i < repeat; i++) {
|
||||
Telegram.WebApp.sendData(new Date().toString());
|
||||
}
|
||||
}
|
||||
function webviewClose() {
|
||||
Telegram.WebApp.close();
|
||||
}
|
||||
$('#main_btn').toggle(!!WebAppData.query_id);
|
||||
$('#with_webview_btn').toggle(!!WebAppData.query_id && !WebAppData.receiver);
|
||||
$('#data_btn,#spam_btn').toggle(!WebAppData.query_id || !WebAppData.receiver);
|
||||
$('#webview_data').html(JSON.stringify(WebAppData, null, 2));
|
||||
$('#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', '');
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
347
data/telegram.org/js/telegram-webview.js
Normal file
347
data/telegram.org/js/telegram-webview.js
Normal file
|
@ -0,0 +1,347 @@
|
|||
(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) {}
|
||||
}
|
||||
}
|
||||
else if (initParams.tgWebviewData && initParams.tgWebviewData.length) {
|
||||
// temp
|
||||
webAppDataRaw = initParams.tgWebviewData;
|
||||
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) {}
|
||||
}
|
||||
}
|
||||
if (webAppData.theme_params) {
|
||||
setThemeParams(webAppData.theme_params);
|
||||
}
|
||||
onEvent('theme_changed', onThemeChanged);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
callback();
|
||||
}
|
||||
else if (window.external && 'notify' in window.external) {
|
||||
window.external.notify(JSON.stringify({eventType: eventType, eventData: 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);
|
||||
callback();
|
||||
} catch (e) {
|
||||
callback(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
callback({notAvailable: true});
|
||||
}
|
||||
};
|
||||
|
||||
function 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);
|
||||
};
|
||||
|
||||
function setThemeParams(theme_params) {
|
||||
var root = document.documentElement, color;
|
||||
if (root && root.style && root.style.setProperty) {
|
||||
for (var key in theme_params) {
|
||||
if ((color = theme_params[key]) &&
|
||||
/^#[0-9a-f]{3}|#[0-9a-f]{6}$/i.test(color)) {
|
||||
if (key == 'bg_color') {
|
||||
root.style.setProperty('--tg-theme-color-scheme', isColorDark(color) ? 'dark' : 'light');
|
||||
}
|
||||
key = '--tg-theme-' + key.split('_').join('-');
|
||||
root.style.setProperty(key, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 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,
|
||||
|
||||
sendData: function (data) {
|
||||
if (!data || !data.length) {
|
||||
console.error('[Telegram.WebApp] Data is empty', 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});
|
||||
postEvent('webview_data_send', false, {data: data});//temp
|
||||
},
|
||||
close: function () {
|
||||
postEvent('web_app_close');
|
||||
postEvent('webview_close');//temp
|
||||
}
|
||||
};
|
||||
|
||||
// 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
|
||||
};
|
||||
|
||||
})();
|
Loading…
Reference in a new issue