PinkSeaMobile Userscript

Complementary userscript for my userstyle to improve drawing on PinkSea from mobile devices

目前為 2025-01-10 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         PinkSeaMobile Userscript
// @namespace    https://github.com/Driftini/pinkseamobile
// @version      1.0.0
// @description  Complementary userscript for my userstyle to improve drawing on PinkSea from mobile devices
// @author       Driftini (https://github.com/Driftini)
// @match        https://pinksea.art/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=pinksea.art
// @grant        none
// @license      MIT
// ==/UserScript==

function can_load() {
    return document.location.href.endsWith("/paint") || document.location.href.endsWith("/paint/");
}

function load(direct = false) {
    /*
     *  "direct" determines whether or not:
     *      - /paint was loaded through a refresh or from the browser URL bar ()
     *      - /paint was loaded from another page in PinkSea
     */

    try {
        setTimeout(() => {
            document.getElementById("tegaki-ctrlgrp-layers").setAttribute("tabindex", -1);
            document.getElementById("tegaki-ctrlgrp-color").setAttribute("tabindex", -1);

            let msg = "The PinkSea mobile userscript should have loaded successfully!"
            if (!direct)
                msg += "\n\nUpon closing this message, you will be prompted to enter a canvas size."
            alert(msg);

            if (!direct)
                document.querySelector("#tegaki-menu-bar>.tegaki-mb-btn:nth-child(1)").click()
        }, 500);
    }
    catch (e) {
        alert("The PinkSea mobile userscript has attempted to load, but failed.\n\n" + e);
    }
}

(function () {
    'use strict';

    if (can_load())
        load(true);
    else {
        // Copying the original method to not make the code
        // freak out over too much recursion
        let rs = history.replaceState;

        // Allow the script to react to the URL change
        history.replaceState = function () {
            rs.apply(history, arguments);

            // really overrelying on setTimeout here
            setTimeout(() => {
                if (can_load())
                    load(false);
            }, 1000);
        };
    }
})();