2014-06-23 16:42:43 -06:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2015-03-07 11:20:18 -07:00
|
|
|
µBlock - a browser extension to block requests.
|
2014-06-23 16:42:43 -06:00
|
|
|
Copyright (C) 2014 Raymond Hill
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
|
|
|
|
|
|
Home: https://github.com/gorhill/uBlock
|
|
|
|
*/
|
|
|
|
|
2014-10-19 05:11:27 -06:00
|
|
|
/* global vAPI, uDom */
|
2015-03-09 17:10:04 -06:00
|
|
|
/* exported renderElapsedTime */
|
|
|
|
|
2014-10-19 05:11:27 -06:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-06-23 16:42:43 -06:00
|
|
|
// Helper to deal with the i18n'ing of HTML files.
|
2014-07-02 10:02:29 -06:00
|
|
|
|
|
|
|
uDom.onLoad(function() {
|
2014-11-07 08:07:26 -07:00
|
|
|
uDom('[data-i18n]').forEach(function(elem) {
|
2014-11-09 09:50:58 -07:00
|
|
|
elem.html(vAPI.i18n(elem.attr('data-i18n')));
|
2014-07-31 09:28:05 -06:00
|
|
|
});
|
2014-11-07 08:07:26 -07:00
|
|
|
uDom('[title]').forEach(function(elem) {
|
2014-11-09 09:50:58 -07:00
|
|
|
var title = vAPI.i18n(elem.attr('title'));
|
2014-07-31 09:28:05 -06:00
|
|
|
if ( title ) {
|
2014-11-07 08:07:26 -07:00
|
|
|
elem.attr('title', title);
|
2014-07-31 09:28:05 -06:00
|
|
|
}
|
|
|
|
});
|
2015-03-03 00:22:26 -07:00
|
|
|
uDom('[placeholder]').forEach(function(elem) {
|
2015-03-03 07:37:15 -07:00
|
|
|
elem.attr('placeholder', vAPI.i18n(elem.attr('placeholder')));
|
2015-03-03 00:22:26 -07:00
|
|
|
});
|
2014-11-07 08:07:26 -07:00
|
|
|
uDom('[data-i18n-tip]').forEach(function(elem) {
|
|
|
|
elem.attr(
|
2014-10-17 13:44:19 -06:00
|
|
|
'data-tip',
|
2014-11-09 09:50:58 -07:00
|
|
|
vAPI.i18n(elem.attr('data-i18n-tip')).replace(/<br>/g, '')
|
2014-08-24 08:04:22 -06:00
|
|
|
);
|
|
|
|
});
|
2014-06-23 16:42:43 -06:00
|
|
|
});
|
2015-03-09 17:10:04 -06:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-03-09 17:19:08 -06:00
|
|
|
vAPI.i18n.renderElapsedTimeToString = function(tstamp) {
|
2015-03-09 17:10:04 -06:00
|
|
|
var value = (Date.now() - tstamp) / 60000;
|
|
|
|
if ( value < 2 ) {
|
|
|
|
return vAPI.i18n('elapsedOneMinuteAgo');
|
|
|
|
}
|
|
|
|
if ( value < 60 ) {
|
|
|
|
return vAPI.i18n('elapsedManyMinutesAgo').replace('{{value}}', Math.floor(value).toLocaleString());
|
|
|
|
}
|
|
|
|
value /= 60;
|
|
|
|
if ( value < 2 ) {
|
|
|
|
return vAPI.i18n('elapsedOneHourAgo');
|
|
|
|
}
|
2015-03-09 18:04:07 -06:00
|
|
|
if ( value < 24 ) {
|
2015-03-09 17:10:04 -06:00
|
|
|
return vAPI.i18n('elapsedManyHoursAgo').replace('{{value}}', Math.floor(value).toLocaleString());
|
|
|
|
}
|
|
|
|
value /= 24;
|
|
|
|
if ( value < 2 ) {
|
|
|
|
return vAPI.i18n('elapsedOneDayAgo');
|
|
|
|
}
|
|
|
|
return vAPI.i18n('elapsedManyDaysAgo').replace('{{value}}', Math.floor(value).toLocaleString());
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|