PinkSeaMobile Userscript

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

当前为 2025-01-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name PinkSeaMobile Userscript
  3. // @namespace https://github.com/Driftini/pinkseamobile
  4. // @version 1.0.0
  5. // @description Complementary userscript for my userstyle to improve drawing on PinkSea from mobile devices
  6. // @author Driftini (https://github.com/Driftini)
  7. // @match https://pinksea.art/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=pinksea.art
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. function can_load() {
  14. return document.location.href.endsWith("/paint") || document.location.href.endsWith("/paint/");
  15. }
  16.  
  17. function load(direct = false) {
  18. /*
  19. * "direct" determines whether or not:
  20. * - /paint was loaded through a refresh or from the browser URL bar ()
  21. * - /paint was loaded from another page in PinkSea
  22. */
  23.  
  24. try {
  25. setTimeout(() => {
  26. document.getElementById("tegaki-ctrlgrp-layers").setAttribute("tabindex", -1);
  27. document.getElementById("tegaki-ctrlgrp-color").setAttribute("tabindex", -1);
  28.  
  29. let msg = "The PinkSea mobile userscript should have loaded successfully!"
  30. if (!direct)
  31. msg += "\n\nUpon closing this message, you will be prompted to enter a canvas size."
  32. alert(msg);
  33.  
  34. if (!direct)
  35. document.querySelector("#tegaki-menu-bar>.tegaki-mb-btn:nth-child(1)").click()
  36. }, 500);
  37. }
  38. catch (e) {
  39. alert("The PinkSea mobile userscript has attempted to load, but failed.\n\n" + e);
  40. }
  41. }
  42.  
  43. (function () {
  44. 'use strict';
  45.  
  46. if (can_load())
  47. load(true);
  48. else {
  49. // Copying the original method to not make the code
  50. // freak out over too much recursion
  51. let rs = history.replaceState;
  52.  
  53. // Allow the script to react to the URL change
  54. history.replaceState = function () {
  55. rs.apply(history, arguments);
  56.  
  57. // really overrelying on setTimeout here
  58. setTimeout(() => {
  59. if (can_load())
  60. load(false);
  61. }, 1000);
  62. };
  63. }
  64. })();