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.

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