crates.io -> lib.rs

Replace all links to crates.io with ones to lib.rs, as the latter is much faster because it doesn't use tons of JavaScript

As of 05. 04. 2020. See the latest version.

// ==UserScript==
// @name         crates.io -> lib.rs
// @version      0.1.5
// @license      GPL-3.0-only; http://www.gnu.org/licenses/gpl-3.0.txt
// @homepageURL  https://github.com/Logarithmus/crates-io-to-lib-rs
// @copyright    2020, Logarithmus (https://github.com/Logarithmus)
// @description  Replace all links to crates.io with ones to lib.rs, as the latter is much faster because it doesn't use tons of JavaScript
// @author       Logarithmus
// @match        *://*/*
// @namespace https://greasyfork.org/users/475664
// ==/UserScript==

(function() {
    if (window.location.hostname === "crates.io") {
        return
    }

    for (let a of document.getElementsByTagName("a")) {
        // Only modify relevant <a> tags to avoid breaking sites
        if (a.hostname === "crates.io"
         && a.pathname.indexOf("/crates/") === 0) {
            a.hostname = "lib.rs"
        }
    }
})();