Removed timeago library.
This commit is contained in:
parent
e5d9128cd0
commit
cecfaf4852
6 changed files with 47 additions and 26 deletions
|
@ -1,5 +1,7 @@
|
|||
#include sakuya.js
|
||||
|
||||
var Misuzu = function() {
|
||||
timeago.render($qa('time'));
|
||||
Sakuya.trackElements($qa('time'));
|
||||
hljs.initHighlighting();
|
||||
|
||||
MszEmbed.init(location.protocol + '//uiharu.' + location.host);
|
||||
|
|
44
assets/misuzu.js/sakuya.js
Normal file
44
assets/misuzu.js/sakuya.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
const Sakuya = (function() {
|
||||
const formatter = new Intl.RelativeTimeFormat(undefined, { numeric: 'auto' });
|
||||
const divisions = [
|
||||
{ amount: 60, name: 'seconds' },
|
||||
{ amount: 60, name: 'minutes' },
|
||||
{ amount: 24, name: 'hours' },
|
||||
{ amount: 7, name: 'days' },
|
||||
{ amount: 4.34524, name: 'weeks' },
|
||||
{ amount: 12, name: 'months' },
|
||||
{ amount: Infinity, name: 'years' },
|
||||
];
|
||||
|
||||
const formatTimeAgo = function(date) {
|
||||
let duration = (date - new Date()) / 1000;
|
||||
|
||||
for(const div of divisions) {
|
||||
if(Math.abs(duration) < div.amount)
|
||||
return formatter.format(Math.round(duration), div.name);
|
||||
duration /= div.amount;
|
||||
}
|
||||
};
|
||||
|
||||
// todo: update at intervals
|
||||
const trackElement = function(elem) {
|
||||
if(elem.dateTime === undefined)
|
||||
return;
|
||||
|
||||
try {
|
||||
const dateTime = new Date(elem.dateTime);
|
||||
elem.textContent = formatTimeAgo(dateTime);
|
||||
} catch {}
|
||||
};
|
||||
|
||||
const trackElements = function(elems) {
|
||||
for(const elem of elems)
|
||||
trackElement(elem);
|
||||
};
|
||||
|
||||
return {
|
||||
formatTimeAgo: formatTimeAgo,
|
||||
trackElement: trackElement,
|
||||
trackElements: trackElements,
|
||||
};
|
||||
})();
|
21
public/vendor/timeago/LICENSE
vendored
21
public/vendor/timeago/LICENSE
vendored
|
@ -1,21 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Hust.cc
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
1
public/vendor/timeago/timeago.locales.min.js
vendored
1
public/vendor/timeago/timeago.locales.min.js
vendored
File diff suppressed because one or more lines are too long
1
public/vendor/timeago/timeago.min.js
vendored
1
public/vendor/timeago/timeago.min.js
vendored
|
@ -1 +0,0 @@
|
|||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.timeago={})}(this,function(t){"use strict";var f=[60,60,24,7,365/7/12,12],o=function(t){return parseInt(t)},n=function(t){return t instanceof Date?t:!isNaN(t)||/^\d+$/.test(t)?new Date(o(t)):(t=(t||"").trim().replace(/\.\d+/,"").replace(/-/,"/").replace(/-/,"/").replace(/(\d)T(\d)/,"$1 $2").replace(/Z/," UTC").replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"),new Date(t))},s=function(t,e){for(var n=0,r=t<0?1:0,a=t=Math.abs(t);f[n]<=t&&n<f.length;n++)t/=f[n];return(0===(n*=2)?9:1)<(t=o(t))&&(n+=1),e(t,n,a)[r].replace("%s",t)},d=function(t,e){return((e=e?n(e):new Date)-n(t))/1e3},r="second_minute_hour_day_week_month_year".split("_"),a="秒_分钟_小时_天_周_个月_年".split("_"),e=function(t,e){if(0===e)return["just now","right now"];var n=r[parseInt(e/2)];return 1<t&&(n+="s"),["".concat(t," ").concat(n," ago"),"in ".concat(t," ").concat(n)]},i={en_US:e,zh_CN:function(t,e){if(0===e)return["刚刚","片刻后"];var n=a[parseInt(e/2)];return["".concat(t," ").concat(n,"前"),"".concat(t," ").concat(n,"后")]}},c=function(t){return i[t]||e},l="timeago-tid",u=function(t,e){return t.getAttribute?t.getAttribute(e):t.attr?t.attr(e):void 0},p=function(t){return u(t,l)},_={},v=function(t){clearTimeout(t),delete _[t]},h=function t(e,n,r,a){v(p(e));var o=d(n,a);e.innerHTML=s(o,r);var i,c,u=setTimeout(function(){t(e,n,r,a)},1e3*function(t){for(var e=1,n=0,r=Math.abs(t);f[n]<=t&&n<f.length;n++)t/=f[n],e*=f[n];return r=(r%=e)?e-r:e,Math.ceil(r)}(o),2147483647);_[u]=0,c=u,(i=e).setAttribute?i.setAttribute(l,c):i.attr&&i.attr(l,c)};t.version="4.0.0-beta.2",t.format=function(t,e,n){var r=d(t,n);return s(r,c(e))},t.render=function(t,e,n){var r;void 0===t.length&&(t=[t]);for(var a=0;a<t.length;a++){r=t[a];var o=u(r,"datetime"),i=c(e);h(r,o,i,n)}return t},t.cancel=function(t){if(t)v(p(t));else for(var e in _)v(e)},t.register=function(t,e){i[t]=e},Object.defineProperty(t,"__esModule",{value:!0})});
|
|
@ -148,8 +148,6 @@
|
|||
<script type="text/javascript">
|
||||
window.addEventListener('DOMContentLoaded', function() { Misuzu(); });
|
||||
</script>
|
||||
<script src="/vendor/timeago/timeago.min.js" type="text/javascript"></script>
|
||||
<script src="/vendor/timeago/timeago.locales.min.js" type="text/javascript"></script>
|
||||
<script src="/vendor/highlightjs/highlight.pack.js" type="text/javascript"></script>
|
||||
<script src="{{ assets.mszjs|default() }}" type="text/javascript"></script>
|
||||
</body>
|
||||
|
|
Loading…
Reference in a new issue