messager.js 720 B

123456789101112131415161718192021222324
  1. var Messager = function() {
  2. this.warning = function(message) {
  3. console.warn(message);
  4. notice(message, "warning", 2000);
  5. };
  6. this.transmission = function(message) {
  7. console.log(message);
  8. notice(message, "transmission", Math.max(message.length * 45, 2000));
  9. };
  10. var notice = function(message, displayType, duration) {
  11. var popup = document.createElement("div");
  12. popup.className = "popup " + displayType;
  13. popup.style = "border-radius: 5px;";
  14. document.getElementById("popupContainer").appendChild(popup);
  15. popup.innerHTML = message;
  16. popup.display = "block";
  17. setTimeout(function() {
  18. document.getElementById("popupContainer").removeChild(popup);
  19. }, duration);
  20. };
  21. }
  22. var messager = new Messager();