deep-rock-wiki

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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 != "";
}