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.

506 lines
16 KiB

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

Powered by TurnKey Linux.