Last active
March 14, 2017 16:27
-
-
Save kir-sf/4caa4b31efaa9ebcaa640939ef9fa51b to your computer and use it in GitHub Desktop.
Скрытый чат
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var USERS=[]; // массив электронных адресов электронной почты участников чата, зарегистрированной в Google | |
var DAYS=['понедельник', 'вторник', 'среда', 'четверг', 'пятница', 'суббота', 'воскресенье']; | |
var HTML_BODY='<a href="адрес публикации скрипта/exec?param=##PARAM##">ХОЧЕШЬ ЗАРАБОТАТЬ МИЛЛИОН?</a>'; | |
function doGet(e) { | |
var myCashe=CacheService.getScriptCache(); | |
var par=e.parameter.param; | |
var code=myCashe.get(Session.getActiveUser().getEmail()); | |
if (par==null) // защита от вызова без параметра | |
return HtmlService.createTemplateFromFile('ind').evaluate(); | |
if (par==code) { // проверяем валидность ссылки | |
myCashe.remove(Session.getActiveUser().getEmail()); // если ссылка валидна удаляем ее, запустить сеанс можно только один раз | |
return HtmlService.createTemplateFromFile('index').evaluate(); | |
} else | |
return HtmlService.createTemplateFromFile('ind').evaluate(); | |
} | |
function Show() { | |
var outText="CHAT<br>"; | |
var myCashe=CacheService.getScriptCache(); | |
var chatHistory=myCashe.get('post'); | |
if (chatHistory==null) chatHistory="chat is empty"; | |
outText=outText+chatHistory; | |
return outText; | |
} | |
function sendPost(post) { | |
var myCashe=CacheService.getScriptCache(); | |
var chatHistory=myCashe.get('post'); | |
if (chatHistory==null) chatHistory=''; | |
chatHistory=chatHistory+Session.getActiveUser().getEmail()+':'+post+'<br>'; | |
myCashe.put('post', chatHistory); | |
} | |
function startChat() { | |
var myCashe=CacheService.getScriptCache(); | |
for (var i=0; i<USERS.length; i++) { | |
var date=new Date(); | |
var str=USERS[i]+Math.round(Math.random()*1000)+DAYS[date.getDay()]; | |
var secret_param=hex_md5(str); | |
myCashe.put(USERS[i], secret_param); | |
var textLink=HTML_BODY.replace("##PARAM##", secret_param); | |
var mail={ | |
to: USERS[i], | |
from: "НЕВЕРОЯТНОЕ ПРЕДЛОЖЕНИЕ", | |
subject: 'ХОЧЕШЬ ЗАРАБОТАТЬ МИЛЛИОН', | |
htmlBody: textLink | |
} | |
MailApp.sendEmail(mail); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
</head> | |
<body> | |
Заглушка | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script> | |
function sendPost() { | |
google.script.run.sendPost(document.getElementById("postOfUser").value); | |
document.getElementById("postOfUser").value=""; | |
} | |
</script> | |
</head> | |
<body> | |
<input id="postOfUser" /><button onclick="sendPost()">Send</button> | |
<div id="outtext"></div> | |
<script> | |
function show(html){ | |
document.getElementById("outtext").innerHTML=html; | |
} | |
</script> | |
<script> | |
function updateContent(){ | |
google.script.run.withSuccessHandler(show).Show(); | |
} | |
function timer(){ | |
setTimeout(function(){ | |
updateContent(); | |
timer(); | |
}, 2000); | |
} | |
timer(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment