/******************************************************************************* µMatrix - a Chromium browser extension to black/white list requests. 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/uMatrix */ /* global vAPI, uDom */ /******************************************************************************/ (function() { 'use strict'; /******************************************************************************/ var messager = vAPI.messaging.channel('info.js'); var targetTabId = null; var maxRequests = 500; var cachedUserSettings = {}; /******************************************************************************/ // Get a list of latest net requests function updateRequestData(callback) { var onResponseReceived = function(r) { var requests = []; for ( var pageURL in r ) { if ( r.hasOwnProperty(pageURL) === false ) { continue; } requests = requests.concat(r[pageURL]); } requests = requests .sort(function(a,b){return b.when-a.when;}) .slice(0, maxRequests); callback(requests); }; var request = { what: 'getRequestLogs', tabId: targetTabId }; messager.send(request, onResponseReceived); } /******************************************************************************/ function clearRequestData() { var request = { what: 'clearRequestLogs', tabId: targetTabId }; messager.send(request); } /******************************************************************************/ function renderNumber(value) { if ( isNaN(value) ) { return '0'; } return value.toLocaleString(); } /******************************************************************************/ function renderNumbers(set) { var keys = Object.keys(set); var i = keys.length; var key; while ( i-- ) { key = keys[i]; uDom(key).text(renderNumber(set[key])); } } /******************************************************************************/ var renderLocalized = function(id, map) { var uElem = uDom('#' + id); var msg = vAPI.i18n(id); for ( var k in map ) { if ( map.hasOwnProperty(k) === false ) { continue; } msg = msg.replace('{{' + k + '}}', map[k]); } uElem.html(msg); }; /******************************************************************************/ function renderPageUrls() { var onResponseReceived = function(result) { var i, n; var select = uDom('#selectPageUrls'); // Remove whatever was put there in a previous call uDom('#selectPageUrls > option').remove(); var builtinOptions = uDom('#selectPageUrlsTemplate > option'); n = builtinOptions.length; for ( i = 0; i < n; i++ ) { option = builtinOptions.at(i).clone(); if ( option.val() === targetTabId ) { option.attr('selected', true); } select.append(option); } var entries = result.pageURLs.sort(); var entry, pageURL, option; n = entries.length; for ( i = 0; i < n; i++ ) { entry = entries[i]; // Behind-the-scene entry is always present, no need to recreate it if ( entry.pageURL === result.behindTheSceneURL ) { continue; } option = uDom('