waifu-tips.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. window.live2d_settings = Array(); /*
  2. く__,.ヘヽ.    / ,ー、 〉
  3.      \ ', !-─‐-i / /´
  4.       /`ー'    L//`ヽ、 Live2D 看板娘 参数设置
  5.      /  /,  /|  ,  ,    ', Version 1.4.2
  6.    イ  / /-‐/ i L_ ハ ヽ!  i Update 2018.11.12
  7.     レ ヘ 7イ`ト  レ'ァ-ト、!ハ|  |
  8.      !,/7 '0'   ´0iソ|   |   
  9.      |.从"  _   ,,,, / |./   | 网页添加 Live2D 看板娘
  10.      レ'| i>.、,,__ _,.イ /  .i  | https://www.fghrsh.net/post/123.html
  11.       レ'| | / k_7_/レ'ヽ, ハ. |
  12.        | |/i 〈|/  i ,.ヘ | i | Thanks
  13.       .|/ / i:   ヘ!  \ | journey-ad / https://github.com/journey-ad/live2d_src
  14.         kヽ>、ハ   _,.ヘ、   /、! xiazeyu / https://github.com/xiazeyu/live2d-widget.js
  15.        !'〈//`T´', \ `'7'ーr' Live2d Cubism SDK WebGL 2.1 Projrct & All model authors.
  16.        レ'ヽL__|___i,___,ンレ|ノ
  17.          ト-,/ |___./
  18.          'ー'  !_,.:*********************************************************************************/
  19. // 后端接口
  20. live2d_settings['modelAPI'] = '//live2d.fghrsh.net/api/'; // 自建 API 修改这里
  21. live2d_settings['tipsMessage'] = 'waifu-tips.json'; // 同目录下可省略路径
  22. live2d_settings['hitokotoAPI'] = 'lwl12.com'; // 一言 API,可选 'lwl12.com', 'hitokoto.cn', 'jinrishici.com'(古诗词)
  23. // 默认模型
  24. live2d_settings['modelId'] = 1; // 默认模型 ID,可在 F12 控制台找到
  25. live2d_settings['modelTexturesId'] = 53; // 默认材质 ID,可在 F12 控制台找到
  26. // 工具栏设置
  27. live2d_settings['showToolMenu'] = true; // 显示 工具栏 ,可选 true(真), false(假)
  28. live2d_settings['canCloseLive2d'] = true; // 显示 关闭看板娘 按钮,可选 true(真), false(假)
  29. live2d_settings['canSwitchModel'] = true; // 显示 模型切换 按钮,可选 true(真), false(假)
  30. live2d_settings['canSwitchTextures'] = true; // 显示 材质切换 按钮,可选 true(真), false(假)
  31. live2d_settings['canSwitchHitokoto'] = true; // 显示 一言切换 按钮,可选 true(真), false(假)
  32. live2d_settings['canTakeScreenshot'] = true; // 显示 看板娘截图 按钮,可选 true(真), false(假)
  33. live2d_settings['canTurnToHomePage'] = true; // 显示 返回首页 按钮,可选 true(真), false(假)
  34. live2d_settings['canTurnToAboutPage'] = true; // 显示 跳转关于页 按钮,可选 true(真), false(假)
  35. // 模型切换模式
  36. live2d_settings['modelStorage'] = true; // 记录 ID (刷新后恢复),可选 true(真), false(假)
  37. live2d_settings['modelRandMode'] = 'switch'; // 模型切换,可选 'rand'(随机), 'switch'(顺序)
  38. live2d_settings['modelTexturesRandMode']= 'rand'; // 材质切换,可选 'rand'(随机), 'switch'(顺序)
  39. // 提示消息选项
  40. live2d_settings['showHitokoto'] = true; // 显示一言
  41. live2d_settings['showF12Status'] = true; // 显示加载状态
  42. live2d_settings['showF12Message'] = false; // 显示看板娘消息
  43. live2d_settings['showF12OpenMsg'] = true; // 显示控制台打开提示
  44. live2d_settings['showCopyMessage'] = true; // 显示 复制内容 提示
  45. live2d_settings['showWelcomeMessage'] = true; // 显示进入面页欢迎词
  46. //看板娘样式设置
  47. live2d_settings['waifuSize'] = '280x250'; // 看板娘大小,例如 '280x250', '600x535'
  48. live2d_settings['waifuTipsSize'] = '250x70'; // 提示框大小,例如 '250x70', '570x150'
  49. live2d_settings['waifuFontSize'] = '12px'; // 提示框字体,例如 '12px', '30px'
  50. live2d_settings['waifuToolFont'] = '14px'; // 工具栏字体,例如 '14px', '36px'
  51. live2d_settings['waifuToolLine'] = '20px'; // 工具栏行高,例如 '20px', '36px'
  52. live2d_settings['waifuToolTop'] = '0px' // 工具栏顶部边距,例如 '0px', '-60px'
  53. live2d_settings['waifuMinWidth'] = '768px'; // 面页小于 指定宽度 隐藏看板娘,例如 'disable'(禁用), '768px'
  54. live2d_settings['waifuEdgeSide'] = 'left:0'; // 看板娘贴边方向,例如 'left:0'(靠左 0px), 'right:30'(靠右 30px)
  55. live2d_settings['waifuDraggable'] = 'disable'; // 拖拽样式,例如 'disable'(禁用), 'axis-x'(只能水平拖拽), 'unlimited'(自由拖拽)
  56. live2d_settings['waifuDraggableRevert'] = true; // 松开鼠标还原拖拽位置,可选 true(真), false(假)
  57. // 其他杂项设置
  58. live2d_settings['l2dVersion'] = '1.4.2'; // 当前版本
  59. live2d_settings['l2dVerDate'] = '2018.11.12'; // 版本更新日期
  60. live2d_settings['homePageUrl'] = 'auto'; // 主页地址,可选 'auto'(自动), '{URL 网址}'
  61. live2d_settings['aboutPageUrl'] = 'https://www.fghrsh.net/post/123.html'; // 关于页地址, '{URL 网址}'
  62. live2d_settings['screenshotCaptureName']= 'live2d.png'; // 看板娘截图文件名,例如 'live2d.png'
  63. /****************************************************************************************************/
  64. String.prototype.render = function(context) {
  65. var tokenReg = /(\\)?\{([^\{\}\\]+)(\\)?\}/g;
  66. return this.replace(tokenReg, function (word, slash1, token, slash2) {
  67. if (slash1 || slash2) { return word.replace('\\', ''); }
  68. var variables = token.replace(/\s/g, '').split('.');
  69. var currentObject = context;
  70. var i, length, variable;
  71. for (i = 0, length = variables.length; i < length; ++i) {
  72. variable = variables[i];
  73. currentObject = currentObject[variable];
  74. if (currentObject === undefined || currentObject === null) return '';
  75. }
  76. return currentObject;
  77. });
  78. };
  79. var re = /x/;
  80. console.log(re);
  81. function empty(obj) {return typeof obj=="undefined"||obj==null||obj==""?true:false}
  82. function getRandText(text) {return Array.isArray(text) ? text[Math.floor(Math.random() * text.length + 1)-1] : text}
  83. function showMessage(text, timeout, flag) {
  84. if(flag || sessionStorage.getItem('waifu-text') === '' || sessionStorage.getItem('waifu-text') === null){
  85. if(Array.isArray(text)) text = text[Math.floor(Math.random() * text.length + 1)-1];
  86. if (live2d_settings.showF12Message) console.log('[Message]', text.replace(/<[^<>]+>/g,''));
  87. if(flag) sessionStorage.setItem('waifu-text', text);
  88. $('.waifu-tips').stop();
  89. $('.waifu-tips').html(text).fadeTo(200, 1);
  90. if (timeout === undefined) timeout = 5000;
  91. hideMessage(timeout);
  92. }
  93. }
  94. function hideMessage(timeout) {
  95. $('.waifu-tips').stop().css('opacity',1);
  96. if (timeout === undefined) timeout = 5000;
  97. window.setTimeout(function() {sessionStorage.removeItem('waifu-text')}, timeout);
  98. $('.waifu-tips').delay(timeout).fadeTo(200, 0);
  99. }
  100. function initModel(waifuPath, type) {
  101. /* console welcome message */
  102. eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('8.d(" ");8.d("\\U,.\\y\\5.\\1\\1\\1\\1/\\1,\\u\\2 \\H\\n\\1\\1\\1\\1\\1\\b \', !-\\r\\j-i\\1/\\1/\\g\\n\\1\\1\\1 \\1 \\a\\4\\f\'\\1\\1\\1 L/\\a\\4\\5\\2\\n\\1\\1 \\1 /\\1 \\a,\\1 /|\\1 ,\\1 ,\\1\\1\\1 \',\\n\\1\\1\\1\\q \\1/ /-\\j/\\1\\h\\E \\9 \\5!\\1 i\\n\\1\\1\\1 \\3 \\6 7\\q\\4\\c\\1 \\3\'\\s-\\c\\2!\\t|\\1 |\\n\\1\\1\\1\\1 !,/7 \'0\'\\1\\1 \\X\\w| \\1 |\\1\\1\\1\\n\\1\\1\\1\\1 |.\\x\\"\\1\\l\\1\\1 ,,,, / |./ \\1 |\\n\\1\\1\\1\\1 \\3\'| i\\z.\\2,,A\\l,.\\B / \\1.i \\1|\\n\\1\\1\\1\\1\\1 \\3\'| | / C\\D/\\3\'\\5,\\1\\9.\\1|\\n\\1\\1\\1\\1\\1\\1 | |/i \\m|/\\1 i\\1,.\\6 |\\F\\1|\\n\\1\\1\\1\\1\\1\\1.|/ /\\1\\h\\G \\1 \\6!\\1\\1\\b\\1|\\n\\1\\1\\1 \\1 \\1 k\\5>\\2\\9 \\1 o,.\\6\\2 \\1 /\\2!\\n\\1\\1\\1\\1\\1\\1 !\'\\m//\\4\\I\\g\', \\b \\4\'7\'\\J\'\\n\\1\\1\\1\\1\\1\\1 \\3\'\\K|M,p,\\O\\3|\\P\\n\\1\\1\\1\\1\\1 \\1\\1\\1\\c-,/\\1|p./\\n\\1\\1\\1\\1\\1 \\1\\1\\1\'\\f\'\\1\\1!o,.:\\Q \\R\\S\\T v"+e.V+" / W "+e.N);8.d(" ");',60,60,'|u3000|uff64|uff9a|uff40|u30fd|uff8d||console|uff8a|uff0f|uff3c|uff84|log|live2d_settings|uff70|u00b4|uff49||u2010||u3000_|u3008||_|___|uff72|u2500|uff67|u30cf|u30fc||u30bd|u4ece|u30d8|uff1e|__|u30a4|k_|uff17_|u3000L_|u3000i|uff1a|u3009|uff34|uff70r|u30fdL__||___i|l2dVerDate|u30f3|u30ce|nLive2D|u770b|u677f|u5a18|u304f__|l2dVersion|FGHRSH|u00b40i'.split('|'),0,{}));
  103. /* 判断 JQuery */
  104. if (typeof($.ajax) != 'function') typeof(jQuery.ajax) == 'function' ? window.$ = jQuery : console.log('[Error] JQuery is not defined.');
  105. /* 加载看板娘样式 */
  106. live2d_settings.waifuSize = live2d_settings.waifuSize.split('x');
  107. live2d_settings.waifuTipsSize = live2d_settings.waifuTipsSize.split('x');
  108. live2d_settings.waifuEdgeSide = live2d_settings.waifuEdgeSide.split(':');
  109. $("#live2d").attr("width",live2d_settings.waifuSize[0]);
  110. $("#live2d").attr("height",live2d_settings.waifuSize[1]);
  111. $(".waifu-tips").width(live2d_settings.waifuTipsSize[0]);
  112. $(".waifu-tips").height(live2d_settings.waifuTipsSize[1]);
  113. $(".waifu-tips").css("top",live2d_settings.waifuToolTop);
  114. $(".waifu-tips").css("font-size",live2d_settings.waifuFontSize);
  115. $(".waifu-tool").css("font-size",live2d_settings.waifuToolFont);
  116. $(".waifu-tool span").css("line-height",live2d_settings.waifuToolLine);
  117. if (live2d_settings.waifuEdgeSide[0] == 'left') $(".waifu").css("left",live2d_settings.waifuEdgeSide[1]+'px');
  118. else if (live2d_settings.waifuEdgeSide[0] == 'right') $(".waifu").css("right",live2d_settings.waifuEdgeSide[1]+'px');
  119. window.waifuResize = function() { $(window).width() <= Number(live2d_settings.waifuMinWidth.replace('px','')) ? $(".waifu").hide() : $(".waifu").show(); };
  120. if (live2d_settings.waifuMinWidth != 'disable') { waifuResize(); $(window).resize(function() {waifuResize()}); }
  121. try {
  122. if (live2d_settings.waifuDraggable == 'axis-x') $(".waifu").draggable({ axis: "x", revert: live2d_settings.waifuDraggableRevert });
  123. else if (live2d_settings.waifuDraggable == 'unlimited') $(".waifu").draggable({ revert: live2d_settings.waifuDraggableRevert });
  124. else $(".waifu").css("transition", 'all .3s ease-in-out');
  125. } catch(err) { console.log('[Error] JQuery UI is not defined.') }
  126. live2d_settings.homePageUrl == 'auto' ? window.location.protocol+'//'+window.location.hostname+'/' : live2d_settings.homePageUrl;
  127. if (window.location.protocol == 'file:' && live2d_settings.modelAPI.substr(0,2) == '//') live2d_settings.modelAPI = 'http:'+live2d_settings.modelAPI;
  128. $('.waifu-tool .fui-home').click(function (){
  129. //window.location = 'https://www.fghrsh.net/';
  130. window.location = live2d_settings.homePageUrl;
  131. });
  132. $('.waifu-tool .fui-info-circle').click(function (){
  133. //window.open('https://imjad.cn/archives/lab/add-dynamic-poster-girl-with-live2d-to-your-blog-02');
  134. window.open(live2d_settings.aboutPageUrl);
  135. });
  136. if (typeof(waifuPath) == "object") loadTipsMessage(waifuPath); else {
  137. $.ajax({
  138. cache: true,
  139. url: waifuPath == '' ? live2d_settings.tipsMessage : (waifuPath.substr(waifuPath.length-15)=='waifu-tips.json'?waifuPath:waifuPath+'waifu-tips.json'),
  140. dataType: "json",
  141. success: function (result){ loadTipsMessage(result); }
  142. });
  143. }
  144. if (!live2d_settings.showToolMenu) $('.waifu-tool').hide();
  145. if (!live2d_settings.canCloseLive2d) $('.waifu-tool .fui-cross').hide();
  146. if (!live2d_settings.canSwitchModel) $('.waifu-tool .fui-eye').hide();
  147. if (!live2d_settings.canSwitchTextures) $('.waifu-tool .fui-user').hide();
  148. if (!live2d_settings.canSwitchHitokoto) $('.waifu-tool .fui-chat').hide();
  149. if (!live2d_settings.canTakeScreenshot) $('.waifu-tool .fui-photo').hide();
  150. if (!live2d_settings.canTurnToHomePage) $('.waifu-tool .fui-home').hide();
  151. if (!live2d_settings.canTurnToAboutPage) $('.waifu-tool .fui-info-circle').hide();
  152. if (waifuPath === undefined) waifuPath = '';
  153. var modelId = localStorage.getItem('modelId');
  154. var modelTexturesId = localStorage.getItem('modelTexturesId');
  155. if (!live2d_settings.modelStorage || modelId == null) {
  156. var modelId = live2d_settings.modelId;
  157. var modelTexturesId = live2d_settings.modelTexturesId;
  158. } loadModel(modelId, modelTexturesId);
  159. }
  160. function loadModel(modelId, modelTexturesId=0) {
  161. if (live2d_settings.modelStorage) {
  162. localStorage.setItem('modelId', modelId);
  163. localStorage.setItem('modelTexturesId', modelTexturesId);
  164. } else {
  165. sessionStorage.setItem('modelId', modelId);
  166. sessionStorage.setItem('modelTexturesId', modelTexturesId);
  167. } loadlive2d('live2d', live2d_settings.modelAPI+'get/?id='+modelId+'-'+modelTexturesId, (live2d_settings.showF12Status ? console.log('[Status]','live2d','模型',modelId+'-'+modelTexturesId,'加载完成'):null));
  168. }
  169. function loadTipsMessage(result) {
  170. window.waifu_tips = result;
  171. $.each(result.mouseover, function (index, tips){
  172. $(document).on("mouseover", tips.selector, function (){
  173. var text = getRandText(tips.text);
  174. text = text.render({text: $(this).text()});
  175. showMessage(text, 3000);
  176. });
  177. });
  178. $.each(result.click, function (index, tips){
  179. $(document).on("click", tips.selector, function (){
  180. var text = getRandText(tips.text);
  181. text = text.render({text: $(this).text()});
  182. showMessage(text, 3000, true);
  183. });
  184. });
  185. $.each(result.seasons, function (index, tips){
  186. var now = new Date();
  187. var after = tips.date.split('-')[0];
  188. var before = tips.date.split('-')[1] || after;
  189. if((after.split('/')[0] <= now.getMonth()+1 && now.getMonth()+1 <= before.split('/')[0]) &&
  190. (after.split('/')[1] <= now.getDate() && now.getDate() <= before.split('/')[1])){
  191. var text = getRandText(tips.text);
  192. text = text.render({year: now.getFullYear()});
  193. showMessage(text, 6000, true);
  194. }
  195. });
  196. if (live2d_settings.showF12OpenMsg) {
  197. re.toString = function() {
  198. showMessage(getRandText(result.waifu.console_open_msg), 5000, true);
  199. return '';
  200. };
  201. }
  202. if (live2d_settings.showCopyMessage) {
  203. $(document).on('copy', function() {
  204. showMessage(getRandText(result.waifu.copy_message), 5000, true);
  205. });
  206. }
  207. $('.waifu-tool .fui-photo').click(function(){
  208. showMessage(getRandText(result.waifu.screenshot_message), 5000, true);
  209. window.Live2D.captureName = live2d_settings.screenshotCaptureName;
  210. window.Live2D.captureFrame = true;
  211. });
  212. $('.waifu-tool .fui-cross').click(function(){
  213. sessionStorage.setItem('waifu-dsiplay', 'none');
  214. showMessage(getRandText(result.waifu.hidden_message), 1300, true);
  215. window.setTimeout(function() {$('.waifu').hide();}, 1300);
  216. });
  217. window.showWelcomeMessage = function(result) {
  218. var text;
  219. if (window.location.href == live2d_settings.homePageUrl) {
  220. var now = (new Date()).getHours();
  221. if (now > 23 || now <= 5) text = getRandText(result.waifu.hour_tips.t23-5);
  222. else if (now > 5 && now <= 7) text = getRandText(result.waifu.hour_tips.t5-7);
  223. else if (now > 7 && now <= 11) text = getRandText(result.waifu.hour_tips.t7-11);
  224. else if (now > 11 && now <= 14) text = getRandText(result.waifu.hour_tips.t11-14);
  225. else if (now > 14 && now <= 17) text = getRandText(result.waifu.hour_tips.t14-17);
  226. else if (now > 17 && now <= 19) text = getRandText(result.waifu.hour_tips.t17-19);
  227. else if (now > 19 && now <= 21) text = getRandText(result.waifu.hour_tips.t19-21);
  228. else if (now > 21 && now <= 23) text = getRandText(result.waifu.hour_tips.t21-23);
  229. else text = getRandText(result.waifu.hour_tips.default);
  230. } else {
  231. var referrer_message = result.waifu.referrer_message;
  232. if (document.referrer !== '') {
  233. var referrer = document.createElement('a');
  234. referrer.href = document.referrer;
  235. var domain = referrer.hostname.split('.')[1];
  236. if (window.location.hostname == referrer.hostname)
  237. text = referrer_message.localhost[0] + document.title.split(referrer_message.localhost[2])[0] + referrer_message.localhost[1];
  238. else if (domain == 'baidu')
  239. text = referrer_message.baidu[0] + referrer.search.split('&wd=')[1].split('&')[0] + referrer_message.baidu[1];
  240. else if (domain == 'so')
  241. text = referrer_message.so[0] + referrer.search.split('&q=')[1].split('&')[0] + referrer_message.so[1];
  242. else if (domain == 'google')
  243. text = referrer_message.google[0] + document.title.split(referrer_message.google[2])[0] + referrer_message.google[1];
  244. else {
  245. $.each(result.waifu.referrer_hostname, function(i,val) {if (i==referrer.hostname) referrer.hostname = getRandText(val)});
  246. text = referrer_message.default[0] + referrer.hostname + referrer_message.default[1];
  247. }
  248. } else text = referrer_message.none[0] + document.title.split(referrer_message.none[2])[0] + referrer_message.none[1];
  249. }
  250. showMessage(text, 6000);
  251. }; if (live2d_settings.showWelcomeMessage) showWelcomeMessage(result);
  252. var waifu_tips = result.waifu;
  253. function loadOtherModel() {
  254. var modelId = modelStorageGetItem('modelId');
  255. var modelRandMode = live2d_settings.modelRandMode;
  256. $.ajax({
  257. cache: modelRandMode == 'switch' ? true : false,
  258. url: live2d_settings.modelAPI+modelRandMode+'/?id='+modelId,
  259. dataType: "json",
  260. success: function(result) {
  261. loadModel(result.model['id']);
  262. var message = result.model['message'];
  263. $.each(waifu_tips.model_message, function(i,val) {if (i==result.model['id']) message = getRandText(val)});
  264. showMessage(message, 3000, true);
  265. }
  266. });
  267. }
  268. function loadRandTextures() {
  269. var modelId = modelStorageGetItem('modelId');
  270. var modelTexturesId = modelStorageGetItem('modelTexturesId');
  271. var modelTexturesRandMode = live2d_settings.modelTexturesRandMode;
  272. $.ajax({
  273. cache: modelTexturesRandMode == 'switch' ? true : false,
  274. url: live2d_settings.modelAPI+modelTexturesRandMode+'_textures/?id='+modelId+'-'+modelTexturesId,
  275. dataType: "json",
  276. success: function(result) {
  277. if (result.textures['id'] == 1 && (modelTexturesId == 1 || modelTexturesId == 0))
  278. showMessage(waifu_tips.load_rand_textures[0], 3000, true);
  279. else showMessage(waifu_tips.load_rand_textures[1], 3000, true);
  280. loadModel(modelId, result.textures['id']);
  281. }
  282. });
  283. }
  284. function modelStorageGetItem(key) { return live2d_settings.modelStorage ? localStorage.getItem(key) : sessionStorage.getItem(key); }
  285. /* 检测用户活动状态,并在空闲时显示一言 */
  286. if (live2d_settings.showHitokoto) {
  287. window.getActed = false; window.hitokotoTimer = 0; window.hitokotoInterval = false;
  288. $(document).mousemove(function(e){getActed = true;}).keydown(function(){getActed = true;});
  289. setInterval(function(){ if (!getActed) ifActed(); else elseActed(); }, 1000);
  290. }
  291. function ifActed() {
  292. if (!hitokotoInterval) {
  293. hitokotoInterval = true;
  294. hitokotoTimer = window.setInterval(showHitokotoActed, 30000);
  295. }
  296. }
  297. function elseActed() {
  298. getActed = hitokotoInterval = false;
  299. window.clearInterval(hitokotoTimer);
  300. }
  301. function showHitokotoActed() {
  302. if ($(document)[0].visibilityState == 'visible') showHitokoto();
  303. }
  304. function showHitokoto() {
  305. switch(live2d_settings.hitokotoAPI) {
  306. case 'lwl12.com':
  307. $.getJSON('https://api.lwl12.com/hitokoto/v1?encode=realjson',function(result){
  308. if (!empty(result.source)) {
  309. var text = waifu_tips.hitokoto_api_message['lwl12.com'][0];
  310. if (!empty(result.author)) text += waifu_tips.hitokoto_api_message['lwl12.com'][1];
  311. text = text.render({source: result.source, creator: result.author});
  312. window.setTimeout(function() {showMessage(text+waifu_tips.hitokoto_api_message['lwl12.com'][2], 3000, true);}, 5000);
  313. } showMessage(result.text, 5000, true);
  314. });break;
  315. case 'fghrsh.net':
  316. $.getJSON('https://api.fghrsh.net/hitokoto/rand/?encode=jsc&uid=3335',function(result){
  317. if (!empty(result.source)) {
  318. var text = waifu_tips.hitokoto_api_message['fghrsh.net'][0];
  319. text = text.render({source: result.source, date: result.date});
  320. window.setTimeout(function() {showMessage(text, 3000, true);}, 5000);
  321. showMessage(result.hitokoto, 5000, true);
  322. }
  323. });break;
  324. case 'jinrishici.com':
  325. $.ajax({
  326. url: 'https://v2.jinrishici.com/one.json',
  327. xhrFields: {withCredentials: true},
  328. success: function (result, status) {
  329. if (!empty(result.data.origin.title)) {
  330. var text = waifu_tips.hitokoto_api_message['jinrishici.com'][0];
  331. text = text.render({title: result.data.origin.title, dynasty: result.data.origin.dynasty, author:result.data.origin.author});
  332. window.setTimeout(function() {showMessage(text, 3000, true);}, 5000);
  333. } showMessage(result.data.content, 5000, true);
  334. }
  335. });break;
  336. default:
  337. $.getJSON('https://v1.hitokoto.cn',function(result){
  338. if (!empty(result.from)) {
  339. var text = waifu_tips.hitokoto_api_message['hitokoto.cn'][0];
  340. text = text.render({source: result.from, creator: result.creator});
  341. window.setTimeout(function() {showMessage(text, 3000, true);}, 5000);
  342. }
  343. showMessage(result.hitokoto, 5000, true);
  344. });
  345. }
  346. }
  347. $('.waifu-tool .fui-eye').click(function (){loadOtherModel()});
  348. $('.waifu-tool .fui-user').click(function (){loadRandTextures()});
  349. $('.waifu-tool .fui-chat').click(function (){showHitokoto()});
  350. }