⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resourcespanel.js

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 JS
📖 第 1 页 / 共 4 页
字号:
        if (resource.endTime !== -1)            var end = ((resource.endTime - this.minimumBoundary) / this.boundarySpan) * 100;        else            var end = (this.startAtZero ? middle : 100);        if (this.startAtZero) {            end -= start;            middle -= start;            start = 0;        }        return {start: start, middle: middle, end: end};    },    computeBarGraphLabels: function(resource)    {        var leftLabel = "";        if (resource.latency > 0)            leftLabel = this.formatValue(resource.latency);        var rightLabel = "";        if (resource.responseReceivedTime !== -1 && resource.endTime !== -1)            rightLabel = this.formatValue(resource.endTime - resource.responseReceivedTime);        if (leftLabel && rightLabel) {            var total = this.formatValue(resource.duration);            var tooltip = WebInspector.UIString("%s latency, %s download (%s total)", leftLabel, rightLabel, total);        } else if (leftLabel)            var tooltip = WebInspector.UIString("%s latency", leftLabel);        else if (rightLabel)            var tooltip = WebInspector.UIString("%s download", rightLabel);        if (resource.cached)            tooltip = WebInspector.UIString("%s (from cache)", tooltip);        return {left: leftLabel, right: rightLabel, tooltip: tooltip};    },    updateBoundaries: function(resource)    {        var didChange = false;        var lowerBound;        if (this.startAtZero)            lowerBound = 0;        else            lowerBound = this._lowerBound(resource);        if (lowerBound !== -1 && (typeof this.minimumBoundary === "undefined" || lowerBound < this.minimumBoundary)) {            this.minimumBoundary = lowerBound;            didChange = true;        }        var upperBound = this._upperBound(resource);        if (upperBound !== -1 && (typeof this.maximumBoundary === "undefined" || upperBound > this.maximumBoundary)) {            this.maximumBoundary = upperBound;            didChange = true;        }        return didChange;    },    formatValue: function(value)    {        return Number.secondsToString(value, WebInspector.UIString.bind(WebInspector));    },    _lowerBound: function(resource)    {        return 0;    },    _upperBound: function(resource)    {        return 0;    },}WebInspector.ResourceTimeCalculator.prototype.__proto__ = WebInspector.ResourceCalculator.prototype;WebInspector.ResourceTransferTimeCalculator = function(){    WebInspector.ResourceTimeCalculator.call(this, false);}WebInspector.ResourceTransferTimeCalculator.prototype = {    formatValue: function(value)    {        return Number.secondsToString(value, WebInspector.UIString.bind(WebInspector));    },    _lowerBound: function(resource)    {        return resource.startTime;    },    _upperBound: function(resource)    {        return resource.endTime;    }}WebInspector.ResourceTransferTimeCalculator.prototype.__proto__ = WebInspector.ResourceTimeCalculator.prototype;WebInspector.ResourceTransferDurationCalculator = function(){    WebInspector.ResourceTimeCalculator.call(this, true);}WebInspector.ResourceTransferDurationCalculator.prototype = {    formatValue: function(value)    {        return Number.secondsToString(value, WebInspector.UIString.bind(WebInspector));    },    _upperBound: function(resource)    {        return resource.duration;    }}WebInspector.ResourceTransferDurationCalculator.prototype.__proto__ = WebInspector.ResourceTimeCalculator.prototype;WebInspector.ResourceTransferSizeCalculator = function(){    WebInspector.ResourceCalculator.call(this);}WebInspector.ResourceTransferSizeCalculator.prototype = {    _value: function(resource)    {        return resource.contentLength;    },    formatValue: function(value)    {        return Number.bytesToString(value, WebInspector.UIString.bind(WebInspector));    }}WebInspector.ResourceTransferSizeCalculator.prototype.__proto__ = WebInspector.ResourceCalculator.prototype;WebInspector.ResourceSidebarTreeElement = function(resource){    this.resource = resource;    this.createIconElement();    WebInspector.SidebarTreeElement.call(this, "resource-sidebar-tree-item", "", "", resource);    this.refreshTitles();}WebInspector.ResourceSidebarTreeElement.prototype = {    onattach: function()    {        WebInspector.SidebarTreeElement.prototype.onattach.call(this);        this._listItemNode.addStyleClass("resources-category-" + this.resource.category.name);    },    onselect: function()    {        WebInspector.panels.resources.showResource(this.resource);    },    get mainTitle()    {        return this.resource.displayName;    },    set mainTitle(x)    {        // Do nothing.    },    get subtitle()    {        var subtitle = this.resource.displayDomain;        if (this.resource.path && this.resource.lastPathComponent) {            var lastPathComponentIndex = this.resource.path.lastIndexOf("/" + this.resource.lastPathComponent);            if (lastPathComponentIndex != -1)                subtitle += this.resource.path.substring(0, lastPathComponentIndex);        }        return subtitle;    },    set subtitle(x)    {        // Do nothing.    },    createIconElement: function()    {        var previousIconElement = this.iconElement;        if (this.resource.category === WebInspector.resourceCategories.images) {            var previewImage = document.createElement("img");            previewImage.className = "image-resource-icon-preview";            previewImage.src = this.resource.url;            this.iconElement = document.createElement("div");            this.iconElement.className = "icon";            this.iconElement.appendChild(previewImage);        } else {            this.iconElement = document.createElement("img");            this.iconElement.className = "icon";        }        if (previousIconElement)            previousIconElement.parentNode.replaceChild(this.iconElement, previousIconElement);    },    refresh: function()    {        this.refreshTitles();        if (!this._listItemNode.hasStyleClass("resources-category-" + this.resource.category.name)) {            this._listItemNode.removeMatchingStyleClasses("resources-category-\\w+");            this._listItemNode.addStyleClass("resources-category-" + this.resource.category.name);            this.createIconElement();        }    },    resetBubble: function()    {        this.bubbleText = "";        this.bubbleElement.removeStyleClass("search-matches");        this.bubbleElement.removeStyleClass("warning");        this.bubbleElement.removeStyleClass("error");    },    set searchMatches(matches)    {        this.resetBubble();        if (!matches)            return;        this.bubbleText = matches;        this.bubbleElement.addStyleClass("search-matches");    },    updateErrorsAndWarnings: function()    {        this.resetBubble();        if (this.resource.warnings || this.resource.errors)            this.bubbleText = (this.resource.warnings + this.resource.errors);        if (this.resource.warnings)            this.bubbleElement.addStyleClass("warning");        if (this.resource.errors)            this.bubbleElement.addStyleClass("error");    }}WebInspector.ResourceSidebarTreeElement.CompareByAscendingStartTime = function(a, b){    return WebInspector.Resource.CompareByStartTime(a.resource, b.resource)        || WebInspector.Resource.CompareByEndTime(a.resource, b.resource)        || WebInspector.Resource.CompareByResponseReceivedTime(a.resource, b.resource);}WebInspector.ResourceSidebarTreeElement.CompareByAscendingResponseReceivedTime = function(a, b){    return WebInspector.Resource.CompareByResponseReceivedTime(a.resource, b.resource)        || WebInspector.Resource.CompareByStartTime(a.resource, b.resource)        || WebInspector.Resource.CompareByEndTime(a.resource, b.resource);}WebInspector.ResourceSidebarTreeElement.CompareByAscendingEndTime = function(a, b){    return WebInspector.Resource.CompareByEndTime(a.resource, b.resource)        || WebInspector.Resource.CompareByStartTime(a.resource, b.resource)        || WebInspector.Resource.CompareByResponseReceivedTime(a.resource, b.resource);}WebInspector.ResourceSidebarTreeElement.CompareByDescendingDuration = function(a, b){    return -1 * WebInspector.Resource.CompareByDuration(a.resource, b.resource);}WebInspector.ResourceSidebarTreeElement.CompareByDescendingLatency = function(a, b){    return -1 * WebInspector.Resource.CompareByLatency(a.resource, b.resource);}WebInspector.ResourceSidebarTreeElement.CompareByDescendingSize = function(a, b){    return -1 * WebInspector.Resource.CompareBySize(a.resource, b.resource);}WebInspector.ResourceSidebarTreeElement.prototype.__proto__ = WebInspector.SidebarTreeElement.prototype;WebInspector.ResourceGraph = function(resource){    this.resource = resource;    this._graphElement = document.createElement("div");    this._graphElement.className = "resources-graph-side";    this._graphElement.addEventListener("mouseover", this.refreshLabelPositions.bind(this), false);    if (resource.cached)        this._graphElement.addStyleClass("resource-cached");    this._barAreaElement = document.createElement("div");    this._barAreaElement.className = "resources-graph-bar-area hidden";    this._graphElement.appendChild(this._barAreaElement);    this._barLeftElement = document.createElement("div");    this._barLeftElement.className = "resources-graph-bar waiting";    this._barAreaElement.appendChild(this._barLeftElement);    this._barRightElement = document.createElement("div");    this._barRightElement.className = "resources-graph-bar";    this._barAreaElement.appendChild(this._barRightElement);    this._labelLeftElement = document.createElement("div");    this._labelLeftElement.className = "resources-graph-label waiting";    this._barAreaElement.appendChild(this._labelLeftElement);    this._labelRightElement = document.createElement("div");    this._labelRightElement.className = "resources-graph-label";    this._barAreaElement.appendChild(this._labelRightElement);    this._graphElement.addStyleClass("resources-category-" + resource.category.name);}WebInspector.ResourceGraph.prototype = {    get graphElement()    {        return this._graphElement;    },    refreshLabelPositions: function()    {        this._labelLeftElement.style.removeProperty("left");        this._labelLeftElement.style.removeProperty("right");        this._labelLeftElement.removeStyleClass("before");        this._labelLeftElement.removeStyleClass("hidden");        this._labelRightElement.style.removeProperty("left");        this._labelRightElement.style.removeProperty("right");        this._labelRightElement.removeStyleClass("after");        this._labelRightElement.removeStyleClass("hidden");        const labelPadding = 10;        const rightBarWidth = (this._barRightElement.offsetWidth - labelPadding);        const leftBarWidth = ((this._barLeftElement.offsetWidth - this._barRightElement.offsetWidth) - labelPadding);        var labelBefore = (this._labelLeftElement.offsetWidth > leftBarWidth);        var labelAfter = (this._labelRightElement.offsetWidth > rightBarWidth);        if (labelBefore) {            if ((this._graphElement.offsetWidth * (this._percentages.start / 100)) < (this._labelLeftElement.offsetWidth + 10))                this._labelLeftElement.addStyleClass("hidden");            this._labelLeftElement.style.setProperty("right", (100 - this._percentages.start) + "%");            this._labelLeftElement.addStyleClass("before");        } else {            this._labelLeftElement.style.setProperty("left", this._percentages.start + "%");            this._labelLeftElement.style.setProperty("right", (100 - this._percentages.middle) + "%");        }        if (labelAfter) {            if ((this._graphElement.offsetWidth * ((100 - this._percentages.end) / 100)) < (this._labelRightElement.offsetWidth + 10))                this._labelRightElement.addStyleClass("hidden");            this._labelRightElement.style.setProperty("left", this._percentages.end + "%");            this._labelRightElement.addStyleClass("after");        } else {            this._labelRightElement.style.setProperty("left", this._percentages.middle + "%");            this._labelRightElement.style.setProperty("right", (100 - this._percentages.end) + "%");        }    },    refresh: function(calculator)    {        var percentages = calculator.computeBarGraphPercentages(this.resource);        var labels = calculator.computeBarGraphLabels(this.resource);        this._percentages = percentages;        this._barAreaElement.removeStyleClass("hidden");        if (!this._graphElement.hasStyleClass("resources-category-" + this.resource.category.name)) {            this._graphElement.removeMatchingStyleClasses("resources-category-\\w+");            this._graphElement.addStyleClass("resources-category-" + this.resource.category.name);        }        this._barLeftElement.style.setProperty("left", percentages.start + "%");        this._barLeftElement.style.setProperty("right", (100 - percentages.end) + "%");        this._barRightElement.style.setProperty("left", percentages.middle + "%");        this._barRightElement.style.setProperty("right", (100 - percentages.end) + "%");        this._labelLeftElement.textContent = labels.left;        this._labelRightElement.textContent = labels.right;        var tooltip = (labels.tooltip || "");        this._barLeftElement.title = tooltip;        this._labelLeftElement.title = tooltip;        this._labelRightElement.title = tooltip;        this._barRightElement.title = tooltip;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -