![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOx4UerZFvdEIMUMMQ7dLXoUz6ASiUG3v_uFfBzh3ruKoH32s9BUuZPLXCHopyYjPY7zPVWMmbdv8WPwAEImgewg_nhs1LOj3W1tKk3OKEz3x_qVxfGoERS6No-wnvDXPGhgWeaShrA__9/s1600/Screen+shot+2014-01-10+at+11.19.15+AM.png)
The code turned out very simple.
code.gs:
function doGet() { return HtmlService.createTemplateFromFile('page') .evaluate() .setSandboxMode(HtmlService.SandboxMode.NATIVE); } function getInboxUnreadCount() { return GmailApp.getInboxUnreadCount(); }
page.html:
<style type="text/css"> #refresh { color: blue; text-decoration: underline; } #refresh:hover { cursor: pointer; } </style> <div id="inbox"> Inbox (<span id="count">...</span>) <span id="refresh">refresh</span> </div> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> function check() { clearTimeout(check.timer); google.script.run .withSuccessHandler(function(result) { $('#count').text(result); $('#inbox').toggleClass('unread', result > 0); }) .getInboxUnreadCount(); $('#count').text("..."); check.timer = setTimeout(check, 600000); } $(function() { check(); $('#refresh').click(check); }); </script>
The getInboxUnreadCount() function needed to be run from the script editor to grant the needed permissions to the script, after that it worked from my personal home page.
No comments:
Post a Comment