PPT

Pixel Place Tools

当前为 2022-04-23 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/443807/1043331/PPT.js

  1. // ==UserScript==
  2. // @name PPT
  3. // @description Pixel Place Tools
  4. // @version 1.4.2
  5. // @author 0vC4
  6. // @namespace https://gf.qytechs.cn/users/670183
  7. // @match https://pixelplace.io/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=pixelplace.io
  9. // @license MIT
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14.  
  15.  
  16.  
  17.  
  18. const PPT = (() => {
  19. if (window.PPT) return window.PPT;
  20.  
  21.  
  22.  
  23. const PPT = {
  24. zero: 0xCCCCCC,
  25. default: new Uint32Array([
  26. 0xFFFFFF,
  27. 0xC4C4C4,
  28. 0x888888,
  29. 0x555555,
  30. 0x222222,
  31. 0x000000,
  32. 0x006600,
  33. 0x22B14C,
  34. 0x02BE01,
  35. 0x51E119,
  36. 0x94E044,
  37. 0xFBFF5B,
  38. 0xE5D900,
  39. 0xE6BE0C,
  40. 0xE59500,
  41. 0xA06A42,
  42. 0x99530D,
  43. 0x633C1F,
  44. 0x6B0000,
  45. 0x9F0000,
  46. 0xE50000,
  47. 0xFF3904,
  48. 0xBB4F00,
  49. 0xFF755F,
  50. 0xFFC49F,
  51. 0xFFDFCC,
  52. 0xFFA7D1,
  53. 0xCF6EE4,
  54. 0xEC08EC,
  55. 0x820080,
  56. 0x5100FF,
  57. 0x020763,
  58. 0x0000EA,
  59. 0x044BFF,
  60. 0x6583CF,
  61. 0x36BAFF,
  62. 0x0083C7,
  63. 0x00D3DD,
  64. 0x45FFC8
  65. ]),
  66. exclude: new Uint32Array([
  67. 0x51E119,
  68. 0xFF3904,
  69. 0x5100FF,
  70. 0x45FFC8
  71. ]),
  72. get palette() {
  73. return this.default.map(color => this.exclude.includes(color) ? this.zero : color);
  74. },
  75.  
  76.  
  77.  
  78. _wheelID: 0,
  79. get wheel() {
  80. let pixel = this._wheelID+1;
  81.  
  82. while (this.palette[pixel] == this.zero)
  83. if (this.palette[++pixel] == null)
  84. pixel = 0;
  85.  
  86. this._wheelID = pixel;
  87. return this._wheelID;
  88. },
  89.  
  90.  
  91.  
  92. RGB2P(r, g, b) {
  93. const closest = [...this.palette]
  94. .filter(n => n != this.zero)
  95. .map(clr =>
  96. [
  97. ((r - ((clr>>16)&0xFF))*.299)**2 +
  98. ((g - ((clr>>8)&0xFF))*.587)**2 +
  99. ((b - (clr&0xFF))*.114)**2,
  100. clr
  101. ]
  102. )
  103. .sort((a,b) => a[0]-b[0])
  104. [0][1];
  105.  
  106. return this.palette.indexOf(closest);
  107. },
  108. CLR2P(color) {
  109. return this.RGB2P((color>>16)&0xFF, (color>>8)&0xFF, color&0xFF);
  110. },
  111. timer: window,
  112. pixel: 0,
  113. size: 1,
  114. square(x,y,callback) {
  115. const half = (this.size>>1);
  116. const {pixel, timer} = this;
  117. let xi = -half;
  118. let yi = -half;
  119. let t = timer.setInterval(() => {
  120. for (; yi < half+1;) {
  121. for (; xi < half+1;) {
  122. callback(x+xi, y+yi, pixel);
  123. xi++;
  124. return;
  125. }
  126. yi++;
  127. xi = -half;
  128. }
  129. timer.clearInterval(t);
  130. return;
  131. });
  132. return t;
  133. },
  134. image(pixels, x,y,w,h, callback) {
  135. const {timer} = this;
  136. let xi = 0;
  137. let yi = 0;
  138. let t = timer.setInterval(() => {
  139. for (; yi < h;) {
  140. for (; xi < w;) {
  141. const pixel = pixels[xi+yi*w];
  142. if (pixel === 255) {
  143. xi++;
  144. continue;
  145. }
  146. callback(x+xi, y+yi, pixel);
  147. xi++;
  148. return;
  149. }
  150. yi++;
  151. xi = 0;
  152. }
  153. timer.clearInterval(t);
  154. return;
  155. });
  156. return t;
  157. }
  158. };
  159.  
  160.  
  161.  
  162. window.PPT = PPT;
  163. return PPT;
  164. })();
  165. // 0vC4#7152

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址