gorhill / uMatrix

uMatrix: Point and click matrix to filter net requests according to source, destination and type
GNU General Public License v3.0
4.54k stars 470 forks source link

GUI: Long host names going under matrix make it impossible to read the domain #991

Closed levicki closed 6 years ago

levicki commented 6 years ago

Host names like this:

bw-1651cf0d2f737d7adeab84d339dbabd3-bcs.s3.amazonaws.com

Result in matrix which looks like this:

image

In my opinion,, either those names should be shortened to something like:

bw-1...3-bcs.s3.amazonaws.com

And the mouseover should show the full name in tooltip, or the matrix column with host name should expand itself to fit.

Browser is Chrome, but I observed this with Firefox too. If you need more information, please let me know.

ArchangeGabriel commented 6 years ago

Duplicate: https://github.com/gorhill/uMatrix/issues/182

levicki commented 6 years ago

Which is a duplicate of #46, an almost four year old issue. Is it impossible to fix?

I see Raymond's comment about browser rendering the text and uMatrix not knowing it will be cut, but it seems to be possible to check the text width in pixels by using invisible DIV:

https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript

I am not sure how much that would slow the rendering though?

theWalkingDuck commented 6 years ago

A clean solution would be adding a title attribute whenever the host name exceeds a certain length.

<div title="bw-1651cf0d2f737d7adeab84d339dbabd3-bwcore.s3.amazonaws.com" class="matCell ....">
    <b>bw-1651cf0d2f737d7adeab84d339dbabd3-bwcore.s3.amazonaws.com</b> 
</div>
uBlock-user commented 6 years ago

https://github.com/gorhill/httpswitchboard/issues/133#issuecomment-42762309

levicki commented 6 years ago

Well it turns out that in HTML5 you can use canvas to measure text width:

function getTextWidth(text, font) {
    // if given, use cached canvas for better performance
    // else, create new canvas
    var canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
    var context = canvas.getContext("2d");
    context.font = font;
    var metrics = context.measureText(text);
    return metrics.width;
};
...
getTextWidth("bw-1651cf0d2f737d7adeab84d339dbabd3-bwcore.s3.amazonaws.com", "bold 12pt arial");

This shouldn't slow down the popup, @gorhill what do you think Raymond?