3 ms·
Since the code in my GM script has become a bit ugly, here is the relevant portion (cleaned up and commented): // Get all the pre tags within comments. var
by Xichekolas 17y ago
Since the code in my GM script has become a bit ugly, here is the relevant portion (cleaned up and commented):
// Get all the pre tags within comments.
var xpathpres = document.evaluate("//span[@class='comment']//pre", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
// Iterate through them.
for (var n = 0; n < xpathpres.snapshotLength; n++) {
var thispre = xpathpres.snapshotItem(n);
// Find width of the spacer image, add 120 (found experimentally).
var reduction = (thispre.parentNode.parentNode.parentNode.firstChild.firstChild.width || 0) + 120;
// pre span td tr td img
// Get the size of the browser window, default to 800px.
var winsize = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 800;
// Ensure a minimum width so things don't disappear.
var width = Math.max(winsize - reduction, 300);
// Set the width.
thispre.style.maxWidth = width + 'px';
}
Really seems like there should be a pure CSS solution to this though. As others have pointed out, setting overflow-x: scroll and then defining widths for all the containing elements explicitly would probably fix it without depending on javascript.
If he were to use my solution, at least he would know the spacer image width serverside, so wouldn't need javascript to find that. Would still have to use it to find the window size though.