From da163bbe4bfdb46d5e02790daf98ea455676ec6a Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 13 Oct 2016 13:25:57 -0400 Subject: [PATCH] fix #1641 --- src/js/1p-filters.js | 3 +-- src/js/dashboard-common.js | 13 +++++++++++-- src/js/dyna-rules.js | 5 ++--- src/js/messaging.js | 3 +-- src/js/utils.js | 9 +++++++++ src/js/whitelist.js | 3 +-- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/js/1p-filters.js b/src/js/1p-filters.js index 57e2f934d..307a70e4f 100644 --- a/src/js/1p-filters.js +++ b/src/js/1p-filters.js @@ -127,9 +127,8 @@ var exportUserFiltersToFile = function() { if ( val === '' ) { return; } - var now = new Date(); var filename = vAPI.i18n('1pExportFilename') - .replace('{{datetime}}', now.toLocaleString()) + .replace('{{datetime}}', uBlockDashboard.dateNowToSensibleString()) .replace(/ +/g, '_'); vAPI.download({ 'url': 'data:text/plain;charset=utf-8,' + encodeURIComponent(val + '\n'), diff --git a/src/js/dashboard-common.js b/src/js/dashboard-common.js index 7cef4f68a..47e04c5ca 100644 --- a/src/js/dashboard-common.js +++ b/src/js/dashboard-common.js @@ -1,7 +1,7 @@ /******************************************************************************* - µBlock - a browser extension to block requests. - Copyright (C) 2014 Raymond Hill + uBlock Origin - a browser extension to block requests. + Copyright (C) 2014-2016 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 @@ -103,6 +103,15 @@ self.uBlockDashboard.mergeNewLines = function(text, newText) { /******************************************************************************/ +self.uBlockDashboard.dateNowToSensibleString = function() { + var now = new Date(Date.now() - (new Date()).getTimezoneOffset() * 60000); + return now.toISOString().replace(/\.\d+Z$/, '') + .replace(/:/g, '.') + .replace('T', '_'); +}; + +/******************************************************************************/ + // Open links in the proper window uDom('a').attr('target', '_blank'); uDom('a[href*="dashboard.html"]').attr('target', '_parent'); diff --git a/src/js/dyna-rules.js b/src/js/dyna-rules.js index abd7a37fb..30e1b0224 100644 --- a/src/js/dyna-rules.js +++ b/src/js/dyna-rules.js @@ -19,7 +19,7 @@ Home: https://github.com/gorhill/uMatrix */ -/* global uDom */ +/* global uDom, uBlockDashboard */ /******************************************************************************/ @@ -153,9 +153,8 @@ var startImportFilePicker = function() { /******************************************************************************/ function exportUserRulesToFile() { - var now = new Date(); var filename = vAPI.i18n('rulesDefaultFileName') - .replace('{{datetime}}', now.toLocaleString()) + .replace('{{datetime}}', uBlockDashboard.dateNowToSensibleString()) .replace(/ +/g, '_'); vAPI.download({ 'url': 'data:text/plain,' + encodeURIComponent(rulesFromHTML('#diff .left li') + '\n'), diff --git a/src/js/messaging.js b/src/js/messaging.js index 29738d61c..fb8901118 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -745,9 +745,8 @@ var backupUserData = function(callback) { var onSelectedListsReady = function(filterLists) { userData.filterLists = filterLists; - var now = new Date(); var filename = vAPI.i18n('aboutBackupFilename') - .replace('{{datetime}}', now.toLocaleString()) + .replace('{{datetime}}', µb.dateNowToSensibleString()) .replace(/ +/g, '_'); vAPI.download({ diff --git a/src/js/utils.js b/src/js/utils.js index ab48e8af2..04c9a3e41 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -135,6 +135,15 @@ /******************************************************************************/ +µBlock.dateNowToSensibleString = function() { + var now = new Date(Date.now() - (new Date()).getTimezoneOffset() * 60000); + return now.toISOString().replace(/\.\d+Z$/, '') + .replace(/:/g, '.') + .replace('T', '_'); +}; + +/******************************************************************************/ + µBlock.LineIterator = function(text, offset) { this.text = text; this.textLen = this.text.length; diff --git a/src/js/whitelist.js b/src/js/whitelist.js index d8e7004fd..a15b48b91 100644 --- a/src/js/whitelist.js +++ b/src/js/whitelist.js @@ -96,9 +96,8 @@ var exportWhitelistToFile = function() { if ( val === '' ) { return; } - var now = new Date(); var filename = vAPI.i18n('whitelistExportFilename') - .replace('{{datetime}}', now.toLocaleString()) + .replace('{{datetime}}', uBlockDashboard.dateNowToSensibleString()) .replace(/ +/g, '_'); vAPI.download({ 'url': 'data:text/plain;charset=utf-8,' + encodeURIComponent(val + '\n'),