topic_load.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. function topic_load(name, sub, num) {
  2. var test = setInterval(function() {
  3. var url = "/api/topic/" + name + "/sub/" + sub + "?num=" + num;
  4. var doc_data = document.getElementById("plus");
  5. var xhr = new XMLHttpRequest();
  6. xhr.open("GET", url, true);
  7. xhr.send(null);
  8. xhr.onreadystatechange = function() {
  9. if(this.readyState === 4 && this.status === 200) {
  10. if(this.responseText) {
  11. doc_data.innerHTML += '<hr class="main_hr">(New)<hr class="main_hr">';
  12. // https://programmingsummaries.tistory.com/379
  13. var options = {
  14. body: 'New topic'
  15. }
  16. var notification = new Notification("openNAMU", options);
  17. setTimeout(function () {
  18. notification.close();
  19. }, 5000);
  20. clearInterval(test);
  21. }
  22. }
  23. }
  24. }, 2000);
  25. }