Mayx's Home Page
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.5 KiB

  1. var message_Path = '/Live2dHistoire/live2d/';
  2. var talkAPI = BlogAPI + "/ai_chat";
  3. function initVisitors() {
  4. if ($('.visitors').length === 1) {
  5. var $visitor = $('.visitors:first');
  6. $.get(BlogAPI + '/count_click_add?id=' + $visitor.attr('id'), function (data) {
  7. $visitor.text(Number(data));
  8. });
  9. } else if ($('.visitors-index').length > 0) {
  10. $('.visitors-index').each(function () {
  11. var $elem = $(this);
  12. $.get(BlogAPI + '/count_click?id=' + $elem.attr('id'), function (data) {
  13. $elem.text(Number(data));
  14. });
  15. });
  16. }
  17. }
  18. function highlightKeyword() {
  19. var match = location.search.match(/[?&]kw=([^&]+)/);
  20. var kw = match ? $.trim(decodeURIComponent(match[1].replace(/\+/g, ' '))) : '';
  21. if (!kw) return;
  22. var reg = new RegExp('(' + kw.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')', 'gi');
  23. var escapeMap = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' };
  24. $('section, section *').not('script, style, textarea').contents().filter(function () {
  25. return this.nodeType === 3;
  26. }).each(function () {
  27. var escapedText = this.nodeValue.replace(/[&<>"']/g, function (m) { return escapeMap[m]; });
  28. var highlighted = escapedText.replace(reg, '<mark>$1</mark>');
  29. if (escapedText !== highlighted) {
  30. $(this).replaceWith(highlighted);
  31. }
  32. });
  33. }
  34. $(function () {
  35. (function () {
  36. var $backToTopTxt = "返回顶部", $backToTopEle = $('<div class="backToTop"></div>').appendTo($("body"))
  37. .text($backToTopTxt).attr("title", $backToTopTxt).click(function () {
  38. $("html, body").animate({ scrollTop: 0 }, 120);
  39. }), $backToTopFun = function () {
  40. var st = $(document).scrollTop(), winh = $(window).height();
  41. (st > 0) ? $backToTopEle.show() : $backToTopEle.hide();
  42. };
  43. $(window).bind("scroll", $backToTopFun);
  44. $(function () { $backToTopFun(); });
  45. })();
  46. initVisitors();
  47. if (Math.floor((new Date().getTime() - lastUpdated.getTime()) / (24 * 60 * 60 * 1000)) > 90) {
  48. $("html").css({
  49. "-webkit-filter": "grayscale(100%)",
  50. "filter": "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)"
  51. })
  52. $('body').html(function (_, oldHTML) {
  53. return oldHTML.replace(/Mayx/g, 'Ghost');
  54. });
  55. console.warn("Mayx may already be Dead");
  56. }
  57. highlightKeyword();
  58. });
  59. function getSearchJSON(callback) {
  60. if (typeof Storage == 'undefined') {
  61. $.getJSON("/search.json", callback);
  62. return;
  63. }
  64. var searchData = JSON.parse(localStorage.getItem("blog_" + lastUpdated.valueOf()));
  65. if (!searchData) {
  66. for (var i = localStorage.length - 1; i >= 0; i--) {
  67. var key = localStorage.key(i);
  68. if (key.indexOf('blog_') === 0) {
  69. localStorage.removeItem(key);
  70. }
  71. }
  72. $.getJSON("/search.json", function (data) {
  73. localStorage.setItem("blog_" + lastUpdated.valueOf(), JSON.stringify(data));
  74. callback(data);
  75. });
  76. } else {
  77. callback(searchData);
  78. }
  79. }
  80. if (typeof window.go === 'undefined') {
  81. window.go = function (url) {
  82. window.location.href = url;
  83. return;
  84. }
  85. }
  86. function getWelcomeText(pathname, title) {
  87. pathname = pathname || window.location.pathname;
  88. title = title || document.title.split(' | ')[0];
  89. if (pathname === '/' || pathname === '/index.html') {
  90. var now = (new Date()).getHours();
  91. if (now > 23 || now <= 5) return '你是夜猫子呀?这么晚还不睡觉,明天起的来嘛?';
  92. if (now > 5 && now <= 7) return '早上好!一日之计在于晨,美好的一天就要开始了!';
  93. if (now > 7 && now <= 11) return '上午好!工作顺利嘛,不要久坐,多起来走动走动哦!';
  94. if (now > 11 && now <= 14) return '中午了,工作了一个上午,现在是午餐时间!';
  95. if (now > 14 && now <= 17) return '午后很容易犯困呢,今天的运动目标完成了吗?';
  96. if (now > 17 && now <= 19) return '傍晚了!窗外夕阳的景色很美丽呢,最美不过夕阳红~~';
  97. if (now > 19 && now <= 21) return '晚上好,今天过得怎么样?';
  98. if (now > 21 && now <= 23) return '已经这么晚了呀,早点休息吧,晚安~~';
  99. return '嗨~ 快来逗我玩吧!';
  100. }
  101. return '欢迎阅读<span style="color:#0099cc;">「 ' + title + ' 」</span>';
  102. }