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.

490 lines
15 KiB

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://v1.hitokoto.cn/',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. $('.message').html(text);
  178. $('.message').fadeTo(200, 1);
  179. //if (timeout === null) timeout = 5000;
  180. //hideMessage(timeout);
  181. }
  182. function talkValTimer(){
  183. $('#live_talk').val('1');
  184. }
  185. function hideMessage(timeout){
  186. //$('.message').stop().css('opacity',1);
  187. if (timeout === null) timeout = 5000;
  188. $('.message').delay(timeout).fadeTo(200, 0);
  189. }
  190. function initLive2d (){
  191. $('#hideButton').on('click', function(){
  192. if(AIFadeFlag){
  193. return false;
  194. }else{
  195. AIFadeFlag = true;
  196. localStorage.setItem("live2dhidden", "0");
  197. $('#landlord').fadeOut(200);
  198. $('#open_live2d').delay(200).fadeIn(200);
  199. setTimeout(function(){
  200. AIFadeFlag = false;
  201. },300);
  202. }
  203. });
  204. $('#open_live2d').on('click', function(){
  205. if(AIFadeFlag){
  206. return false;
  207. }else{
  208. AIFadeFlag = true;
  209. localStorage.setItem("live2dhidden", "1");
  210. $('#open_live2d').fadeOut(200);
  211. $('#landlord').delay(200).fadeIn(200);
  212. setTimeout(function(){
  213. AIFadeFlag = false;
  214. },300);
  215. }
  216. });
  217. $('#youduButton').on('click',function(){
  218. if($('#youduButton').hasClass('doudong')){
  219. var typeIs = $('#youduButton').attr('data-type');
  220. $('#youduButton').removeClass('doudong');
  221. $('body').removeClass(typeIs);
  222. $('#youduButton').attr('data-type','');
  223. }else{
  224. var duType = $('#duType').val();
  225. var duArr = duType.split(",");
  226. var dataType = duArr[Math.floor(Math.random() * duArr.length)];
  227. $('#youduButton').addClass('doudong');
  228. $('#youduButton').attr('data-type',dataType);
  229. $('body').addClass(dataType);
  230. }
  231. });
  232. if(talkAPI!==""){
  233. $('#showInfoBtn').on('click',function(){
  234. var live_statu = $('#live_statu_val').val();
  235. if(live_statu=="0"){
  236. return
  237. }else{
  238. $('#live_statu_val').val("0");
  239. $('.live_talk_input_body').fadeOut(500);
  240. AITalkFlag = false;
  241. showHitokoto();
  242. $('#showTalkBtn').show();
  243. $('#showInfoBtn').hide();
  244. }
  245. });
  246. $('#showTalkBtn').on('click',function(){
  247. var live_statu = $('#live_statu_val').val();
  248. if(live_statu=="1"){
  249. return
  250. }else{
  251. $('#live_statu_val').val("1");
  252. $('.live_talk_input_body').fadeIn(500);
  253. AITalkFlag = true;
  254. $('#showTalkBtn').hide();
  255. $('#showInfoBtn').show();
  256. }
  257. });
  258. $('#talk_send').on('click',function(){
  259. var info_ = $('#AIuserText').val();
  260. var userid_ = $('#AIuserName').val();
  261. if(info_ == "" ){
  262. showMessage('写点什么吧!',0);
  263. return;
  264. }
  265. if(userid_ == ""){
  266. showMessage('聊之前请告诉我你的名字吧!',0);
  267. return;
  268. }
  269. showMessage('思考中~', 0);
  270. $.ajax({
  271. type: 'POST',
  272. url: "https://www.tuling123.com/openapi/api",
  273. data: {
  274. "reqType":0,
  275. "perception": {
  276. "inputText": {
  277. "text": info_
  278. }
  279. },
  280. "userInfo": {
  281. "apiKey": "ae8933884bcc4bac96289a43d8a864db",
  282. "userId": userid_
  283. }
  284. },
  285. success: function(res) {
  286. if(res.intent.code !== 0){
  287. talkValTimer();
  288. showMessage('似乎有什么错误,请和站长联系!',0);
  289. }else{
  290. talkValTimer();
  291. showMessage(res.results[0].values.text,0);
  292. }
  293. console.log(res);
  294. $('#AIuserText').val("");
  295. sessionStorage.setItem("live2duser", userid_);
  296. }
  297. });
  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. ]
  443. var images = [];
  444. var imgLength = AIimgSrc.length;
  445. var loadingNum = 0;
  446. for(var i=0;i<imgLength;i++){
  447. images[i] = new Image();
  448. images[i].src = AIimgSrc[i];
  449. images[i].onload = function(){
  450. loadingNum++;
  451. if(loadingNum===imgLength){
  452. var live2dhidden = localStorage.getItem("live2dhidden");
  453. if(live2dhidden==="0"){
  454. setTimeout(function(){
  455. $('#open_live2d').fadeIn(200);
  456. },1300);
  457. }else{
  458. setTimeout(function(){
  459. $('#landlord').fadeIn(200);
  460. },1300);
  461. }
  462. setTimeout(function(){
  463. loadlive2d("live2d", message_Path+"model/histoire/model.json");
  464. },1000);
  465. initLive2d ();
  466. images = null;
  467. }
  468. }
  469. }
  470. });
  471. }

Powered by TurnKey Linux.