Greasy Fork is available in English.

Diep.style

Press Esc twice to toggle the menu,and save the setting

  1. // ==UserScript==
  2. // @name Diep.style
  3. // @namespace https://www.reddit.com/r/Diepio/comments/5y1np1/diepstyle_plugin/
  4. // @version 0.097
  5. // @description Press Esc twice to toggle the menu,and save the setting
  6. // @author sbk2015
  7. // @match https://*diep.io/*
  8. // @grant none
  9. // @run-at document-idle
  10.  
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15. const jsColorPackage=`https://cdnjs.cloudflare.com/ajax/libs/jscolor/2.0.4/jscolor.min.js`;
  16. var localStorage;
  17. var saveList;
  18. var nowSetting;
  19. var isLocal;
  20. var clone;
  21. jsInit();
  22. setTimeout(pluginInit, 2000);
  23.  
  24. function jsInit() {
  25. Storage.prototype.setObject = function (key, value) {
  26. this.setItem(key, JSON.stringify(value));
  27. };
  28. Storage.prototype.getObject = function (key) {
  29. var value = this.getItem(key);
  30. return value && JSON.parse(value);
  31. };
  32. clone = function (obj) {
  33. return JSON.parse(JSON.stringify(obj));
  34. };
  35. window.diepStyle = {};
  36. localStorage = window.localStorage;
  37. if (location.href.indexOf("file://") >= 0) {
  38. var warning = false;
  39. warning ? "" : console.warn("off warning");
  40. isLocal = true;
  41. window.input = {
  42. set_convar: function () {
  43. warning ? console.warn("block input.set_convar") : "";
  44. },
  45. execute: function () {
  46. warning ? console.warn("block input.set_execute") : "";
  47. },
  48. };
  49. }
  50. }
  51.  
  52. function pluginInit() {
  53. storageInit();
  54. keyListen();
  55. tempInit();
  56. styleInit();
  57. diepStyle.onColor = onColor;
  58. diepStyle.storageInit = storageInit;
  59. //togglePanel(true);
  60.  
  61. function storageInit(cmd) {
  62. var th = 50,
  63. netTH = 110;
  64. var colors = [
  65. {
  66. id: 2,
  67. name: "You FFA",
  68. color: "00b1de",
  69. },
  70. {
  71. id: 15,
  72. name: "Other FFA",
  73. color: "f14e54",
  74. },
  75. {
  76. id: 3,
  77. name: "Blue Team",
  78. color: "00b1de",
  79. },
  80. {
  81. id: 4,
  82. name: "Red Team",
  83. color: "f14e54",
  84. },
  85. {
  86. id: 5,
  87. name: "Purple Team",
  88. color: "bf7ff5",
  89. },
  90. {
  91. id: 6,
  92. name: "Green Team",
  93. color: "00e16e",
  94. },
  95. {
  96. id: 17,
  97. name: "Fallen team",
  98. color: "c6c6c6",
  99. },
  100. {
  101. id: 12,
  102. name: "Arena Closer",
  103. color: "ffe869",
  104. },
  105. {
  106. id: 8,
  107. name: "Square",
  108. color: "ffe869",
  109. },
  110. {
  111. id: 7,
  112. name: "Green Square?",
  113. color: "89ff69",
  114. },
  115. {
  116. id: 16,
  117. name: "Necro Square",
  118. color: "fcc376",
  119. },
  120. {
  121. id: 9,
  122. name: "Triangle",
  123. color: "fc7677",
  124. },
  125. {
  126. id: 10,
  127. name: "Pentagon",
  128. color: "768dfc",
  129. },
  130. {
  131. id: 11,
  132. name: "Crasher",
  133. color: "f177dd",
  134. },
  135. {
  136. id: 14,
  137. name: "Waze Wall",
  138. color: "bbbbbb",
  139. },
  140. {
  141. id: 1,
  142. name: "Turret",
  143. color: "999999",
  144. },
  145. {
  146. id: 0,
  147. name: "Smasher",
  148. color: "4f4f4f",
  149. },
  150. {
  151. id: th++,
  152. name: "All Bars",
  153. color: "000000",
  154. cmd: "ren_bar_background_color",
  155. },
  156. {
  157. id: th++,
  158. name: "Outline",
  159. color: "555555",
  160. cmd: "ren_stroke_solid_color",
  161. },
  162. {
  163. id: 13,
  164. name: "Leader Board",
  165. color: "64ff8c",
  166. },
  167. {
  168. id: th++,
  169. name: "Xp Bar",
  170. color: "ffde43",
  171. cmd: "ren_xp_bar_fill_color",
  172. },
  173. {
  174. id: th++,
  175. name: "Score Bar",
  176. color: "43ff91",
  177. cmd: "ren_score_bar_fill_color",
  178. },
  179. {
  180. id: th++,
  181. name: "Health Bar1",
  182. color: "85e37d",
  183. cmd: "ren_health_fill_color",
  184. },
  185. {
  186. id: th++,
  187. name: "Health Bar2",
  188. color: "555555",
  189. cmd: "ren_health_background_color",
  190. },
  191. {
  192. id: th++,
  193. name: "Grid Color",
  194. color: "000000",
  195. cmd: "ren_grid_color",
  196. },
  197. {
  198. id: th++,
  199. name: "Minimap 1",
  200. color: "CDCDCD",
  201. cmd: "ren_minimap_background_color",
  202. },
  203. {
  204. id: th++,
  205. name: "Minimap 2",
  206. color: "797979",
  207. cmd: "ren_minimap_border_color",
  208. },
  209. {
  210. id: th++,
  211. name: "Background 1",
  212. color: "CDCDCD",
  213. cmd: "ren_background_color",
  214. },
  215. {
  216. id: th++,
  217. name: "Background 2",
  218. color: "797979",
  219. cmd: "ren_border_color",
  220. },
  221. {
  222. id: netTH++,
  223. name: "UI Color1",
  224. color: "e69f6c",
  225. cmd: "ui_replace_colors",
  226. },
  227. {
  228. id: netTH++,
  229. name: "UI Color2",
  230. color: "ff73ff",
  231. cmd: "ui_replace_colors",
  232. },
  233. {
  234. id: netTH++,
  235. name: "UI Color3",
  236. color: "c980ff",
  237. cmd: "ui_replace_colors",
  238. },
  239. {
  240. id: netTH++,
  241. name: "UI Color4",
  242. color: "71b4ff",
  243. cmd: "ui_replace_colors",
  244. },
  245. {
  246. id: netTH++,
  247. name: "UI Color5",
  248. color: "ffed3f",
  249. cmd: "ui_replace_colors",
  250. },
  251. {
  252. id: netTH++,
  253. name: "UI Color6",
  254. color: "ff7979",
  255. cmd: "ui_replace_colors",
  256. },
  257. {
  258. id: netTH++,
  259. name: "UI Color7",
  260. color: "88ff41",
  261. cmd: "ui_replace_colors",
  262. },
  263. {
  264. id: netTH++,
  265. name: "UI Color8",
  266. color: "41ffff",
  267. cmd: "ui_replace_colors",
  268. },
  269. ];
  270. diepStyle.colorMap = new Map(
  271. colors.map(function (elem) {
  272. return [
  273. elem.id,
  274. {
  275. color: elem.color,
  276. cmd: elem.cmd || "no cmd",
  277. },
  278. ];
  279. })
  280. );
  281.  
  282. diepStyle.uiColorMap = function (cmd) {
  283. var uiTH = nowSetting.colors.findIndex(
  284. (elem) => elem.name == "UI Color1"
  285. );
  286. var colorBunch = "";
  287. var arr = [];
  288. if (cmd == "0x") {
  289. for (var i = 0; i < 8; i++) {
  290. colorBunch = " 0x" + nowSetting.colors[uiTH + i].color + colorBunch;
  291. }
  292. return colorBunch;
  293. }
  294. if (cmd == "array") {
  295. for (var i = 0; i < 8; i++) {
  296. arr.push(nowSetting.colors[uiTH + i].color);
  297. }
  298. return arr;
  299. }
  300. };
  301. var renders = [
  302. {
  303. name: "Grid Alpha",
  304. value: 0.1,
  305. cmd: "grid_base_alpha",
  306. },
  307. {
  308. name: "Outline Intensity",
  309. value: 0.25,
  310. cmd: "stroke_soft_color_intensity",
  311. },
  312. {
  313. name: "Show Outline",
  314. value: false,
  315. cmd: "stroke_soft_color",
  316. reverse: true,
  317. },
  318. {
  319. name: "Border Alpha",
  320. value: 0.1,
  321. cmd: "border_color_alpha",
  322. },
  323. {
  324. name: "UI Scale",
  325. value: 1,
  326. cmd: "ui_scale",
  327. },
  328. {
  329. name: "Clear UI",
  330. value: false,
  331. cmd: "ui",
  332. reverse: true,
  333. },
  334. {
  335. name: "Show FPS",
  336. value: false,
  337. cmd: "fps",
  338. },
  339. {
  340. name: "Show Health",
  341. value: false,
  342. cmd: "raw_health_values",
  343. },
  344. {
  345. name: "Hide Name",
  346. value: false,
  347. cmd: "names",
  348. reverse: true,
  349. },
  350. ];
  351.  
  352. (function checkHasStorage() {
  353. var _localStorage = localStorage.getObject("diepStyle");
  354. var page = 1;
  355. if (nowSetting && nowSetting.saveTH) {
  356. page = nowSetting.saveTH;
  357. }
  358. if (_localStorage && _localStorage.saveList) {
  359. saveList = _localStorage.saveList;
  360. nowSetting = _localStorage.nowSetting;
  361. }
  362. if (!nowSetting || cmd == "reset") {
  363. nowSetting = getBlankSetting();
  364. nowSetting.saveTH = page;
  365. }
  366.  
  367. if (!saveList) saveList = getBlankSaveList();
  368. saveList[0] = getBlankSetting();
  369. (function checkMissing() {
  370. var plain = getBlankSetting();
  371. plain.renders.forEach((elem, th) => {
  372. var index = nowSetting.renders.findIndex(
  373. (now) => elem.cmd == now.cmd
  374. );
  375. if (index < 0) {
  376. nowSetting.renders.splice(th, 0, elem);
  377. saveList[nowSetting.saveTH].renders.splice(th, 0, elem);
  378. }
  379. });
  380. plain.colors.forEach((elem, th) => {
  381. var index = nowSetting.colors.findIndex((now) => {
  382. if (elem.cmd && elem.cmd == now.cmd) return true;
  383. if ((elem.id || elem.id == 0) && elem.id == now.id) return true;
  384. });
  385. if (index < 0) {
  386. nowSetting.colors.splice(th, 0, elem);
  387. saveList[nowSetting.saveTH].colors.splice(th, 0, elem);
  388. }
  389. });
  390. })();
  391. })();
  392.  
  393. (function command() {
  394. diepStyle.command = {};
  395. renders.forEach((elem) => {
  396. diepStyle.command[elem.cmd] = {};
  397. if (elem.reverse) diepStyle.command[elem.cmd].reverse = true;
  398. });
  399. diepStyle.command.fn = function (cmd, value) {
  400. nowSetting.renders = nowSetting.renders.map((elem) => {
  401. if (elem.cmd == cmd) elem.value = value;
  402. return elem;
  403. });
  404. if (diepStyle.command[cmd].reverse) value = !value;
  405. input.set_convar("ren_" + cmd, value);
  406. };
  407. })();
  408.  
  409. function getBlankSetting() {
  410. return {
  411. version: 0.097,
  412. saveTH: 1,
  413. lock: false,
  414. colors,
  415. renders,
  416. };
  417. }
  418.  
  419. function getBlankSaveList() {
  420. var list = [];
  421. for (var i = 0; i < 6; i++) {
  422. list[i] = getBlankSetting();
  423. if (i == 0) list[i].isDefault = "default,no save";
  424. }
  425. return clone(list);
  426. }
  427. Storage.prototype.pluginSave = function () {
  428. saveList[nowSetting.saveTH] = clone(nowSetting);
  429. var _storageObj = {
  430. nowSetting: clone(nowSetting),
  431. saveList: clone(saveList),
  432. };
  433. localStorage.setObject("diepStyle", _storageObj);
  434. };
  435. localStorage.pluginSave();
  436. }
  437.  
  438. function keyListen() {
  439. var input = "";
  440. document.addEventListener("keyup", function (evt) {
  441. var that = this;
  442. if (that.pluginOn == undefined) that.pluginOn = false;
  443. var e = window.event || evt;
  444. var key = e.which || e.keyCode;
  445. input += key;
  446. if (input.indexOf("2727") >= 0) {
  447. input = "";
  448. that.pluginOn = !that.pluginOn;
  449. togglePanel(that.pluginOn);
  450. (function save() {
  451. if (!that.pluginOn) {
  452. localStorage.pluginSave();
  453. }
  454. })();
  455. }
  456. if (input.length > 10) input = input.substring(input.length - 10);
  457. });
  458. }
  459.  
  460. function tempInit() {
  461. var colorObj = {
  462. th: 0,
  463. };
  464. var setObj = {
  465. th: 0,
  466. };
  467.  
  468. diepStyle.exportJSON = exportJSON;
  469. diepStyle.importJSON = importJSON;
  470. init1();
  471. loadColor();
  472. setTimeout(diepStyle.resetRender, 1500);
  473. diepStyle.resetColor = loadColor;
  474.  
  475. function init1() {
  476. diepStyle.resetRender = resetRender;
  477.  
  478. var title = `<div class="title">Diep.Style Ver 0.096<br>
  479. Press Esc twice to toggle this</div>`;
  480.  
  481. var colorPlane = function (id) {
  482. return `{position:'left',width:300, height:200,onFineChange:'diepStyle.onColor(${id},this)'}`;
  483. };
  484.  
  485. colorObj.setClass = function () {
  486. return `colorBlock colorBlock${this.th++}`;
  487. };
  488. setObj.setClass = function () {
  489. return `setting setting${this.th++}`;
  490. };
  491.  
  492. function resetRender(cmd) {
  493. document
  494. .querySelectorAll("#styleSetting .render")
  495. .forEach(function (elem) {
  496. elem.outerHTML = ``;
  497. });
  498. var it = document.querySelector(".renderBegin");
  499. it.insertAdjacentHTML("afterend", getRenderBody());
  500. it.remove();
  501. nowSetting.renders.forEach(function (elem) {
  502. diepStyle.command.fn(elem.cmd, elem.value);
  503. });
  504. listenerInit(cmd);
  505. }
  506. var bodyTheme = getThemeBody();
  507. var bodyRender = getRenderBody();
  508. var bodyColor = getColorBody();
  509. var bodyImport = getImportBody();
  510.  
  511. function getThemeBody() {
  512. var th = 0;
  513. var html = `
  514. <div class="themeBody">
  515. <div class="themeBegin">Theme</div>
  516. <div class="header hide themeDesc">
  517. <span class="name"></span>
  518. <span class="author"></span>
  519. </div>
  520. <div class="theme">
  521. <div class="list">
  522. <div data-theme="dark"><img src="https://imgur.com/bFyXqs5.jpg"><br>Dark</div>
  523. <div data-theme="glass"><img src="https://imgur.com/4fnXdkE.jpg"><br>Glass</div>
  524. <div data-theme="moomoo"><img src="https://imgur.com/XJwGabH.jpg"><br>Moomoo</div>
  525. <div data-theme="80s"><img src="https://imgur.com/9Lma43A.jpg"><br>80s </div>
  526. </div>
  527. </div>
  528. </div>
  529. `;
  530. return html;
  531. }
  532.  
  533. function getRenderBody() {
  534. var renders = nowSetting.renders;
  535. var th = -1;
  536. var html = `
  537. <div class="renderBegin">Render</div>
  538.  
  539. <div class="row render">
  540. <div class="cell">${
  541. renders[++th].name
  542. } <br><span class="grid_base_value">${
  543. renders[th].value
  544. }</span></div>
  545. <div class="cell"><input type="range" name="grid_base_alpha" value=${
  546. renders[th].value * 100
  547. } max="200"></div>
  548. </div>
  549. <div class="row render">
  550. <div class="cell">${
  551. renders[++th].name
  552. } <br><span class="stroke_intensity_value">${
  553. renders[th].value
  554. }</span></div>
  555. <div class="cell"><input type="range" name="stroke_soft_color_intensity" value=${
  556. renders[th].value * 100
  557. } max="100"></div>
  558. </div>
  559. <div class="row render">
  560. <div class="cell">${renders[++th].name}</div>
  561. <div class="cell"><input type="checkbox" name="stroke_soft_color" ${
  562. renders[th].value ? "checked" : ""
  563. }></div>
  564. </div>
  565. <div class="row render">
  566. <div class="cell">${
  567. renders[++th].name
  568. } <br><span class="border_value">${
  569. renders[th].value
  570. }</span></div>
  571. <div class="cell"><input type="range" name="border_color_alpha" value=${
  572. renders[th].value * 100
  573. } max="100"></div>
  574. </div>
  575. <div class="row render">
  576. <div class="cell">${
  577. renders[++th].name
  578. } <br><span class="ui_scale_value">${
  579. renders[th].value
  580. }</span></div>
  581. <div class="cell"><input type="range" name="ui_scale" value=${
  582. renders[th].value * 100
  583. } max="200"></div>
  584. </div>
  585. <div class="row render">
  586. <div class="cell">${renders[++th].name}</div>
  587. <div class="cell"><input type="checkbox" name="ui" ${
  588. renders[th].value ? "checked" : ""
  589. }></div>
  590. </div>
  591. <div class="row render">
  592. <div class="cell">${renders[++th].name}</div>
  593. <div class="cell"><input type="checkbox" name="fps" ${
  594. renders[th].value ? "checked" : ""
  595. }></div>
  596. </div>
  597. <div class="row render">
  598. <div class="cell">${renders[++th].name}</div>
  599. <div class="cell"><input type="checkbox" name="raw_health_values" ${
  600. renders[th].value ? "checked" : ""
  601. }></div>
  602. </div>
  603. <div class="row render">
  604. <div class="cell">${renders[++th].name}</div>
  605. <div class="cell"><input type="checkbox" name="names" ${
  606. renders[th].value ? "checked" : ""
  607. }></div>
  608. </div>
  609. `;
  610. return html;
  611. }
  612.  
  613. function getColorBody() {
  614. var it = `<div class="row colorBegin">Color</div>\n`;
  615. nowSetting.colors.forEach(function (elem, th) {
  616. var id = elem.id;
  617. it += `
  618. <div class="row colorBlock colorBlock${th}">
  619. <div class="cell"></div>
  620. <div class="cell"><input class="jscolor ${colorPlane(
  621. `${id}`
  622. )}"> </div>
  623. </div>
  624. `;
  625. });
  626. return it;
  627. }
  628.  
  629. var allBody = `
  630. <div class="pluginBody">${title}
  631. <hr>
  632. ${bodyTheme}
  633. <div class="table">
  634. ${bodyRender} ${bodyColor} <br>
  635. </div>
  636. </div>
  637. `;
  638. var getSaveBtns = function () {
  639. var btn = "";
  640. for (var i = 0; i < 6; i++) {
  641. if (i == 0) {
  642. btn += `<button>Default</button>`;
  643. continue;
  644. }
  645. btn += `<button>${i}</button>`;
  646. }
  647. return btn;
  648. };
  649.  
  650. function getImportBody() {
  651. var html = `
  652. <div class="importBegin">Import / Export Save</div>
  653. <div class="row">
  654. <div class="cell">
  655. <button class="import">Import</button>
  656. </div>
  657. <div class="cell">
  658. <button class="export">Export</button>
  659. </div>
  660. </div>
  661. `;
  662. return html;
  663. }
  664. // <button class="selectTheme">Theme</button>
  665. var footer = `
  666. <div class="footer">
  667. <div class="saveBtns">${getSaveBtns()}</div>
  668. <div class="otherBtns">
  669. <span><button class="import">Import</button></span>
  670. <span><button class="export">Export</button></span>
  671. <span class="lock"><button>Lock</button></span>
  672. <span class="reset"><button>Reset</button></span>
  673. </div>
  674. </div>
  675. `;
  676. var id = 0;
  677. var temp = `<div id="styleSetting"> ${allBody} ${footer} </div>`;
  678. document.querySelector("body").insertAdjacentHTML("afterend", temp);
  679. addScript(jsColorPackage);
  680.  
  681. function listenerInit(cmd) {
  682. (function () {
  683. var theName = "grid_base_alpha";
  684. document
  685. .querySelector(`input[name=${theName}]`)
  686. .addEventListener("input", function (e) {
  687. var value = (e.target.value - (e.target.value % 2)) / 100;
  688. document.querySelector(".grid_base_value").innerHTML = value;
  689. diepStyle.command.fn(theName, value);
  690. });
  691. })();
  692. (function () {
  693. var theName = "stroke_soft_color_intensity";
  694. document
  695. .querySelector(`input[name=${theName}]`)
  696. .addEventListener("input", function (e) {
  697. var value = (e.target.value - (e.target.value % 5)) / 100;
  698. document.querySelector(".stroke_intensity_value").innerHTML =
  699. value;
  700. diepStyle.command.fn(theName, value);
  701. });
  702. })();
  703. (function () {
  704. var theName = "stroke_soft_color";
  705. document
  706. .querySelector(`input[name=${theName}]`)
  707. .addEventListener("change", function (e) {
  708. diepStyle.command.fn(theName, e.target.checked);
  709. });
  710. })();
  711. (function () {
  712. var theName = "border_color_alpha";
  713. document
  714. .querySelector(`input[name=${theName}]`)
  715. .addEventListener("input", function (e) {
  716. var value = (e.target.value - (e.target.value % 2)) / 100;
  717. document.querySelector(".border_value").innerHTML = value;
  718. diepStyle.command.fn(theName, value);
  719. });
  720. })();
  721. (function () {
  722. var theName = "ui_scale";
  723. document
  724. .querySelector(`input[name=${theName}]`)
  725. .addEventListener("input", function (e) {
  726. var value = (e.target.value - (e.target.value % 2)) / 100;
  727. document.querySelector(`.${theName}_value`).innerHTML = value;
  728. diepStyle.command.fn(theName, value);
  729. });
  730. })();
  731. (function () {
  732. var theName = "ui";
  733. document
  734. .querySelector(`input[name=${theName}]`)
  735. .addEventListener("change", function (e) {
  736. diepStyle.command.fn(theName, e.target.checked);
  737. });
  738. })();
  739. (function () {
  740. var theName = "fps";
  741. document
  742. .querySelector(`input[name=${theName}]`)
  743. .addEventListener("change", function (e) {
  744. diepStyle.command.fn(theName, e.target.checked);
  745. });
  746. })();
  747. (function () {
  748. var theName = "raw_health_values";
  749. document
  750. .querySelector(`input[name=${theName}]`)
  751. .addEventListener("change", function (e) {
  752. diepStyle.command.fn(theName, e.target.checked);
  753. });
  754. })();
  755. (function () {
  756. var theName = "names";
  757. document
  758. .querySelector(`input[name=${theName}]`)
  759. .addEventListener("change", function (e) {
  760. diepStyle.command.fn(theName, e.target.checked);
  761. });
  762. })();
  763. if (cmd == "reset") return;
  764. (function () {
  765. document
  766. .querySelectorAll(`.theme div[data-theme]`)
  767. .forEach((dom) => {
  768. dom.addEventListener("click", () => {
  769. const name = dom.getAttribute("data-theme");
  770. const themes = diepStyle.themeJson;
  771. diepStyle.importJSON(themes[name]);
  772. });
  773. });
  774. })();
  775. // document.querySelector('button.selectTheme').addEventListener('click', function(e) {
  776. // alert('k');
  777. // });
  778. document
  779. .querySelector("button.import")
  780. .addEventListener("click", () => {
  781. var example =
  782. '[\n{"cmd":"ui_scale","value":"1.5"},' +
  783. '\n{"id":"8","value":"888888"}\n]';
  784. var gotValue = prompt(
  785. "Enter The JSON\nExample:\n" + example,
  786. example.replace(/\s/g, "")
  787. );
  788. diepStyle.importJSON(gotValue);
  789. });
  790. document
  791. .querySelector("button.export")
  792. .addEventListener("click", function (e) {
  793. prompt("Copy the Json", diepStyle.exportJSON("one"));
  794. });
  795. document.querySelectorAll(".saveBtns button").forEach((elem, th) => {
  796. elem.addEventListener("click", function () {
  797. localStorage.pluginSave();
  798. nowSetting = clone(saveList[th]);
  799. nowSetting.saveTH = th;
  800. // diepStyle.storageInit();
  801. // nowSetting.saveTH=th;
  802. diepStyle.resetColor();
  803. diepStyle.resetRender("reset");
  804. updateSaveBtns();
  805. });
  806. });
  807. document
  808. .querySelector(".lock button")
  809. .addEventListener("click", function (e) {
  810. nowSetting.lock = !nowSetting.lock;
  811. updateSaveBtns();
  812. });
  813. document
  814. .querySelector(".reset button")
  815. .addEventListener("click", function (e) {
  816. if (e.target.innerHTML != "Confirm") {
  817. e.target.innerHTML = "Confirm";
  818. } else {
  819. diepStyle.storageInit("reset");
  820. diepStyle.resetColor();
  821. diepStyle.resetRender("reset");
  822. updateSaveBtns();
  823. }
  824. });
  825. document
  826. .querySelector(".reset button")
  827. .addEventListener("mouseleave", function (e) {
  828. e.target.innerHTML = "Reset";
  829. });
  830. updateSaveBtns();
  831.  
  832. function updateSaveBtns() {
  833. var theTH = nowSetting.saveTH;
  834. var status = saveList[theTH];
  835. var lockBtn = document.querySelector(".lock button");
  836. var resetBtn = document.querySelector(".reset button");
  837. if (theTH == 0) {
  838. lockBtn.disabled = true;
  839. resetBtn.disabled = true;
  840. nowSetting.lock = true;
  841. } else {
  842. resetBtn.disabled = nowSetting.lock;
  843. lockBtn.disabled = false;
  844. }
  845. if (resetBtn.disabled) {
  846. document.querySelector(".table").classList.add("noClicks");
  847. document.querySelector(".themeBody").classList.add("noClicks");
  848. document.querySelector("button.import").classList.add("noClicks");
  849. lockBtn.innerHTML = "locked";
  850. } else {
  851. document.querySelector(".table").classList.remove("noClicks");
  852. document.querySelector(".themeBody").classList.remove("noClicks");
  853. document
  854. .querySelector("button.import")
  855. .classList.remove("noClicks");
  856. lockBtn.innerHTML = "no lock";
  857. }
  858. (function () {
  859. document
  860. .querySelectorAll(".saveBtns button")
  861. .forEach(function (elem, th) {
  862. elem.classList.remove("chosenBtn");
  863. if (theTH == th) elem.classList.add("chosenBtn");
  864. });
  865. })();
  866. }
  867. }
  868. }
  869.  
  870. function loadColor() {
  871. if (nowSetting.theme) {
  872. document.querySelector(".themeDesc").classList.remove("hide");
  873. var it = document.querySelector(".themeDesc .name");
  874. it.innerText = nowSetting.theme.name;
  875. it = document.querySelector(".themeDesc .author");
  876. it.innerText = "by\n " + nowSetting.theme.author;
  877. } else {
  878. document.querySelector(".themeDesc").classList.add("hide");
  879. }
  880.  
  881. nowSetting.colors.some(function (elem, th) {
  882. var target = document.querySelector(`.colorBlock${th}`);
  883. if (!target || !target.querySelector(".cell input").jscolor) {
  884. setTimeout(loadColor, 500);
  885. return true;
  886. }
  887. onColor(elem.id, elem.color);
  888. target.querySelector(".cell").innerHTML = elem.name;
  889. target.querySelector(".cell input").jscolor.fromString(elem.color);
  890. });
  891. }
  892.  
  893. function exportJSON(cmd) {
  894. var toExport = [];
  895. if (cmd == "one") toExport = write(nowSetting);
  896. if (cmd == "all")
  897. saveList.forEach((elem) => toExport.push(write(elem)));
  898. return JSON.stringify(toExport);
  899.  
  900. function write(now) {
  901. var array = [];
  902. now.colors.forEach(function (elem) {
  903. if (elem.id && elem.id < 50)
  904. array.push({
  905. id: elem.id,
  906. value: elem.color,
  907. });
  908. if (elem.id && elem.id >= 50 && elem.id < 100)
  909. array.push({
  910. cmd: elem.cmd,
  911. value: elem.color,
  912. });
  913. if (!elem.id && elem.cmd)
  914. array.push({
  915. cmd: elem.cmd,
  916. value: elem.color,
  917. });
  918. });
  919. array.push({
  920. cmd: "ui_replace_colors",
  921. value: diepStyle.uiColorMap("array"),
  922. });
  923. now.renders.forEach(function (elem) {
  924. array.push({
  925. cmd: elem.cmd,
  926. value: elem.value,
  927. });
  928. });
  929. if (now.theme) {
  930. array.unshift({
  931. theme: {
  932. name: now.theme.name || "",
  933. author: now.theme.author || "",
  934. },
  935. });
  936. } else {
  937. array.unshift({
  938. theme: {
  939. name: "",
  940. author: "",
  941. },
  942. });
  943. }
  944. return array;
  945. }
  946. }
  947.  
  948. function importJSON(json) {
  949. if (!isJson(json)) {
  950. alert("Code Incorrect\nPlz git gud and check your JSON");
  951. return;
  952. }
  953. var gotArr = JSON.parse(json);
  954. if (!gotArr) return;
  955. gotArr.forEach(function (elem) {
  956. nowSetting.colors = nowSetting.colors.map(function (now) {
  957. if (elem.id && now.id == elem.id) now.color = elem.value;
  958. if (!elem.id && elem.cmd && now.cmd == elem.cmd)
  959. now.color = elem.value;
  960. return now;
  961. });
  962. nowSetting.renders = nowSetting.renders.map(function (now) {
  963. if (elem.cmd && now.cmd == elem.cmd) now.value = elem.value;
  964. return now;
  965. });
  966. if (elem.cmd == "ui_replace_colors") {
  967. var uiTH = nowSetting.colors.findIndex(
  968. (elem) => elem.name == "UI Color1"
  969. );
  970. for (var i = 0; i < 8; i++) {
  971. nowSetting.colors[uiTH + i].color = elem.value[i];
  972. }
  973. }
  974. if (elem.theme) {
  975. if (elem.theme.name || elem.theme.author)
  976. nowSetting.theme = elem.theme;
  977. } else {
  978. elem.theme = {};
  979. }
  980. });
  981. document
  982. .querySelectorAll(".saveBtns button")
  983. [nowSetting.saveTH].click();
  984.  
  985. function isJson(str) {
  986. try {
  987. JSON.parse(str);
  988. } catch (e) {
  989. return false;
  990. }
  991. if (typeof JSON.parse(str) == "object") return true;
  992. }
  993. }
  994. }
  995.  
  996. function onColor(id, e) {
  997. var target = id;
  998. var color = e.toString();
  999. if (id >= 0 && id < 50) {
  1000. input.execute(`net_replace_color ${target} 0x${color}`);
  1001. } else if (id >= 50 && id < 100) {
  1002. var cmd = diepStyle.colorMap.get(id).cmd;
  1003. input.set_convar(cmd, `0x${color}`);
  1004. } else {
  1005. input.execute("ui_replace_colors" + diepStyle.uiColorMap("0x"));
  1006. }
  1007. nowSetting.colors = nowSetting.colors.map(function (elem) {
  1008. if (elem.id === id) elem.color = color;
  1009. return elem;
  1010. });
  1011. }
  1012.  
  1013. function styleInit() {
  1014. addGlobalStyle(`#styleSetting{padding: 0.2em; margin:0.2em; position: absolute;top: 0;right: 0;width: 35%;
  1015. min-width:20em; background-color: rgba(200,200,200,0.8);display:none;border: 1px solid black;height: 85vh;}`);
  1016. addGlobalStyle(
  1017. ".table{ display: table; text-align: center; width: 99%;}"
  1018. );
  1019. addGlobalStyle(".row{ display: table-row; }");
  1020. addGlobalStyle(`.cell{ display: table-cell;}`);
  1021. addGlobalStyle(
  1022. `.cell:not(.noBoard){ display: table-cell; padding: 0.1em 0.3em;border: 1px solid black;}`
  1023. );
  1024. addGlobalStyle(
  1025. "input[type=checkbox],input[type=range]{transform: scale(1.2); }"
  1026. );
  1027. addGlobalStyle(`.pluginBody{height: 90%; overflow-y: auto;}`);
  1028. addGlobalStyle(
  1029. `.theme .list div{width: 48%; float: left; text-align: center; padding: 1%;}`
  1030. );
  1031. addGlobalStyle(`.theme img {width: 90%;}`);
  1032. addGlobalStyle(
  1033. `.colorBegin, .renderBegin, .importBegin,.themeBegin,.header{font-size:1.1rem; line-height:1.3em;text-align: center;}`
  1034. );
  1035. addGlobalStyle(`.saveBtns button{margin: 0 3%; padding: 0.2em 0.5em;}`);
  1036. addGlobalStyle(
  1037. `@-moz-document url-prefix() {.saveBtns button{margin: 0 1%;padding: 0.1em 0.3em;} } }`
  1038. );
  1039. addGlobalStyle(`.otherBtns button{margin: 0 4%; padding: 0.2em 0.5em;}`);
  1040. addGlobalStyle(
  1041. `.footer{text-align:center;height:10%; border: 1px solid black;}`
  1042. );
  1043. addGlobalStyle(`.footer > *{margin: 0.2vh 0 1.3vh 0;}`);
  1044.  
  1045. addGlobalStyle(`.reset button{box-shadow: 0 0 1em red;}`);
  1046. addGlobalStyle(`.backRed{background-color:#f14e54}`);
  1047. addGlobalStyle(
  1048. `.chosenBtn{-webkit-filter: brightness(0.8);filter:brightness(0.8);}`
  1049. );
  1050. addGlobalStyle(
  1051. `.noClicks{pointer-events:none; -webkit-filter: opacity(50%); filter: opacity(50%);}`
  1052. );
  1053. addGlobalStyle(`.hide{display:none}`);
  1054.  
  1055. function addGlobalStyle(css) {
  1056. var head, style;
  1057. head = document.getElementsByTagName("head")[0];
  1058. if (!head) {
  1059. return;
  1060. }
  1061. style = document.createElement("style");
  1062. style.type = "text/css";
  1063. style.innerHTML = css;
  1064. head.appendChild(style);
  1065. }
  1066. }
  1067. }
  1068.  
  1069. function togglePanel(tf) {
  1070. if (tf) {
  1071. try {
  1072. document.querySelector("#styleSetting").style.display = "block";
  1073. } catch (err) {
  1074. var warn =
  1075. "\n\nYou can DELETE ALL PLUGIN SAVES to fix this" +
  1076. "\nType delete to confirm" +
  1077. "\nor cancel to download all saves";
  1078. var gotValue = prompt("Got an error\n" + err + warn);
  1079. if (gotValue == "delete") {
  1080. localStorage.removeItem("diepStyle");
  1081. alert("Deleted,refresh to take effect");
  1082. return;
  1083. } else {
  1084. download("diep.style saves.txt", diepStyle.exportJSON("all"));
  1085. }
  1086. }
  1087. } else {
  1088. document.querySelector("#styleSetting").style.display = "none";
  1089. }
  1090. function download(filename, text) {
  1091. var element = document.createElement("a");
  1092. element.setAttribute(
  1093. "href",
  1094. "data:text/plain;charset=utf-8," + encodeURIComponent(text)
  1095. );
  1096. element.setAttribute("download", filename);
  1097. element.style.display = "none";
  1098. document.body.appendChild(element);
  1099. element.click();
  1100. document.body.removeChild(element);
  1101. }
  1102. }
  1103.  
  1104. (function loadThemes() {
  1105. diepStyle.themeJson = {
  1106. dark: `[{"theme":{"name":"Dark Mode","author":"/u/162893476"}} ,{"id":2,"value":"001117"},{"id":15,"value":"140000"},{"id":3,"value":"005574"},{"id":4,"value":"540000"},{"id":5,"value":"090413"},{"id":6,"value":"00121a"},{"id":17,"value":"0D0D0D"},{"id":12,"value":"0D0D0D"},{"id":8,"value":"141400"},{"id":7,"value":"0d1500"},{"id":9,"value":"170606"},{"id":10,"value":"0a0016"},{"id":11,"value":"160517"},{"id":14,"value":"141414"},{"id":1,"value":"0f0f0f"},{"cmd":"ren_bar_background_color","value":"000000"},{"cmd":"ren_stroke_solid_color","value":"555555"},{"id":13,"value":"00bd88"},{"cmd":"ren_xp_bar_fill_color","value":"ffde43"},{"cmd":"ren_score_bar_fill_color","value":"43ff91"},{"cmd":"ren_health_fill_color","value":"85e37d"},{"cmd":"ren_health_background_color","value":"555555"},{"cmd":"ren_grid_color","value":"111111"},{"cmd":"ren_minimap_background_color","value":"323232"},{"cmd":"ren_minimap_border_color","value":"986895"},{"cmd":"ren_background_color","value":"000000"},{"cmd":"ren_border_color","value":"0f0f0f"},{"cmd":"ui_replace_colors","value":["ffe280","ff31a0","882dff","2d5aff","ffde26","ff2626","95ff26","17d2ff"]},{"cmd":"grid_base_alpha","value":2},{"cmd":"stroke_soft_color_intensity","value":-10},{"cmd":"stroke_soft_color","value":false},{"cmd":"border_color_alpha","value":0.5},{"cmd":"ui_scale","value":1},{"cmd":"ui","value":false},{"cmd":"fps","value":false},{"cmd":"raw_health_values","value":false},{"cmd":"names","value":false}] `,
  1107. glass: `[{"theme":{"name":"Glass","author":"/u/162893476"}}, {"id":2,"value":"00627D"},{"id":15,"value":"7E0000"},{"id":3,"value":"00627D"},{"id":4,"value":"7E0000"},{"id":5,"value":"3D007E"},{"id":6,"value":"007E00"},{"id":17,"value":"464646"},{"id":12,"value":"7E7E00"},{"id":8,"value":"7E7E00"},{"id":7,"value":"457E00"},{"id":16,"value":"795C00"},{"id":9,"value":"7C0320"},{"id":10,"value":"43397d"},{"id":11,"value":"7E037A"},{"id":14,"value":"252525"},{"id":1,"value":"464646"},{"cmd":"ren_bar_background_color","value":"191919"},{"cmd":"ren_stroke_solid_color","value":"555555"},{"id":13,"value":"008B54"},{"cmd":"ren_xp_bar_fill_color","value":"666600"},{"cmd":"ren_score_bar_fill_color","value":"008B54"},{"cmd":"ren_health_fill_color","value":"85e37d"},{"cmd":"ren_health_background_color","value":"555555"},{"cmd":"ren_grid_color","value":"373737"},{"cmd":"ren_minimap_background_color","value":"464646"},{"cmd":"ren_minimap_border_color","value":"676767"},{"cmd":"ren_background_color","value":"000000"},{"cmd":"ren_border_color","value":"454545"},{"cmd":"ui_replace_colors","value":["e69f6c","ff73ff","c980ff","71b4ff","ffed3f","ff7979","88ff41","41ffff"]},{"cmd":"grid_base_alpha","value":2},{"cmd":"stroke_soft_color_intensity","value":-9},{"cmd":"stroke_soft_color","value":false},{"cmd":"border_color_alpha","value":0.5},{"cmd":"ui_scale","value":1},{"cmd":"ui","value":false},{"cmd":"fps","value":false},{"cmd":"raw_health_values","value":false},{"cmd":"names","value":false}] `,
  1108. moomoo: `[{"theme":{"name":"Moomoo","author":"yst6zJTuKCHQvAXW4IPV"}}, {"id":2,"value":"847377"},{"id":15,"value":"7F4B63"},{"id":3,"value":"475F9E"},{"id":4,"value":"844052"},{"id":5,"value":"A330B1"},{"id":6,"value":"A66E4F"},{"id":17,"value":"6D6B84"},{"id":12,"value":"596B4A"},{"id":8,"value":"5b6b4d"},{"id":7,"value":"928150"},{"id":16,"value":"596B4A"},{"id":9,"value":"8c4256"},{"id":10,"value":"63647e"},{"id":11,"value":"5A5B72"},{"id":14,"value":"837752"},{"id":1,"value":"535377"},{"cmd":"ren_bar_background_color","value":"586B44"},{"cmd":"ren_stroke_solid_color","value":"35354E"},{"id":13,"value":"64ff8c"},{"cmd":"ren_xp_bar_fill_color","value":"FFFFFF"},{"cmd":"ren_score_bar_fill_color","value":"586B44"},{"cmd":"ren_health_fill_color","value":"8ECC51"},{"cmd":"ren_health_background_color","value":"3D3F42"},{"cmd":"ren_grid_color","value":"000000"},{"cmd":"ren_minimap_background_color","value":"586B44"},{"cmd":"ren_minimap_border_color","value":"586B44"},{"cmd":"ren_background_color","value":"768F5B"},{"cmd":"ren_border_color","value":"333333"},{"cmd":"ui_replace_colors","value":["5d4322","825d30","a8783e","bf8f54","c89e6a","d6b68f","e3ceb5","f1e7da"]},{"cmd":"grid_base_alpha","value":0.1},{"cmd":"stroke_soft_color_intensity","value":0.25},{"cmd":"stroke_soft_color","value":false},{"cmd":"border_color_alpha","value":0.1},{"cmd":"ui_scale","value":1},{"cmd":"ui","value":false},{"cmd":"fps","value":false},{"cmd":"raw_health_values","value":false},{"cmd":"names","value":false}]`,
  1109. "80s": `[{"theme":{"name":"80s Light","author":"Road-to-100k"}}, {"id":2,"value":"00efff"},{"id":15,"value":"ff00ff"},{"id":3,"value":"00efff"},{"id":4,"value":"ff00ff"},{"id":5,"value":"ffaa00"},{"id":6,"value":"4FFFB0"},{"id":17,"value":"c6c6c6"},{"id":12,"value":"ffe869"},{"id":8,"value":"FFD800"},{"id":7,"value":"89ff69"},{"id":16,"value":"fcc376"},{"id":9,"value":"FF004F"},{"id":10,"value":"0000CD"},{"id":11,"value":"ffffff"},{"id":14,"value":"43197e"},{"id":1,"value":"999999"},{"cmd":"ren_bar_background_color","value":"1e0b38"},{"cmd":"ren_stroke_solid_color","value":"555555"},{"id":13,"value":"64ff8c"},{"cmd":"ren_xp_bar_fill_color","value":"ffde43"},{"cmd":"ren_score_bar_fill_color","value":"43ff91"},{"cmd":"ren_health_fill_color","value":"85e37d"},{"cmd":"ren_health_background_color","value":"555555"},{"cmd":"ren_grid_color","value":"ff00ff"},{"cmd":"ren_minimap_background_color","value":"CDCDCD"},{"cmd":"ren_minimap_border_color","value":"797979"},{"cmd":"ren_background_color","value":"1e0b38"},{"cmd":"ren_border_color","value":"000000"},{"cmd":"ui_replace_colors","value":["e69f6c","ff73ff","c980ff","71b4ff","ffed3f","ff7979","88ff41","41ffff"]},{"cmd":"grid_base_alpha","value":1.1},{"cmd":"stroke_soft_color_intensity","value":0.3},{"cmd":"stroke_soft_color","value":false},{"cmd":"border_color_alpha","value":0.6},{"cmd":"ui_scale","value":1},{"cmd":"ui","value":false},{"cmd":"fps","value":false},{"cmd":"raw_health_values","value":false},{"cmd":"names","value":false}] `,
  1110. };
  1111. })();
  1112. function addScript(src) {
  1113. var s = document.createElement("script");
  1114. s.setAttribute("src", src);
  1115. document.body.appendChild(s);
  1116. }
  1117. })();