main.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. var iUp = (function () {
  2. var time = 0,
  3. duration = 150,
  4. clean = function () {
  5. time = 0;
  6. },
  7. up = function (element) {
  8. setTimeout(function () {
  9. element.classList.add("up");
  10. }, time);
  11. time += duration;
  12. },
  13. down = function (element) {
  14. element.classList.remove("up");
  15. },
  16. toggle = function (element) {
  17. setTimeout(function () {
  18. element.classList.toggle("up");
  19. }, time);
  20. time += duration;
  21. };
  22. return {
  23. clean: clean,
  24. up: up,
  25. down: down,
  26. toggle: toggle
  27. };
  28. })();
  29. function getBingImages(imgUrls) {
  30. /**
  31. * 获取Bing壁纸
  32. * 先使用 GitHub Action 每天获取 Bing 壁纸 URL 并更新 images.json 文件
  33. * 然后读取 images.json 文件中的数据
  34. */
  35. var indexName = "bing-image-index";
  36. var index = sessionStorage.getItem(indexName);
  37. var panel = document.querySelector('#panel');
  38. if (isNaN(index) || index == 7) index = 0;
  39. else index++;
  40. var imgUrl = imgUrls[index];
  41. var url = "https://www.cn.bing.com" + imgUrl;
  42. panel.style.background = "url('" + url + "') center center no-repeat #666";
  43. panel.style.backgroundSize = "cover";
  44. sessionStorage.setItem(indexName, index);
  45. }
  46. function decryptEmail(encoded) {
  47. var address = atob(encoded);
  48. window.location.href = "mailto:" + address;
  49. }
  50. document.addEventListener('DOMContentLoaded', function () {
  51. // 获取一言数据
  52. var xhr = new XMLHttpRequest();
  53. xhr.onreadystatechange = function () {
  54. if (this.readyState == 4 && this.status == 200) {
  55. var res = JSON.parse(this.responseText);
  56. document.getElementById('description').innerHTML = res.hitokoto + "<br/> -「<strong>" + res.from + "</strong>」";
  57. }
  58. };
  59. xhr.open("GET", "https://v1.hitokoto.cn", true);
  60. xhr.send();
  61. var iUpElements = document.querySelectorAll(".iUp");
  62. iUpElements.forEach(function (element) {
  63. iUp.up(element);
  64. });
  65. var avatarElement = document.querySelector(".js-avatar");
  66. avatarElement.addEventListener('load', function () {
  67. avatarElement.classList.add("show");
  68. });
  69. });
  70. var btnMobileMenu = document.querySelector('.btn-mobile-menu__icon');
  71. var navigationWrapper = document.querySelector('.navigation-wrapper');
  72. btnMobileMenu.addEventListener('click', function () {
  73. if (navigationWrapper.style.display == "block") {
  74. navigationWrapper.addEventListener('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () {
  75. navigationWrapper.classList.toggle('visible');
  76. navigationWrapper.classList.toggle('animated');
  77. navigationWrapper.classList.toggle('bounceOutUp');
  78. navigationWrapper.removeEventListener('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', arguments.callee);
  79. });
  80. navigationWrapper.classList.toggle('animated');
  81. navigationWrapper.classList.toggle('bounceInDown');
  82. navigationWrapper.classList.toggle('animated');
  83. navigationWrapper.classList.toggle('bounceOutUp');
  84. } else {
  85. navigationWrapper.classList.toggle('visible');
  86. navigationWrapper.classList.toggle('animated');
  87. navigationWrapper.classList.toggle('bounceInDown');
  88. }
  89. btnMobileMenu.classList.toggle('social');
  90. btnMobileMenu.classList.toggle('iconfont');
  91. btnMobileMenu.classList.toggle('icon-list');
  92. btnMobileMenu.classList.toggle('social');
  93. btnMobileMenu.classList.toggle('iconfont');
  94. btnMobileMenu.classList.toggle('icon-angleup');
  95. btnMobileMenu.classList.toggle('animated');
  96. btnMobileMenu.classList.toggle('fadeIn');
  97. });