/core.html

https://github.com/xupisco/gameLib-Chrome-Extension · HTML · 121 lines · 101 code · 20 blank · 0 comment · 0 complexity · 6675f7b02313eb890bc4ea9d6da56848 MD5 · raw file

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link rel="stylesheet" type="text/css" href="css/style.css" />
  5. <script src="js/jquery-1.6.4.min.js"></script> <!-- Including jQuery -->
  6. <script src="js/core.js"></script> <!-- Our script file -->
  7. <script type="text/javascript">
  8. var req;
  9. var firstRun = true;
  10. var page = 0;
  11. var limit = 5;
  12. var opened = 0;
  13. var feedUrl = 'http://www.gamelib.com.br/app/latest/?limit=' + limit;
  14. function main() {
  15. req = new XMLHttpRequest();
  16. req.onload = handleResponse;
  17. req.onerror = handleError;
  18. req.open("GET", feedUrl, true);
  19. req.send(null);
  20. bg = chrome.extension.getBackgroundPage()
  21. bg.unreaded = 0;
  22. chrome.browserAction.setBadgeText({text:''});
  23. $("#logo").click(function() {
  24. chrome.tabs.create({'url': 'http://www.gamelib.com.br'});
  25. self.close();
  26. });
  27. $("#next").addClass('on');
  28. $("#previous").addClass('on');
  29. $("#next").click(function() { gotoPage(1) });
  30. $("#previous").click(function() { gotoPage(0) });
  31. }
  32. function gotoPage(n) {
  33. page = n ? page + 1 : page - 1;
  34. if(page != -1) {
  35. $("#content").css('opacity', '0.1');
  36. $("#loader").css({ 'position': 'absolute', 'top': '170px', 'left': '60px' });
  37. $("#loader").show();
  38. offset = limit * page;
  39. feedUrl = 'http://www.gamelib.com.br/app/latest/?limit=' + limit + '&offset=' + offset;
  40. req.open("GET", feedUrl, true);
  41. req.send(null);
  42. } else {
  43. page = 0;
  44. }
  45. }
  46. function openPost(pid) {
  47. chrome.tabs.create({'url': 'http://www.gamelib.com.br' + $("#" + pid).attr('link')});
  48. self.close();
  49. }
  50. function handleResponse() {
  51. $("#content").html('');
  52. data = $.parseJSON(req.response);
  53. for (var i = 0; i < data.results.length; i++) {
  54. var post = data.results[i];
  55. div = "<div class='post_holder' id='" + post.content_id + "' link='" + post.content_link + "' post_id='" + post.content_id + "'>";
  56. div += "<div class='post_comments'>" + post.content_comments + "</div>\n";
  57. div += "<div class='post_date'>" + post.content_date + "</div>\n";
  58. div += "<div class='post_title'>" + post.content_title + "</div>\n";
  59. div += "</div>\n";
  60. div += "<div id='post_content_" + post.content_id + "' class='post_content'>" + post.content_teaser + "<div class='post_more'><a href='javascript:openPost(" + post.content_id + ")'>Abrir post completo...</a></div></div>\n";
  61. $("#content").append(div);
  62. }
  63. if(page <= 0) {
  64. $("#previous").removeClass('on').addClass('off');
  65. } else {
  66. $("#previous").removeClass('off').addClass('on');
  67. }
  68. $("#loader").hide();
  69. $("#content").css('opacity', '1');
  70. $(".post_holder").click(function() {
  71. post_content = "#post_content_" + $(this).attr('post_id');
  72. if(opened != $(this).attr('post_id')) {
  73. $('.post_content').each(function() { $(this).slideUp(); });
  74. $(post_content).slideToggle();
  75. opened = $(this).attr('post_id');
  76. } else {
  77. //openPost($(this).attr('post_id'));
  78. opened = 0;
  79. $(post_content).slideUp();
  80. }
  81. });
  82. if(firstRun) {
  83. $("#pages").slideDown();
  84. }
  85. firstRun = false;
  86. }
  87. function handleError() {}
  88. </script>
  89. </head>
  90. <body onload="main()">
  91. <div id="rounded">
  92. <div id="logo"><img src="http://www.gamelib.com.br/static/images/gamelib_logo-alert.gif" border="0" /></div>
  93. <div id="loader"><img src="images/loading.gif" border="0" /></div>
  94. <div id="content"></div>
  95. <div id="pages">
  96. <div id="next"><img src="images/arrow_next.png" border="0" /></div>
  97. <div id="previous"><img src="images/arrow_previous.png" border="0" /></div>
  98. </div>
  99. </div>
  100. </body>
  101. </html>