NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name LatestLaravel
// @namespace https://www.mha.systems
// @version 1.12
// @description Automatically redirect you to your preferred version of the laravel documentation.
// @author Patabugen
// @match https://laravel.com/docs/*
// @license MIT
// @grant none
// @run-at document-idle
// @downloadURL https://openuserjs.org/install/Patabugen/LatestLaravel.user.js
// @updateURL https://openuserjs.org/meta/Patabugen/LatestLaravel.meta.js
// @copyright 2017-2026, Patabugen (https://openuserjs.org/users/Patabugen)
// ==/UserScript==
// Change Log
// 0.1 Initial release
// 0.2 Warn when clicking version options
// 1.0 Use local storage to let users set their own preferred version
// 1.1 Change default "latest version" to be Laravel 8 (you can change it by clucking on the version selector on the Docs homepage)
// 1.2 Updated script because laravel.com changed the ID of the version dropdown.
// 1.3 2021-12-03 Updated updateURL
// 1.4 Set default Laravel version to 9.x
// 1.5 Fix not being redirected when changing preferred version when there's an anchor in the URL
// 1.6 Set default Laravel version to 10.x
// 1.7 2023-03-15 Fix versionParts regex not matching two-digit versions (e.g. Laravel 10)
// 1.8 Set default Laravel version to 11.x
// 1.9 Add e.preventDefault() to hook onto the version switcher more reliably
// 1.10 Updated querySelector switch to work on the new Laravel site
// 1.11 Be more flexible about handling preferred version input. Set default Laravel version to 12
// 1.12 Set default Laravel version to 13.x
(function() {
'use strict';
function redirectToPreferredVersion(){
var localStorage = window.localStorage;
var versionParts = document.location.pathname.match(/\/docs\/([0-9]{1,2}.[0-9x])/);
var version = versionParts[1];
var preferredVersion = localStorage.getItem('preferredVersion');
if (!preferredVersion) {
preferredVersion = "13.x";
localStorage.setItem('preferredVersion', preferredVersion);
}
// Compare the versions ignoring any wildcard ".x"
if (parseFloat(version) != parseFloat(preferredVersion.replace('.x', ''))) {
var newUrl = document.location.href.replace('/docs/' + version, '/docs/' + preferredVersion);
document.location.href = newUrl;
}
}
redirectToPreferredVersion();
var switcher = document.querySelector('[aria-label="Laravel version"]');
switcher.onclick = function(e){
e.preventDefault();
var response = confirm("You must disable the LatestLaravel UserScript otherwise you'll just end up back here. Would you like to change your preferred version?");
if (response) {
var versionOptions = switcher.children;
var availableVersions = [];
for (var i = 0; i < versionOptions.length; i++) {
availableVersions.push(versionOptions[i].text);
}
var preferredVersion = prompt("Enter the version you would like?\n\n - " + availableVersions.join("\n - "));
// We want to work whether the user types 'Version' or not, and also if they copy & paste fro our
// alert and their string starts with the hyphen. So normalise the string, and make sure the Version is prefixed.
preferredVersion = preferredVersion.replace('-', '').trim().replace('Version ', '')
if (availableVersions.indexOf('Version ' + preferredVersion) > -1) {
localStorage.setItem('preferredVersion', preferredVersion);
redirectToPreferredVersion();
} else {
alert("Invalid version - please make sure you type it exactly as it appears in the list");
}
}
}
})();