Pixelplanet+

Customize the PixelPlanet interface with extended personalization options and revert to default.

目前为 2024-11-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Pixelplanet+
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.5
  5. // @author Pixel, join dsc.gg/turkmenlippf
  6. // @description Customize the PixelPlanet interface with extended personalization options and revert to default.
  7. // @match https://pixelplanet.fun/*
  8. // @grant GM_addStyle
  9. // @icon https://cdn.discordapp.com/attachments/1295091021016862782/1305807684657876992/image.png?ex=67345fac&is=67330e2c&hm=f8dac6f7693c5f04b3e07bcb82e41885ec1bfdae62ae0a39da2739452dcdeff3&
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Import Pixelify Sans font from Google Fonts (or other font source)
  16. GM_addStyle(`
  17. @import url('https://fonts.googleapis.com/css2?family=Pixelify+Sans&display=swap');
  18. `);
  19.  
  20. // Default CSS code (content of default.css)
  21. const defaultCSS = `
  22. /* Default CSS codes here */
  23. body {
  24. margin: 0;
  25. font-family: 'Montserrat', sans-serif;
  26. font-size: 16px;
  27. border: none;
  28. user-select: none;
  29. background: #c4c4c4;
  30. }
  31. .menu > div {
  32. background-color: transparent !important;
  33. }
  34. `;
  35.  
  36. // Apply customizations when the page loads
  37. const applyStoredStyles = () => {
  38. const buttonColor = getStoredValue('buttonColor', '#4CAF50');
  39. const buttonHoverColor = getStoredValue('buttonHoverColor', '#ff91a6');
  40. const tableRowEvenColor = getStoredValue('tableRowEvenColor', '#61dcea');
  41. const tableRowOddColor = getStoredValue('tableRowOddColor', '#ffb1e1');
  42. const fontColor = getStoredValue('fontColor', '#000000');
  43. const fontSize = getStoredValue('fontSize', '16');
  44. const fontFamily = getStoredValue('fontFamily', 'Arial');
  45. const backgroundOpacity = getStoredValue('backgroundOpacity', '1');
  46. const backgroundImage = getStoredValue('backgroundImage', '');
  47.  
  48. applyCustomStyles(buttonColor, buttonHoverColor, tableRowEvenColor, tableRowOddColor, fontColor, fontSize, fontFamily, backgroundOpacity, backgroundImage);
  49. };
  50.  
  51. // Reset to default CSS
  52. const resetToDefaultStyles = () => {
  53. localStorage.clear(); // Clear localStorage
  54. GM_addStyle(defaultCSS); // Load default CSS
  55. applyStoredStyles(); // Apply customizations
  56. };
  57.  
  58. // Get stored user data
  59. const getStoredValue = (key, defaultValue) => {
  60. return localStorage.getItem(key) || defaultValue;
  61. };
  62.  
  63. // Store user data
  64. const setStoredValue = (key, value) => {
  65. localStorage.setItem(key, value);
  66. };
  67.  
  68. // Apply custom styles to the page
  69. const applyCustomStyles = (buttonColor, buttonHoverColor, tableRowEvenColor, tableRowOddColor, fontColor, fontSize, fontFamily, backgroundOpacity, backgroundImage) => {
  70. GM_addStyle(`
  71. body {
  72. background-color: rgba(255, 255, 255, ${backgroundOpacity});
  73. background-image: url(${backgroundImage});
  74. }
  75. .actionbuttons, .actionbuttons button {
  76. background-color: ${buttonColor} !important;
  77. color: white !important;
  78. }
  79. .actionbuttons:hover, .actionbuttons button:hover {
  80. background-color: ${buttonHoverColor} !important;
  81. }
  82. table tr:nth-child(even) {
  83. background-color: ${tableRowEvenColor};
  84. }
  85. table tr:nth-child(odd) {
  86. background-color: ${tableRowOddColor};
  87. }
  88. body, .content {
  89. font-size: ${fontSize}px;
  90. font-family: ${fontFamily};
  91. color: ${fontColor};
  92. }
  93. `);
  94. };
  95.  
  96. // Add customization button
  97. const addCustomizationButton = () => {
  98. const customizationButton = document.createElement('div');
  99. customizationButton.id = 'customizationButton';
  100. customizationButton.className = 'actionbuttons';
  101. customizationButton.setAttribute('role', 'button');
  102. customizationButton.setAttribute('title', 'Customization');
  103. customizationButton.innerHTML = `
  104. <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg">
  105. <circle cx="12" cy="12" r="10" style="fill: #FFC107;" />
  106. <text x="12" y="16" text-anchor="middle" fill="white" font-size="10">K</text>
  107. </svg>`;
  108.  
  109. customizationButton.style.position = 'fixed';
  110. customizationButton.style.left = '16px';
  111. customizationButton.style.top = '37%';
  112. customizationButton.style.zIndex = '9999';
  113. customizationButton.style.transform = 'translateY(-50%)';
  114.  
  115. document.body.appendChild(customizationButton);
  116. customizationButton.addEventListener('click', showCustomizationPanel);
  117. };
  118.  
  119. // Create the customization panel
  120. const createCustomizationPanel = () => {
  121. const panelHTML = `
  122. <div class="modal TEMPLATES show" style="z-index: 9998; width: 60%; max-width: 600px; padding: 20px; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: white; border: 1px solid #ccc; border-radius: 10px;">
  123. <h2>Customization</h2>
  124. <div class="modal-topbtn close" role="button" title="Close" style="position: absolute; top: 10px; right: 10px; cursor: pointer;">✕</div>
  125. <div class="modal-content">
  126. <div style="padding-top: 10px;">
  127. <div>
  128. <label>Button Color:</label>
  129. <input type="color" id="buttonColorPicker" value="${getStoredValue('buttonColor', '#4CAF50')}" />
  130. </div>
  131. <div>
  132. <label>Button Hover Color:</label>
  133. <input type="color" id="buttonHoverColorPicker" value="${getStoredValue('buttonHoverColor', '#ff91a6')}" />
  134. </div>
  135. <div>
  136. <label>Table Row Colors - Even:</label>
  137. <input type="color" id="tableRowEvenColorPicker" value="${getStoredValue('tableRowEvenColor', '#61dcea')}" />
  138. </div>
  139. <div>
  140. <label>Table Row Colors - Odd:</label>
  141. <input type="color" id="tableRowOddColorPicker" value="${getStoredValue('tableRowOddColor', '#ffb1e1')}" />
  142. </div>
  143. <div>
  144. <label>Font Color:</label>
  145. <input type="color" id="fontColorPicker" value="${getStoredValue('fontColor', '#000000')}" />
  146. </div>
  147. <div>
  148. <label>Font Size:</label>
  149. <input type="number" id="fontSizePicker" min="10" max="30" value="${getStoredValue('fontSize', '16')}" /> px
  150. </div>
  151. <div>
  152. <label>Font Family:</label>
  153. <select id="fontFamilyPicker">
  154. <option value="Arial" ${getStoredValue('fontFamily', 'Arial') === 'Arial' ? 'selected' : ''}>Arial</option>
  155. <option value="Verdana" ${getStoredValue('fontFamily', 'Arial') === 'Verdana' ? 'selected' : ''}>Verdana</option>
  156. <option value="Helvetica" ${getStoredValue('fontFamily', 'Arial') === 'Helvetica' ? 'selected' : ''}>Helvetica</option>
  157. <option value="Tahoma" ${getStoredValue('fontFamily', 'Arial') === 'Tahoma' ? 'selected' : ''}>Tahoma</option>
  158. <option value="Pixelify Sans" ${getStoredValue('fontFamily', 'Arial') === 'Pixelify Sans' ? 'selected' : ''}>Pixelify Sans</option>
  159. </select>
  160. </div>
  161. <div>
  162. <label>Background Opacity:</label>
  163. <input type="range" id="backgroundOpacity" min="0.1" max="1" step="0.1" value="${getStoredValue('backgroundOpacity', '1')}" />
  164. </div>
  165. <div>
  166. <label>Background Image URL:</label>
  167. <input type="text" id="backgroundImage" value="${getStoredValue('backgroundImage', '')}" />
  168. </div>
  169. <div style="margin-top: 10px;">
  170. <button id="saveCustomization">Save</button>
  171. <button id="resetCustomization">Reset</button>
  172. </div>
  173. </div>
  174. </div>
  175. </div>`;
  176.  
  177. document.body.insertAdjacentHTML('beforeend', panelHTML);
  178.  
  179. document.getElementById('saveCustomization').addEventListener('click', saveCustomization);
  180. document.getElementById('resetCustomization').addEventListener('click', resetToDefaultStyles);
  181. document.querySelector('.close').addEventListener('click', hideCustomizationPanel);
  182. };
  183.  
  184. // Save the customization
  185. const saveCustomization = () => {
  186. const buttonColor = document.getElementById('buttonColorPicker').value;
  187. const buttonHoverColor = document.getElementById('buttonHoverColorPicker').value;
  188. const tableRowEvenColor = document.getElementById('tableRowEvenColorPicker').value;
  189. const tableRowOddColor = document.getElementById('tableRowOddColorPicker').value;
  190. const fontColor = document.getElementById('fontColorPicker').value;
  191. const fontSize = document.getElementById('fontSizePicker').value;
  192. const fontFamily = document.getElementById('fontFamilyPicker').value;
  193. const backgroundOpacity = document.getElementById('backgroundOpacity').value;
  194. const backgroundImage = document.getElementById('backgroundImage').value;
  195.  
  196. // Save to localStorage
  197. setStoredValue('buttonColor', buttonColor);
  198. setStoredValue('buttonHoverColor', buttonHoverColor);
  199. setStoredValue('tableRowEvenColor', tableRowEvenColor);
  200. setStoredValue('tableRowOddColor', tableRowOddColor);
  201. setStoredValue('fontColor', fontColor);
  202. setStoredValue('fontSize', fontSize);
  203. setStoredValue('fontFamily', fontFamily);
  204. setStoredValue('backgroundOpacity', backgroundOpacity);
  205. setStoredValue('backgroundImage', backgroundImage);
  206.  
  207. applyCustomStyles(buttonColor, buttonHoverColor, tableRowEvenColor, tableRowOddColor, fontColor, fontSize, fontFamily, backgroundOpacity, backgroundImage);
  208. };
  209.  
  210. // Show the customization panel
  211. const showCustomizationPanel = () => {
  212. createCustomizationPanel();
  213. };
  214.  
  215. // Hide the customization panel
  216. const hideCustomizationPanel = () => {
  217. const panel = document.querySelector('.modal');
  218. if (panel) {
  219. panel.remove();
  220. }
  221. };
  222.  
  223. // On page load, apply previous customizations
  224. applyStoredStyles();
  225. addCustomizationButton();
  226. })();