Bustimes Detailed View Enforcer

Automatically adds ?detailed=1 or &detailed=1 to bustimes.org pages

// ==UserScript==
// @name         Bustimes Detailed View Enforcer
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically adds ?detailed=1 or &detailed=1 to bustimes.org pages
// @match        *://*.bustimes.org/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const url = new URL(window.location.href);

    // Don't do anything if detailed=1 is already present
    if (url.searchParams.get("detailed") === "1") {
        return;
    }

    url.searchParams.set("detailed", "1");

    // Only reload if necessary
    if (window.location.href !== url.href) {
        window.location.replace(url.href);
    }
})();