Jump to content

MediaWiki:Common.js

From ICANNWiki
Revision as of 23:53, 22 April 2024 by MarkWD (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
document.addEventListener('DOMContentLoaded', function() {
    console.log("Script running...");
    var links = document.querySelectorAll('a[href*="https://ntldstats.com/tld/"]');
    console.log("Links found: ", links.length);
    links.forEach(function(link) {
        console.log("Original href: ", link.href);
        var url = new URL(link.href);
        var paths = url.pathname.split('/');
        var lastSegment = paths[paths.length - 1];
        if (lastSegment.startsWith('.')) {
            lastSegment = lastSegment.substring(1); // Remove the leading dot
            paths[paths.length - 1] = lastSegment;
            url.pathname = paths.join('/');
            link.href = url.toString();
            console.log("Modified href: ", link.href);
        }
    });
});