/******************************************************************************* µ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 messaging, uDom */ /******************************************************************************/ (function() { /******************************************************************************/ messaging.start('info.js'); var targetUrl = 'all'; 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', pageURL: targetUrl !== 'all' ? targetUrl : null }; messaging.ask(request, onResponseReceived); } /******************************************************************************/ function clearRequestData() { var request = { what: 'clearRequestLogs', pageURL: targetUrl !== 'all' ? targetUrl : null }; messaging.tell(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 = chrome.i18n.getMessage(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(r) { 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() === targetUrl ) { option.attr('selected', true); } select.append(option); } var pageURLs = r.pageURLs.sort(); var pageURL, option; n = pageURLs.length; for ( i = 0; i < n; i++ ) { pageURL = pageURLs[i]; // Behind-the-scene entry is always present, no need to recreate it if ( pageURL === r.behindTheSceneURL ) { continue; } option = uDom('