Userscript to always show LW comments in context vs at the top

post by Vlad Sitalo (harcisis) · 2023-11-21T17:53:30.418Z · LW · GW · 8 comments

The out of context top-level display of comments when I navigate to them always bothered me, but up until recently I haven't realized there is a way to go to the actual comment via a simple URL change. 

From https://www.lesswrong.com/posts/<postid>/?commentId=<commentid>
To https://www.lesswrong.com/posts/<postid>#<commentid>

Here is a quick gpt4 generated userscript that does this. 

// ==UserScript==
// @name         Always show in-context comments
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Redirect from '?commentId=' format to '#'
// @author       Vlad Sitalo
// @match        https://www.lesswrong.com/*
// @grant        none
// ==/UserScript==


(function() {
    'use strict';

    var checkAndRedirect = function() {
        var url = window.location.href;
        if(url.includes("?commentId=")){
            var newUrl = url.split("?commentId=").join("#");
            window.location.href = newUrl;
        }
    };

    // Run on page load
    checkAndRedirect();

    // Run on URL change
    var pushState = history.pushState;
    history.pushState = function() {
        pushState.apply(history, arguments);
        checkAndRedirect();
    };

    var replaceState = history.replaceState;
    history.replaceState = function() {
        replaceState.apply(history, arguments);
        checkAndRedirect();
    };

    window.addEventListener('popstate', checkAndRedirect);
})();

8 comments

Comments sorted by top scores.

comment by lc · 2023-11-22T00:58:10.124Z · LW(p) · GW(p)

Whenever I browse to a comment link I'm just waiting until the page loads so that I can use the See Context button.

Replies from: harcisis
comment by Vlad Sitalo (harcisis) · 2023-11-22T01:31:58.149Z · LW(p) · GW(p)

Oh, that actually suggests a slightly better version, that won't reload the page. Updated the post!

Replies from: harcisis
comment by Vlad Sitalo (harcisis) · 2023-11-22T01:35:04.347Z · LW(p) · GW(p)

Uh nvm, that doesn't work reliably bc of the comment lazy loading 🤔

comment by jefftk (jkaufman) · 2023-11-22T01:46:07.123Z · LW(p) · GW(p)

I wish I could use this on mobile...

I don't understand why the non-context display option exists.

(Except for a bug where "see in context" doesn't work when the parent is collapsed)

Replies from: harcisis
comment by Vlad Sitalo (harcisis) · 2023-11-22T02:59:20.151Z · LW(p) · GW(p)

If you use android: https://kiwibrowser.com/ supports extensions!

Replies from: jkaufman
comment by jefftk (jkaufman) · 2023-11-22T12:03:51.630Z · LW(p) · GW(p)

When you use a browser you're putting an enormous amount of trust in it's manufacturer to get security right, and I don't have that level of trust for most vendors.

Replies from: harcisis
comment by Vlad Sitalo (harcisis) · 2023-11-22T17:35:35.766Z · LW(p) · GW(p)

That's fair. I believe kiwi is a fork of chrome that is kept up to date with a set of patches applied on top fwiw.

Replies from: jkaufman
comment by jefftk (jkaufman) · 2023-11-22T21:34:36.384Z · LW(p) · GW(p)

How up to date? Chrome security patches are very often followed by reverse engineering and exploitation, so you need to be very prompt.

(Yes, this means I don't trust any browsers except Chrome, Firefox, Safari)