Mayx's Home Page https://mabbs.github.io
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.

496 lines
16 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. var home_Path = document.location.protocol + '//' + window.document.location.hostname + '/';
  2. var userAgent = window.navigator.userAgent.toLowerCase();
  3. console.log(userAgent);
  4. var norunAI = ["android", "iphone", "ipod", "ipad", "windows phone"];
  5. var norunFlag = false;
  6. for (var i = 0; i < norunAI.length; i++) {
  7. if (userAgent.indexOf(norunAI[i]) > -1) {
  8. norunFlag = true;
  9. break;
  10. }
  11. }
  12. if (!window.WebGLRenderingContext) {
  13. norunFlag = true;
  14. }
  15. if (!norunFlag) {
  16. var hitFlag = false;
  17. var AIFadeFlag = false;
  18. var liveTlakTimer = null;
  19. var sleepTimer_ = null;
  20. var AITalkFlag = false;
  21. var talkNum = 0;
  22. (function () {
  23. function renderTip(template, context) {
  24. var tokenReg = /(\\)?\{([^\{\}\\]+)(\\)?\}/g;
  25. return template.replace(tokenReg, function (word, slash1, token, slash2) {
  26. if (slash1 || slash2) {
  27. return word.replace(/\\/g, '');
  28. }
  29. var variables = token.replace(/\s/g, '').split('.');
  30. var currentObject = context;
  31. var i, length, variable;
  32. for (i = 0, length = variables.length; i < length; ++i) {
  33. variable = variables[i];
  34. currentObject = currentObject[variable];
  35. if (currentObject === undefined || currentObject === null) return '';
  36. }
  37. return currentObject;
  38. });
  39. }
  40. String.prototype.renderTip = function (context) {
  41. return renderTip(this, context);
  42. };
  43. var re = /x/;
  44. console.log(re);
  45. re.toString = function () {
  46. showMessage('哈哈,你打开了控制台,是想要看看我的秘密吗?', 5000);
  47. return '';
  48. };
  49. $(document).on('copy', function () {
  50. showMessage('你都复制了些什么呀,转载要记得加上出处哦~~', 5000);
  51. });
  52. function initTips() {
  53. $.ajax({
  54. cache: true,
  55. url: message_Path + 'message.json',
  56. dataType: "json",
  57. success: function (result) {
  58. $.each(result.mouseover, function (index, tips) {
  59. $(tips.selector).mouseover(function () {
  60. var text = tips.text;
  61. if (Array.isArray(tips.text)) text = tips.text[Math.floor(Math.random() * tips.text.length + 1) - 1];
  62. text = text.renderTip({ text: $(this).text() });
  63. showMessage(text, 3000);
  64. talkValTimer();
  65. clearInterval(liveTlakTimer);
  66. liveTlakTimer = null;
  67. });
  68. $(tips.selector).mouseout(function () {
  69. showHitokoto();
  70. if (liveTlakTimer == null) {
  71. liveTlakTimer = window.setInterval(function () {
  72. showHitokoto();
  73. }, 15000);
  74. };
  75. });
  76. });
  77. $.each(result.click, function (index, tips) {
  78. $(tips.selector).click(function () {
  79. if (hitFlag) {
  80. return false
  81. }
  82. hitFlag = true;
  83. setTimeout(function () {
  84. hitFlag = false;
  85. }, 8000);
  86. var text = tips.text;
  87. if (Array.isArray(tips.text)) text = tips.text[Math.floor(Math.random() * tips.text.length + 1) - 1];
  88. text = text.renderTip({ text: $(this).text() });
  89. showMessage(text, 3000);
  90. });
  91. clearInterval(liveTlakTimer);
  92. liveTlakTimer = null;
  93. if (liveTlakTimer == null) {
  94. liveTlakTimer = window.setInterval(function () {
  95. showHitokoto();
  96. }, 15000);
  97. };
  98. });
  99. }
  100. });
  101. }
  102. initTips();
  103. var text;
  104. if (document.referrer !== '' && document.referrer.split('/')[2] !== window.location.host) {
  105. var referrer = document.createElement('a');
  106. referrer.href = document.referrer;
  107. text = '嗨!来自 <span style="color:#0099cc;">' + referrer.hostname + '</span> 的朋友!';
  108. var domain = referrer.hostname.split('.')[1];
  109. if (domain == 'baidu') {
  110. text = '嗨! 来自 百度搜索 的朋友!<br>欢迎访问<span style="color:#0099cc;">「 ' + document.title.split(' | ')[0] + ' 」</span>';
  111. } else if (domain == 'so') {
  112. text = '嗨! 来自 360搜索 的朋友!<br>欢迎访问<span style="color:#0099cc;">「 ' + document.title.split(' | ')[0] + ' 」</span>';
  113. } else if (domain == 'google') {
  114. text = '嗨! 来自 谷歌搜索 的朋友!<br>欢迎访问<span style="color:#0099cc;">「 ' + document.title.split(' | ')[0] + ' 」</span>';
  115. }
  116. } else {
  117. if (window.location.href == home_Path) { //主页URL判断,需要斜杠结尾
  118. var now = (new Date()).getHours();
  119. if (now > 23 || now <= 5) {
  120. text = '你是夜猫子呀?这么晚还不睡觉,明天起的来嘛?';
  121. } else if (now > 5 && now <= 7) {
  122. text = '早上好!一日之计在于晨,美好的一天就要开始了!';
  123. } else if (now > 7 && now <= 11) {
  124. text = '上午好!工作顺利嘛,不要久坐,多起来走动走动哦!';
  125. } else if (now > 11 && now <= 14) {
  126. text = '中午了,工作了一个上午,现在是午餐时间!';
  127. } else if (now > 14 && now <= 17) {
  128. text = '午后很容易犯困呢,今天的运动目标完成了吗?';
  129. } else if (now > 17 && now <= 19) {
  130. text = '傍晚了!窗外夕阳的景色很美丽呢,最美不过夕阳红~~';
  131. } else if (now > 19 && now <= 21) {
  132. text = '晚上好,今天过得怎么样?';
  133. } else if (now > 21 && now <= 23) {
  134. text = '已经这么晚了呀,早点休息吧,晚安~~';
  135. } else {
  136. text = '嗨~ 快来逗我玩吧!';
  137. }
  138. } else {
  139. text = '欢迎阅读<span style="color:#0099cc;">「 ' + document.title.split(' | ')[0] + ' 」</span>';
  140. }
  141. }
  142. showMessage(text, 12000);
  143. })();
  144. liveTlakTimer = setInterval(function () {
  145. showHitokoto();
  146. }, 15000);
  147. function showHitokoto() {
  148. if (sessionStorage.getItem("Sleepy") !== "1") {
  149. if (!AITalkFlag) {
  150. $.getJSON('https://hitokoto.mayx.eu.org/', function (result) {
  151. talkValTimer();
  152. showMessage(result.hitokoto, 0);
  153. });
  154. }
  155. } else {
  156. hideMessage(0);
  157. if (sleepTimer_ == null) {
  158. sleepTimer_ = setInterval(function () {
  159. checkSleep();
  160. }, 200);
  161. }
  162. console.log(sleepTimer_);
  163. }
  164. }
  165. function checkSleep() {
  166. var sleepStatu = sessionStorage.getItem("Sleepy");
  167. if (sleepStatu !== '1') {
  168. talkValTimer();
  169. showMessage('你回来啦~', 0);
  170. clearInterval(sleepTimer_);
  171. sleepTimer_ = null;
  172. }
  173. }
  174. function showMessage(text, timeout) {
  175. if (Array.isArray(text)) text = text[Math.floor(Math.random() * text.length + 1) - 1];
  176. //console.log('showMessage', text);
  177. $('.message').stop();
  178. if (text instanceof EventSource) {
  179. var outputContainer = $('.message')[0];
  180. var eventFlag = false;
  181. text.onmessage = function(event) {
  182. if (event.data == "[DONE]") {
  183. text.close();
  184. return;
  185. } else {
  186. if (!eventFlag) {
  187. talkValTimer();
  188. outputContainer.textContent = "";
  189. eventFlag = true;
  190. }
  191. var data = JSON.parse(event.data);
  192. outputContainer.textContent += data.response;
  193. }
  194. }
  195. } else {
  196. $('.message').html(text);
  197. }
  198. $('.message').fadeTo(200, 1);
  199. //if (timeout === null) timeout = 5000;
  200. //hideMessage(timeout);
  201. }
  202. function talkValTimer() {
  203. $('#live_talk').val('1');
  204. }
  205. function hideMessage(timeout) {
  206. //$('.message').stop().css('opacity',1);
  207. if (timeout === null) timeout = 5000;
  208. $('.message').delay(timeout).fadeTo(200, 0);
  209. }
  210. function initLive2d() {
  211. $("#landlord").mouseenter(function () {
  212. $(".live_ico_box").fadeIn();
  213. });
  214. $("#landlord").mouseleave(function () {
  215. $(".live_ico_box").fadeOut();
  216. });
  217. $('#hideButton').on('click', function () {
  218. if (AIFadeFlag) {
  219. return false;
  220. } else {
  221. AIFadeFlag = true;
  222. localStorage.setItem("live2dhidden", "0");
  223. $('#landlord').fadeOut(200);
  224. $('#open_live2d').delay(200).fadeIn(200);
  225. setTimeout(function () {
  226. AIFadeFlag = false;
  227. }, 300);
  228. }
  229. });
  230. $('#open_live2d').on('click', function () {
  231. if (AIFadeFlag) {
  232. return false;
  233. } else {
  234. AIFadeFlag = true;
  235. localStorage.setItem("live2dhidden", "1");
  236. $('#open_live2d').fadeOut(200);
  237. $('#landlord').delay(200).fadeIn(200);
  238. setTimeout(function () {
  239. AIFadeFlag = false;
  240. }, 300);
  241. }
  242. });
  243. $('#youduButton').on('click', function () {
  244. if ($('#youduButton').hasClass('doudong')) {
  245. var typeIs = $('#youduButton').attr('data-type');
  246. $('#youduButton').removeClass('doudong');
  247. $('body').removeClass(typeIs);
  248. $('#youduButton').attr('data-type', '');
  249. } else {
  250. var duType = $('#duType').val();
  251. var duArr = duType.split(",");
  252. var dataType = duArr[Math.floor(Math.random() * duArr.length)];
  253. $('#youduButton').addClass('doudong');
  254. $('#youduButton').attr('data-type', dataType);
  255. $('body').addClass(dataType);
  256. }
  257. });
  258. if (talkAPI !== "" && typeof EventSource !== 'undefined') {
  259. $('#showInfoBtn').on('click', function () {
  260. var live_statu = $('#live_statu_val').val();
  261. if (live_statu == "0") {
  262. return
  263. } else {
  264. $('#live_statu_val').val("0");
  265. $('.live_talk_input_body').fadeOut(500);
  266. AITalkFlag = false;
  267. showHitokoto();
  268. $('#showTalkBtn').show();
  269. $('#showInfoBtn').hide();
  270. }
  271. });
  272. $('#showTalkBtn').on('click', function () {
  273. var live_statu = $('#live_statu_val').val();
  274. if (live_statu == "1") {
  275. return
  276. } else {
  277. $('#live_statu_val').val("1");
  278. $('.live_talk_input_body').fadeIn(500);
  279. AITalkFlag = true;
  280. $('#showTalkBtn').hide();
  281. $('#showInfoBtn').show();
  282. }
  283. });
  284. $('#live_talk_input_form').on('submit', function (e) {
  285. e.preventDefault();
  286. var info_ = $('#AIuserText').val();
  287. // var userid_ = $('#AIuserName').val();
  288. let add_id = "";
  289. if ($('#load_this').prop("checked")) {
  290. add_id = "&id=" + encodeURIComponent($('#post_id').val());
  291. }
  292. if (info_ == "") {
  293. showMessage('写点什么吧!', 0);
  294. return;
  295. }
  296. showMessage('思考中~', 0);
  297. showMessage(new EventSource(talkAPI + "?info=" + encodeURIComponent(info_) + add_id));
  298. });
  299. } else {
  300. $('#showInfoBtn').hide();
  301. $('#showTalkBtn').hide();
  302. }
  303. //获取音乐信息初始化
  304. var bgmListInfo = $('input[name=live2dBGM]');
  305. if (bgmListInfo.length == 0) {
  306. $('#musicButton').hide();
  307. } else {
  308. var bgmPlayNow = parseInt($('#live2d_bgm').attr('data-bgm'));
  309. var bgmPlayTime = 0;
  310. var live2dBGM_Num = sessionStorage.getItem("live2dBGM_Num");
  311. var live2dBGM_PlayTime = sessionStorage.getItem("live2dBGM_PlayTime");
  312. if (live2dBGM_Num) {
  313. if (live2dBGM_Num <= $('input[name=live2dBGM]').length - 1) {
  314. bgmPlayNow = parseInt(live2dBGM_Num);
  315. }
  316. }
  317. if (live2dBGM_PlayTime) {
  318. bgmPlayTime = parseInt(live2dBGM_PlayTime);
  319. }
  320. var live2dBGMSrc = bgmListInfo.eq(bgmPlayNow).val();
  321. $('#live2d_bgm').attr('data-bgm', bgmPlayNow);
  322. $('#live2d_bgm').attr('src', live2dBGMSrc);
  323. $('#live2d_bgm')[0].currentTime = bgmPlayTime;
  324. $('#live2d_bgm')[0].volume = 0.5;
  325. var live2dBGM_IsPlay = sessionStorage.getItem("live2dBGM_IsPlay");
  326. var live2dBGM_WindowClose = sessionStorage.getItem("live2dBGM_WindowClose");
  327. if (live2dBGM_IsPlay == '0' && live2dBGM_WindowClose == '0') {
  328. $('#live2d_bgm')[0].play();
  329. $('#musicButton').addClass('play');
  330. }
  331. sessionStorage.setItem("live2dBGM_WindowClose", '1');
  332. $('#musicButton').on('click', function () {
  333. if ($('#musicButton').hasClass('play')) {
  334. $('#live2d_bgm')[0].pause();
  335. $('#musicButton').removeClass('play');
  336. sessionStorage.setItem("live2dBGM_IsPlay", '1');
  337. } else {
  338. $('#live2d_bgm')[0].play();
  339. $('#musicButton').addClass('play');
  340. sessionStorage.setItem("live2dBGM_IsPlay", '0');
  341. }
  342. });
  343. window.onbeforeunload = function () {
  344. sessionStorage.setItem("live2dBGM_WindowClose", '0');
  345. if ($('#musicButton').hasClass('play')) {
  346. sessionStorage.setItem("live2dBGM_IsPlay", '0');
  347. }
  348. }
  349. document.getElementById('live2d_bgm').addEventListener("timeupdate", function () {
  350. var live2dBgmPlayTimeNow = document.getElementById('live2d_bgm').currentTime;
  351. sessionStorage.setItem("live2dBGM_PlayTime", live2dBgmPlayTimeNow);
  352. });
  353. document.getElementById('live2d_bgm').addEventListener("ended", function () {
  354. var listNow = parseInt($('#live2d_bgm').attr('data-bgm'));
  355. listNow++;
  356. if (listNow > $('input[name=live2dBGM]').length - 1) {
  357. listNow = 0;
  358. }
  359. var listNewSrc = $('input[name=live2dBGM]').eq(listNow).val();
  360. sessionStorage.setItem("live2dBGM_Num", listNow);
  361. $('#live2d_bgm').attr('src', listNewSrc);
  362. $('#live2d_bgm')[0].play();
  363. $('#live2d_bgm').attr('data-bgm', listNow);
  364. });
  365. document.getElementById('live2d_bgm').addEventListener("error", function () {
  366. $('#live2d_bgm')[0].pause();
  367. $('#musicButton').removeClass('play');
  368. showMessage('音乐似乎加载不出来了呢!', 0);
  369. });
  370. }
  371. // //获取用户名
  372. // var live2dUser = sessionStorage.getItem("live2duser");
  373. // if(live2dUser !== null){
  374. // $('#AIuserName').val(live2dUser);
  375. // }
  376. //获取位置
  377. var landL = sessionStorage.getItem("historywidth");
  378. var landB = sessionStorage.getItem("historyheight");
  379. if (landL == null || landB == null) {
  380. landL = '5px'
  381. landB = '0px'
  382. }
  383. $('#landlord').css('left', landL + 'px');
  384. $('#landlord').css('bottom', landB + 'px');
  385. //移动
  386. function getEvent() {
  387. return window.event || arguments.callee.caller.arguments[0];
  388. }
  389. var smcc = document.getElementById("landlord");
  390. var moveX = 0;
  391. var moveY = 0;
  392. var moveBottom = 0;
  393. var moveLeft = 0;
  394. var moveable = false;
  395. var docMouseMoveEvent = document.onmousemove;
  396. var docMouseUpEvent = document.onmouseup;
  397. smcc.onmousedown = function () {
  398. var ent = getEvent();
  399. moveable = true;
  400. moveX = ent.clientX;
  401. moveY = ent.clientY;
  402. var obj = smcc;
  403. moveBottom = parseInt(obj.style.bottom);
  404. moveLeft = parseInt(obj.style.left);
  405. if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
  406. window.getSelection().removeAllRanges();
  407. }
  408. document.onmousemove = function () {
  409. if (moveable) {
  410. var ent = getEvent();
  411. var x = moveLeft + ent.clientX - moveX;
  412. var y = moveBottom + (moveY - ent.clientY);
  413. obj.style.left = x + "px";
  414. obj.style.bottom = y + "px";
  415. }
  416. };
  417. document.onmouseup = function () {
  418. if (moveable) {
  419. var historywidth = obj.style.left;
  420. var historyheight = obj.style.bottom;
  421. historywidth = historywidth.replace('px', '');
  422. historyheight = historyheight.replace('px', '');
  423. sessionStorage.setItem("historywidth", historywidth);
  424. sessionStorage.setItem("historyheight", historyheight);
  425. document.onmousemove = docMouseMoveEvent;
  426. document.onmouseup = docMouseUpEvent;
  427. moveable = false;
  428. moveX = 0;
  429. moveY = 0;
  430. moveBottom = 0;
  431. moveLeft = 0;
  432. }
  433. };
  434. };
  435. }
  436. $(document).ready(function () {
  437. var AIimgSrc = [
  438. home_Path + message_Path + "model/histoire/histoire.1024/texture_00.png",
  439. home_Path + message_Path + "model/histoire/histoire.1024/texture_01.png",
  440. home_Path + message_Path + "model/histoire/histoire.1024/texture_02.png",
  441. home_Path + message_Path + "model/histoire/histoire.1024/texture_03.png",
  442. home_Path + message_Path + "images/info.png",
  443. home_Path + message_Path + "images/music.png",
  444. home_Path + message_Path + "images/pasue.png",
  445. home_Path + message_Path + "images/quite.png",
  446. home_Path + message_Path + "images/talk.png",
  447. home_Path + message_Path + "images/youdu.png"
  448. ]
  449. var images = [];
  450. var imgLength = AIimgSrc.length;
  451. var loadingNum = 0;
  452. for (var i = 0; i < imgLength; i++) {
  453. images[i] = new Image();
  454. images[i].src = AIimgSrc[i];
  455. images[i].onload = function () {
  456. loadingNum++;
  457. if (loadingNum === imgLength) {
  458. var live2dhidden = localStorage.getItem("live2dhidden");
  459. if (live2dhidden === "0") {
  460. setTimeout(function () {
  461. $('#open_live2d').fadeIn(200);
  462. }, 1300);
  463. } else {
  464. setTimeout(function () {
  465. $('#landlord').fadeIn(200);
  466. }, 1300);
  467. }
  468. setTimeout(function () {
  469. loadlive2d("live2d", message_Path + "model/histoire/model.json");
  470. }, 1000);
  471. initLive2d();
  472. images = null;
  473. }
  474. }
  475. }
  476. });
  477. }

Powered by TurnKey Linux.