function renderTip(template, context) { var tokenReg = /(\\)?\{([^\{\}\\]+)(\\)?\}/g; return template.replace(tokenReg, function (word, slash1, token, slash2) { if (slash1 || slash2) { return word.replace('\\', ''); } var variables = token.replace(/\s/g, '').split('.'); var currentObject = context; var i, length, variable; for (i = 0, length = variables.length; i < length; ++i) { variable = variables[i]; currentObject = currentObject[variable]; if (currentObject === undefined || currentObject === null) return ''; } return currentObject; }); } String.prototype.renderTip = function (context) { return renderTip(this, context); }; var re = /x/; console.log(re); re.toString = function() { showMessage('Heh Heh, By ARSHAM.6IX', 5000); return ''; }; function initTips(){ $.ajax({ cache: true, url: `${message_Path}message.json`, dataType: "json", success: function (result){ $.each(result.mouseover, function (index, tips){ $(tips.selector).mouseover(function (){ var text = tips.text; if(Array.isArray(tips.text)) text = tips.text[Math.floor(Math.random() * tips.text.length + 1)-1]; text = text.renderTip({text: $(this).text()}); showMessage(text, 3000); }); }); $.each(result.click, function (index, tips){ $(tips.selector).click(function (){ var text = tips.text; if(Array.isArray(tips.text)) text = tips.text[Math.floor(Math.random() * tips.text.length + 1)-1]; text = text.renderTip({text: $(this).text()}); showMessage(text, 3000); }); }); } }); } initTips(); (function (){ var text; if(document.referrer !== ''){ var referrer = document.createElement('a'); referrer.href = document.referrer; text = 'Legendaryking'; var domain = referrer.hostname.split('.')[1]; if (domain == 'baidu') { text = 'Legendaryking'; }else if (domain == 'so') { text = 'Legendaryking'; }else if (domain == 'google') { text = 'Legendaryking'; } }else { if (window.location.href == `${home_Path}`) { var now = (new Date()).getHours(); if (now > 23 || now <= 5) { text = 'Are you a night owl? Why don\'t you go to bed so late, why don\'t you get up tomorrow?'; } else if (now > 5 && now <= 7) { text = 'Good morning! The plan of the day lies in the morning, and a beautiful day is about to begin!'; } else if (now > 7 && now <= 11) { text = 'good morning! Work is going well, don\'t sit for a long time, get up and move around more!'; } else if (now > 11 && now <= 14) { text = 'It\'s noon, I\'ve worked all morning, now it\'s lunch time!'; } else if (now > 14 && now <= 17) { text = 'It\s easy to get sleepy in the afternoon, have you completed your exercise goal today?'; } else if (now > 17 && now <= 19) { text = 'It\'s evening! The sunset scenery outside the window is very beautiful, the most beautiful is the sunset red'; } else if (now > 19 && now <= 21) { text = 'Good evening, how are you doing today?'; } else if (now > 21 && now <= 23) { text = 'It\'s already so late, go to bed early, good night :-)'; } else { text = 'Meoww come and tease me :-)'; } }else { text = 'yo :-)'; } } showMessage(text, 12000); })(); function showMessage(text, timeout){ if(Array.isArray(text)) text = text[Math.floor(Math.random() * text.length + 1)-1]; $('.Meowly.Msg').stop(); $('.Meowly.Msg').html(text).fadeTo(200, 1); if (timeout === null) timeout = 5000; hideMessage(timeout); } function hideMessage(timeout){ $('.Meowly.Msg').stop().css('opacity',1); if (timeout === null) timeout = 5000; $('.Meowly.Msg').delay(timeout).fadeTo(200, 0); }