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.

498 lines
15 KiB

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('\\', '');
  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. 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.href == home_Path) { //主页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(text instanceof EventSource){
  178. var outputContainer = $('.message')[0]
  179. outputContainer.textContent = "";
  180. text.onmessage = (event) => {
  181. if (event.data == "[DONE]") {
  182. text.close();
  183. return;
  184. } else {
  185. const data = JSON.parse(event.data);
  186. outputContainer.textContent += data.response;
  187. }
  188. }
  189. }else{
  190. $('.message').html(text);
  191. }
  192. $('.message').fadeTo(200, 1);
  193. //if (timeout === null) timeout = 5000;
  194. //hideMessage(timeout);
  195. }
  196. function talkValTimer(){
  197. $('#live_talk').val('1');
  198. }
  199. function hideMessage(timeout){
  200. //$('.message').stop().css('opacity',1);
  201. if (timeout === null) timeout = 5000;
  202. $('.message').delay(timeout).fadeTo(200, 0);
  203. }
  204. function initLive2d (){
  205. $('#hideButton').on('click', function(){
  206. if(AIFadeFlag){
  207. return false;
  208. }else{
  209. AIFadeFlag = true;
  210. localStorage.setItem("live2dhidden", "0");
  211. $('#landlord').fadeOut(200);
  212. $('#open_live2d').delay(200).fadeIn(200);
  213. setTimeout(function(){
  214. AIFadeFlag = false;
  215. },300);
  216. }
  217. });
  218. $('#open_live2d').on('click', function(){
  219. if(AIFadeFlag){
  220. return false;
  221. }else{
  222. AIFadeFlag = true;
  223. localStorage.setItem("live2dhidden", "1");
  224. $('#open_live2d').fadeOut(200);
  225. $('#landlord').delay(200).fadeIn(200);
  226. setTimeout(function(){
  227. AIFadeFlag = false;
  228. },300);
  229. }
  230. });
  231. $('#youduButton').on('click',function(){
  232. if($('#youduButton').hasClass('doudong')){
  233. var typeIs = $('#youduButton').attr('data-type');
  234. $('#youduButton').removeClass('doudong');
  235. $('body').removeClass(typeIs);
  236. $('#youduButton').attr('data-type','');
  237. }else{
  238. var duType = $('#duType').val();
  239. var duArr = duType.split(",");
  240. var dataType = duArr[Math.floor(Math.random() * duArr.length)];
  241. $('#youduButton').addClass('doudong');
  242. $('#youduButton').attr('data-type',dataType);
  243. $('body').addClass(dataType);
  244. }
  245. });
  246. if(talkAPI!==""){
  247. $('#showInfoBtn').on('click',function(){
  248. var live_statu = $('#live_statu_val').val();
  249. if(live_statu=="0"){
  250. return
  251. }else{
  252. $('#live_statu_val').val("0");
  253. $('.live_talk_input_body').fadeOut(500);
  254. AITalkFlag = false;
  255. showHitokoto();
  256. $('#showTalkBtn').show();
  257. $('#showInfoBtn').hide();
  258. }
  259. });
  260. $('#showTalkBtn').on('click',function(){
  261. var live_statu = $('#live_statu_val').val();
  262. if(live_statu=="1"){
  263. return
  264. }else{
  265. $('#live_statu_val').val("1");
  266. $('.live_talk_input_body').fadeIn(500);
  267. AITalkFlag = true;
  268. $('#showTalkBtn').hide();
  269. $('#showInfoBtn').show();
  270. }
  271. });
  272. $('#talk_send').on('click',function(){
  273. var info_ = $('#AIuserText').val();
  274. // var userid_ = $('#AIuserName').val();
  275. if(info_ == "" ){
  276. showMessage('写点什么吧!',0);
  277. return;
  278. }
  279. // if(userid_ == ""){
  280. // showMessage('聊之前请告诉我你的名字吧!',0);
  281. // return;
  282. // }
  283. showMessage('思考中~', 0);
  284. const evSource = new EventSource(talkAPI + "?info=" + encodeURIComponent(info_));
  285. showMessage(evSource);
  286. // $.ajax({
  287. // type: 'POST',
  288. // url: talkAPI,
  289. // data: {
  290. // "info": info_,
  291. // "userId": userid_
  292. // },
  293. // success: function(res) {
  294. // if(res.intent.code !== 0){
  295. // talkValTimer();
  296. // showMessage('似乎有什么错误,请和站长联系!',0);
  297. // }else{
  298. // talkValTimer();
  299. // showMessage(res.results[0].values.text,0);
  300. // }
  301. // console.log(res);
  302. // $('#AIuserText').val("");
  303. // sessionStorage.setItem("live2duser", userid_);
  304. // }
  305. // });
  306. });
  307. }else{
  308. $('#showInfoBtn').hide();
  309. $('#showTalkBtn').hide();
  310. }
  311. //获取音乐信息初始化
  312. var bgmListInfo = $('input[name=live2dBGM]');
  313. if(bgmListInfo.length == 0){
  314. $('#musicButton').hide();
  315. }else{
  316. var bgmPlayNow = parseInt($('#live2d_bgm').attr('data-bgm'));
  317. var bgmPlayTime = 0;
  318. var live2dBGM_Num = sessionStorage.getItem("live2dBGM_Num");
  319. var live2dBGM_PlayTime = sessionStorage.getItem("live2dBGM_PlayTime");
  320. if(live2dBGM_Num){
  321. if(live2dBGM_Num<=$('input[name=live2dBGM]').length-1){
  322. bgmPlayNow = parseInt(live2dBGM_Num);
  323. }
  324. }
  325. if(live2dBGM_PlayTime){
  326. bgmPlayTime = parseInt(live2dBGM_PlayTime);
  327. }
  328. var live2dBGMSrc = bgmListInfo.eq(bgmPlayNow).val();
  329. $('#live2d_bgm').attr('data-bgm',bgmPlayNow);
  330. $('#live2d_bgm').attr('src',live2dBGMSrc);
  331. $('#live2d_bgm')[0].currentTime = bgmPlayTime;
  332. $('#live2d_bgm')[0].volume = 0.5;
  333. var live2dBGM_IsPlay = sessionStorage.getItem("live2dBGM_IsPlay");
  334. var live2dBGM_WindowClose = sessionStorage.getItem("live2dBGM_WindowClose");
  335. if(live2dBGM_IsPlay == '0' && live2dBGM_WindowClose == '0'){
  336. $('#live2d_bgm')[0].play();
  337. $('#musicButton').addClass('play');
  338. }
  339. sessionStorage.setItem("live2dBGM_WindowClose" , '1');
  340. $('#musicButton').on('click',function(){
  341. if($('#musicButton').hasClass('play')){
  342. $('#live2d_bgm')[0].pause();
  343. $('#musicButton').removeClass('play');
  344. sessionStorage.setItem("live2dBGM_IsPlay",'1');
  345. }else{
  346. $('#live2d_bgm')[0].play();
  347. $('#musicButton').addClass('play');
  348. sessionStorage.setItem("live2dBGM_IsPlay",'0');
  349. }
  350. });
  351. window.onbeforeunload = function(){
  352. sessionStorage.setItem("live2dBGM_WindowClose" , '0');
  353. if($('#musicButton').hasClass('play')){
  354. sessionStorage.setItem("live2dBGM_IsPlay",'0');
  355. }
  356. }
  357. document.getElementById('live2d_bgm').addEventListener("timeupdate", function(){
  358. var live2dBgmPlayTimeNow = document.getElementById('live2d_bgm').currentTime;
  359. sessionStorage.setItem("live2dBGM_PlayTime" , live2dBgmPlayTimeNow );
  360. });
  361. document.getElementById('live2d_bgm').addEventListener("ended", function(){
  362. var listNow = parseInt($('#live2d_bgm').attr('data-bgm'));
  363. listNow ++ ;
  364. if(listNow > $('input[name=live2dBGM]').length-1){
  365. listNow = 0;
  366. }
  367. var listNewSrc = $('input[name=live2dBGM]').eq(listNow).val();
  368. sessionStorage.setItem("live2dBGM_Num",listNow);
  369. $('#live2d_bgm').attr('src',listNewSrc);
  370. $('#live2d_bgm')[0].play();
  371. $('#live2d_bgm').attr('data-bgm',listNow);
  372. });
  373. document.getElementById('live2d_bgm').addEventListener("error", function(){
  374. $('#live2d_bgm')[0].pause();
  375. $('#musicButton').removeClass('play');
  376. showMessage('音乐似乎加载不出来了呢!',0);
  377. });
  378. }
  379. //获取用户名
  380. var live2dUser = sessionStorage.getItem("live2duser");
  381. if(live2dUser !== null){
  382. $('#AIuserName').val(live2dUser);
  383. }
  384. //获取位置
  385. var landL = sessionStorage.getItem("historywidth");
  386. var landB = sessionStorage.getItem("historyheight");
  387. if(landL == null || landB ==null){
  388. landL = '5px'
  389. landB = '0px'
  390. }
  391. $('#landlord').css('left',landL+'px');
  392. $('#landlord').css('bottom',landB + 'px');
  393. //移动
  394. function getEvent() {
  395. return window.event || arguments.callee.caller.arguments[0];
  396. }
  397. var smcc = document.getElementById("landlord");
  398. var moveX = 0;
  399. var moveY = 0;
  400. var moveBottom = 0;
  401. var moveLeft = 0;
  402. var moveable = false;
  403. var docMouseMoveEvent = document.onmousemove;
  404. var docMouseUpEvent = document.onmouseup;
  405. smcc.onmousedown = function(){
  406. var ent = getEvent();
  407. moveable = true;
  408. moveX = ent.clientX;
  409. moveY = ent.clientY;
  410. var obj = smcc;
  411. moveBottom = parseInt(obj.style.bottom);
  412. moveLeft = parseInt(obj.style.left);
  413. if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
  414. window.getSelection().removeAllRanges();
  415. }
  416. document.onmousemove = function(){
  417. if(moveable){
  418. var ent = getEvent();
  419. var x = moveLeft + ent.clientX - moveX;
  420. var y = moveBottom + (moveY - ent.clientY);
  421. obj.style.left = x + "px";
  422. obj.style.bottom = y + "px";
  423. }
  424. };
  425. document.onmouseup = function(){
  426. if(moveable){
  427. var historywidth = obj.style.left;
  428. var historyheight = obj.style.bottom;
  429. historywidth = historywidth.replace('px', '');
  430. historyheight = historyheight.replace('px', '');
  431. sessionStorage.setItem("historywidth", historywidth);
  432. sessionStorage.setItem("historyheight", historyheight);
  433. document.onmousemove = docMouseMoveEvent;
  434. document.onmouseup = docMouseUpEvent;
  435. moveable = false;
  436. moveX = 0;
  437. moveY = 0;
  438. moveBottom = 0;
  439. moveLeft = 0;
  440. }
  441. };
  442. };
  443. }
  444. $(document).ready(function() {
  445. var AIimgSrc = [
  446. home_Path + message_Path + "model/histoire/histoire.1024/texture_00.png",
  447. home_Path + message_Path + "model/histoire/histoire.1024/texture_01.png",
  448. home_Path + message_Path + "model/histoire/histoire.1024/texture_02.png",
  449. home_Path + message_Path + "model/histoire/histoire.1024/texture_03.png"
  450. ]
  451. var images = [];
  452. var imgLength = AIimgSrc.length;
  453. var loadingNum = 0;
  454. for(var i=0;i<imgLength;i++){
  455. images[i] = new Image();
  456. images[i].src = AIimgSrc[i];
  457. images[i].onload = function(){
  458. loadingNum++;
  459. if(loadingNum===imgLength){
  460. var live2dhidden = localStorage.getItem("live2dhidden");
  461. if(live2dhidden==="0"){
  462. setTimeout(function(){
  463. $('#open_live2d').fadeIn(200);
  464. },1300);
  465. }else{
  466. setTimeout(function(){
  467. $('#landlord').fadeIn(200);
  468. },1300);
  469. }
  470. setTimeout(function(){
  471. loadlive2d("live2d", message_Path+"model/histoire/model.json");
  472. },1000);
  473. initLive2d ();
  474. images = null;
  475. }
  476. }
  477. }
  478. });
  479. }

Powered by TurnKey Linux.