Jump to content

User:Taavi/Unslashifier.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Superpes15 (talk | contribs) at 13:31, 20 June 2022 (Superpes15 moved page User:Majavah/Unslashifier.js to User:Taavi/Unslashifier.js: Automatically moved page while renaming the user "Majavah" to "Taavi"). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
 * Unslashifier by [[User:Majavah]] @ en.wikipedia.org
 * A user script that redirects accidental navigation to 404's ending in a slash (say, Foo/) to the normal page (Foo)
 */
$(function() {
    var pageName = mw.config.get('wgPageName');
    if (pageName.endsWith('/') && document.querySelector('#p-namespaces .selected.new')) {
        var url = mw.util.getUrl(pageName.slice(0, -1));
        window.location.href = url;
    }
});