Linux.do Watermark Neo

Force watermark username to 'neo'

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ć!)

Advertisement:

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ć!)

Advertisement:

// ==UserScript==
// @name         Linux.do Watermark Neo
// @namespace    http://tampermonkey.net/
// @description  Force watermark username to 'neo'
// @version      1.1
// @match        https://linux.do/*
// @icon         https://linux.do/favicon.ico
// @grant        unsafeWindow
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const rawAttach = Element.prototype.attachShadow;
    Element.prototype.attachShadow = function(init) {
        if (init && init.mode === 'closed') {
            init.mode = 'open';
            const shadowRoot = rawAttach.call(this, init);
            const style = document.createElement('style');
            style.textContent = 'div { opacity: 0 !important; visibility: hidden !important; pointer-events: none !important; }';
            shadowRoot.appendChild(style);
            return shadowRoot;
        }
        return rawAttach.call(this, init);
    };

    const CONFIG = {
        text: "neo",
        id: "ld-wm-neo-force",
        density: 130,
        intensity: 2,
        angle: -25,
        font: "bold 15px sans-serif"
    };

    function generateWatermark() {
        if (document.getElementById(CONFIG.id)) return;

        const dpr = window.devicePixelRatio || 1;
        const canvas = document.createElement("canvas");
        const size = CONFIG.density * dpr;

        canvas.width = size;
        canvas.height = size;

        const ctx = canvas.getContext("2d");
        ctx.scale(dpr, dpr);
        ctx.translate(CONFIG.density / 2, CONFIG.density / 2);
        ctx.rotate(CONFIG.angle * Math.PI / 180);
        ctx.font = CONFIG.font;
        ctx.textAlign = "center";
        ctx.textBaseline = "middle";
        ctx.fillStyle = `rgb(${CONFIG.intensity}, ${CONFIG.intensity}, ${CONFIG.intensity})`;
        ctx.fillText(`@${CONFIG.text}`, 0, 0);

        const div = document.createElement("div");
        div.id = CONFIG.id;
        div.style.cssText = `
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            z-index: 2147483647;
            pointer-events: none;
            background-image: url(${canvas.toDataURL("image/png")});
            background-repeat: repeat;
            background-size: ${CONFIG.density}px;
            mix-blend-mode: difference;
            opacity: 1;
        `;
        document.body.appendChild(div);
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', generateWatermark);
    } else {
        generateWatermark();
    }
})();