deep-rock-wiki

Transform https://deeprockgalactic.wiki.gg pages into https://deeprock.wiki link

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         deep-rock-wiki
// @namespace    https://github.com/imDaniX
// @version      1.2.0
// @description  Transform https://deeprockgalactic.wiki.gg pages into https://deeprock.wiki link
// @author       imDaniX
// @homepageURL  https://github.com/imDaniX/deep-rock-wiki
// @license      MIT; https://opensource.org/license/mit
// @match        https://deeprockgalactic.wiki.gg/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=deeprockgalactic.wiki.gg
// ==/UserScript==

const MAIN_DOMAIN = "deeprock.wiki"
const MAIN_PAGE = "/Deep_Rock_Galactic_Wiki";
const SURVIVOR_NAMESPACE = "/Survivor:"
const SURVIVOR_PAGE = SURVIVOR_NAMESPACE + "Main";
const RC_NAMESPACE = "/Rogue_Core:"
const RC_PAGE = RC_NAMESPACE + "Main";

(function() {
    'use strict';

    addEventListener("copy", (event) => {
        let location = window.location;
        let query = location.search;
        if (hasSelection() || query.includes("action=edit") || query.includes("action=submit")) return;

        let path = location.pathname.replace("index.php", "").replace("/wiki", "");
        let domain = MAIN_DOMAIN;
        if (path == MAIN_PAGE || path == "/") {
            path = "";
        } else if (path.startsWith(SURVIVOR_NAMESPACE)) {
            domain = "survivor." + domain;
            path = path != SURVIVOR_PAGE
                ? path.replace("Survivor:", "")
                : ""
        } else if (path.startsWith(RC_NAMESPACE)) {
            domain = "rc." + domain;
            path = path != RC_PAGE
                ? path.replace("Rogue_Core:", "")
                : ""
        }

        path = decodeURI(path + query + location.hash).replaceAll(" ", "%20");

        event.clipboardData.setData("text/plain", `https://${domain}${path}`);
        event.preventDefault();
    });
})();

/**
 * https://stackoverflow.com/a/5379408
 */
function hasSelection() {
    let text = "";
    const activeEl = document.activeElement;
    const activeElTagName = activeEl ? activeEl.tagName.toLowerCase() : null;

    if (
      (activeElTagName == "textarea") || (activeElTagName == "input" && /^(?:text|search|password|tel|url)$/i.test(activeEl.type)) &&
      (typeof activeEl.selectionStart == "number")
    ) {
        text = activeEl.value.slice(activeEl.selectionStart, activeEl.selectionEnd);
    } else if (window.getSelection) {
        text = window.getSelection().toString();
    }

    return text && text != "";
}