Greasy Fork is available in English.

Configuration Dialog

A enhanced configuration dialog for Userscripts.

Verze ze dne 08. 02. 2019. Zobrazit nejnovější verzi.

Tento skript by neměl být instalován přímo. Jedná se o knihovnu, kterou by měly jiné skripty využívat pomocí meta příkazu // @require https://update.greatest.deepsurf.us/scripts/45343/668865/Configuration%20Dialog.js

  1. /*
  2. /////////////////////////////////////////////////////
  3. # #
  4. # Script made by Marius Adam #
  5. # ©DevForce 2019 #
  6. # Code Version 0.3 #
  7. # #
  8. /////////////////////////////////////////////////////
  9. */
  10.  
  11. var configurationWindow = {
  12. maximized: false,
  13. minimized: false,
  14.  
  15. changed: false,
  16.  
  17. data: undefined,
  18. window_id: "window",
  19.  
  20. values: {},
  21. get : function(id){
  22. return this.values[id];
  23. },
  24. getElseSet : function(id, def, ifNone){
  25. var val = this.get(id);
  26. if(val == undefined){
  27. if(def == undefined){
  28. val = ifNone;
  29. this.set(id, ifNone);
  30. }else{
  31. val = def;
  32. this.set(id, def);
  33. }
  34. }
  35. return val;
  36. },
  37. set : function(id, value){
  38. this.values[id] = value;
  39. },
  40. save : function(){
  41. GM_setValue(this.window_id, JSON.stringify(this.values));
  42. console.debug("Saved to #" + this.window_id, this.values);
  43. },
  44. load : function(){
  45. var loaded = GM_getValue(this.window_id);
  46. if(loaded == undefined || loaded.length < 2) loaded = "{}";
  47. this.values = JSON.parse(loaded);
  48. console.debug("Loaded Values: ", this.values);
  49. },
  50. updateChanged : function() {
  51. this.changed = ($('[style="border: 2px solid rgb(255, 244, 0);"]').length + $('[style="outline: rgb(255, 244, 0) solid 3px;"]').length + $('[style="outline: 3px solid rgb(255, 244, 0);"]').length) > 0;
  52. $('#' + this.window_id).find('#saveButton').prop("disabled", ! this.changed);
  53. $('#' + this.window_id).find('#revertButton').prop("disabled", ! this.changed);
  54. },
  55. maximize : function() {
  56. $('#' + this.window_id).find('#content').show();
  57. $('#' + this.window_id).find('#footer').show();
  58. $('#' + this.window_id).find('#theme_dropdown').show();
  59. $("#window_minimize").show();
  60. $('#' + this.window_id).width("calc(100% - 20px)");
  61. $('#' + this.window_id).height("calc(100% - 20px)");
  62. $('#' + this.window_id).css("top", "7px");
  63. $('#' + this.window_id).css("left", "7px");
  64. $('#' + this.window_id).css("min-height", "");
  65.  
  66. this.maximized = true;
  67. this.minimized = false;
  68. },
  69.  
  70. minimize : function(){
  71. $('#' + this.window_id).find('#content').hide();
  72. $('#' + this.window_id).find('#footer').hide();
  73. $('#' + this.window_id).find('#theme_dropdown').hide();
  74. $("#window_minimize").hide();
  75. $('#' + this.window_id).width("50%");
  76. $('#' + this.window_id).height("25px");
  77. $('#' + this.window_id).css("top", "calc(100% - 30px)");
  78. $('#' + this.window_id).css("left", "25%");
  79. $('#' + this.window_id).css("min-height", "30px");
  80.  
  81. this.minimized = true;
  82. },
  83.  
  84. normalize : function(){
  85. $('#' + this.window_id).find('#content').show();
  86. $('#' + this.window_id).find('#footer').show();
  87. $('#' + this.window_id).find('#theme_dropdown').show();
  88. $("#window_minimize").show();
  89. $('#' + this.window_id).width("");
  90. $('#' + this.window_id).height("");
  91. $('#' + this.window_id).css("top", "");
  92. $('#' + this.window_id).css("left", "");
  93. $('#' + this.window_id).css("min-height", "");
  94.  
  95. this.maximized = false;
  96. this.minimized = false;
  97. },
  98.  
  99. clearSelection : function(){
  100. if (window.getSelection) {
  101. if (window.getSelection().empty) { // Chrome
  102. window.getSelection().empty();
  103. } else if (window.getSelection().removeAllRanges) { // Firefox
  104. window.getSelection().removeAllRanges();
  105. }
  106. } else if (document.selection) { // IE
  107. document.selection.empty();
  108. }
  109. },
  110.  
  111. makeDragable : function(move, dragbox, useBorder) {
  112. if(dragbox == undefined) dragbox = move;
  113. if(useBorder == undefined) useBorder = true;
  114.  
  115. var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0, dragged = false;
  116.  
  117. dragbox.onmousedown = dragMouseDown;
  118.  
  119. function dragMouseDown(e) {
  120. e = e || window.event;
  121. if(configurationWindow.minimized){
  122. document.onmouseup = null;
  123. document.onmousemove = null;
  124. return;
  125. }
  126. // get the mouse cursor position at startup:
  127. pos3 = e.clientX;
  128. pos4 = e.clientY;
  129. document.onmouseup = closeDragElement;
  130. // call a function whenever the cursor moves:
  131. document.onmousemove = elementDrag;
  132. }
  133.  
  134. function elementDrag(e) {
  135. e = e || window.event;
  136. // calculate the new cursor position:
  137. pos1 = pos3 - e.clientX;
  138. pos2 = pos4 - e.clientY;
  139. pos3 = e.clientX;
  140. pos4 = e.clientY;
  141. // set the element's new position:
  142. var new_top = move.offsetTop - pos2;
  143. var new_left = move.offsetLeft - pos1;
  144. if(configurationWindow.maximized){
  145. configurationWindow.normalize();
  146. new_top = e.clientY;
  147. new_left = e.clientX;
  148. }
  149. if(useBorder){
  150. var max_width = $(window).width() - $(move).width();
  151. var max_height = $(window).height() - $(move).height();
  152. if(new_top < 0) new_top = 0;
  153. else if(new_top > max_height) new_top = max_height;
  154. if(new_left < 0) new_left = 0;
  155. else if(new_left > max_width) new_left = max_width;
  156. }
  157. move.style.left = new_left + "px";
  158. move.style.top = new_top + "px";
  159. dragged = true;
  160. configurationWindow.clearSelection();
  161. }
  162.  
  163. function closeDragElement() {
  164. /* stop moving when mouse button is released:*/
  165. if(useBorder && dragged){
  166. if(move.style.top.indexOf("%") == -1 && move.style.top.replace("px", "") < 2)
  167. configurationWindow.maximize();
  168. }
  169. document.onmouseup = null;
  170. document.onmousemove = null;
  171. }
  172. },
  173.  
  174. isArray : function(what) {
  175. return Object.prototype.toString.call(what) === '[object Array]';
  176. },
  177.  
  178. isObject : function(what) {
  179. return Object.prototype.toString.call(what) === '[object Object]';
  180. },
  181.  
  182. join : function(labelFirst, label, element){
  183. return (labelFirst ? label + " " + element : element + " " + label);
  184. },
  185.  
  186. replaceAll : function(target, search, replacement) {
  187. return target.replace(new RegExp(search, 'g'), replacement);
  188. },
  189.  
  190. revertChanges : function(){
  191. $('#' + this.window_id).find("#content").find("input[type=text], input[type=password], input[type=number], input[type=color]").each(function(){
  192. $(this).val($(this).attr("value"));
  193. $(this).css("border", "");
  194. });
  195.  
  196. $('#' + this.window_id).find("#content").find("select").each(function(){
  197. this.value = $(this).find("option[selected]").val();
  198. $(this).css("border", "");
  199. });
  200.  
  201. $('#' + this.window_id).find("#content").find('input[type=checkbox]:not(.toggle)').each(function() {
  202. this.checked = $(this).attr("default") == "true";
  203. $(this).css("outline", "");
  204. });
  205.  
  206. $($(this)).change();
  207. this.updateChanged();
  208. },
  209.  
  210. saveChanges : function(){
  211. $('#' + this.window_id).find("#content").find("input[type=text], input[type=password], input[type=number], input[type=color]").each(function(){
  212. configurationWindow.set(this.id, this.value);
  213. $(this).attr("value", this.value);
  214. $(this).css("border", "");
  215. });
  216.  
  217. $('#' + this.window_id).find("#content").find("select").each(function(){
  218. configurationWindow.set(this.id, this.value);
  219.  
  220. var main_val = this.value;
  221.  
  222. $(this).find("option[selected]").removeAttr("selected");
  223. $(this).find("option").filter(function() {
  224. return this.innerHTML == main_val;
  225. }).attr("selected", "selected");
  226.  
  227. this.value = main_val;
  228.  
  229. $(this).css("border", "");
  230. });
  231.  
  232. $('#' + this.window_id).find("#content").find('input[type=checkbox]:not(.toggle)').each(function() {
  233. configurationWindow.set(this.id, this.checked);
  234. $(this).attr("default", this.checked);
  235. $(this).css("outline", "");
  236. });
  237.  
  238. this.updateChanged();
  239. this.save();
  240. },
  241.  
  242. ResetSettings : function(){
  243. if(this.isArray(this.data.content)){
  244. for(i = 0; i < this.data.content.length; i++){
  245. if(this.isObject(this.data.content[i])){
  246. var object = this.data.content[i];
  247. object.default = (object.default == undefined ? "" : object.default);
  248. var elem = $('#' + this.window_id).find("#content").find("#" + object.id);
  249. var type = elem.attr("type");
  250. if(type == undefined && elem.is("select")) type = "select";
  251. switch(type){
  252. case "text":
  253. case "number":
  254. case "password":
  255. case "select":
  256. $(elem).val(object.default);
  257. break;
  258. case "checkbox":
  259. $(elem).prop("checked", object.default);
  260. break;
  261. default: break;
  262. }
  263. $(elem).change();
  264. }
  265. }
  266. }
  267. this.updateChanged();
  268. },
  269.  
  270. close : function(){
  271. if(this.changed){
  272. if(!confirm(this.data.confirm_close)){
  273. return false;
  274. }
  275. }
  276. $('#' + this.window_id).attr("style", "display: none;");
  277. return true;
  278. },
  279. open : function(data){
  280. $('#' + this.window_id).attr("style", "");
  281. },
  282.  
  283. create : function(data){
  284. //var data = JSON.parse(content);
  285.  
  286. this.data = data;
  287. if(this.window_id != undefined)
  288. $('#' + this.window_id).remove();
  289.  
  290. $('#window_style').remove();
  291. $('#font-awesome').remove();
  292.  
  293. if(data.id == undefined) data.id = "window";
  294. this.window_id = data.id;
  295.  
  296. this.load();
  297. $('head').append('<link id="font-awesome" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">');
  298.  
  299. if (data.theme == undefined) data.theme = "mac";
  300. if (!(data.theme == "mac" || data.theme == "win10" || data.theme == "winXP")) data.theme = "mac";
  301. var saved_theme = GM_getValue("config_theme");
  302. if(data.theme_selector == undefined || data.theme_selector == true || data.theme_selector == "true"){
  303. data.theme_selector = true;
  304. if(saved_theme != undefined) data.theme = saved_theme;
  305. }else{
  306. data.theme_selector = false;
  307. }
  308. if(data.width == undefined) data.width = 50;
  309. if(data.height == undefined) data.height = 50;
  310. var section_color = "#c9c9c9";
  311. var subsection_color = "#f1f1f1";
  312. var style = "<style id='window_style'>";
  313. if(data.theme == "mac"){
  314. style += `
  315. #` + this.window_id + ` > #top > .btn {
  316. height: 16px;
  317. width: 16px;
  318. background-color: #bbb;
  319. border-radius: 50%;
  320. float: right;
  321. margin-right: 10px;
  322. display: inline-block;
  323. font-size: 10px;
  324. text-align: center;
  325. color: white;
  326. cursor: pointer;
  327. //font-weight: bold;
  328. }
  329.  
  330. #` + this.window_id + ` > #top > .title {
  331. margin: auto;
  332. font-size: 16px;
  333. font-weight: bold;
  334. cursor: move;
  335. }
  336.  
  337. #` + this.window_id + ` {
  338. border: 3px solid #f1f1f1;
  339. border-top-left-radius: 3px;
  340. border-top-right-radius: 3px;
  341. height: ` + data.height + `%;
  342. width: ` + data.width + `%;
  343. top: ` + ((100 - data.height) / 2) + `%;
  344. left: ` + ((100 - data.width) / 2) + `%;
  345. position: fixed;
  346. z-index: 11000;
  347. background: white;
  348. min-width: 250px;
  349. min-height: 250px;
  350. resize: both;
  351. overflow: auto;
  352. line-height: unset;
  353. overflow-y: hidden;`
  354. + (data.font != undefined ?
  355. (data.font.size != undefined ? "font-size: " + data.font.size + ";" : "") +
  356. (data.font.family != undefined ? "font-family: " + data.font.family + ";" : "")
  357. : "") +
  358. `}
  359.  
  360. #` + this.window_id + ` > #top {
  361. padding: 10px;
  362. //height: 20px;
  363. background: #f1f1f1;
  364. border-top-left-radius: 4px;
  365. border-top-right-radius: 4px;
  366. position: absolute;
  367. width: calc(100% - 20px);
  368. }
  369. `;
  370. }else if(data.theme == "win10"){
  371. section_color = "#1f9cff";
  372. subsection_color = "#9dd4ff";
  373. style += `
  374. #` + this.window_id + ` > #top > .btn {
  375. height: 22px;
  376. width: 30px;
  377. float: right;
  378. margin-right: 5px;
  379. display: inline-block;
  380. font-size: 16px;
  381. text-align: center;
  382. color: white;
  383. cursor: pointer;
  384. color: black;
  385. padding: 2px;
  386. }
  387. #` + this.window_id + ` > #top > #window_minimize:hover, #` + this.window_id + ` > #top > #window_maximize:hover {
  388. background-color: #ddd;
  389. }
  390. #` + this.window_id + ` > #top > #window_close:hover {
  391. background-color: red;
  392. }
  393.  
  394. #` + this.window_id + ` > #top > .title {
  395. margin: auto;
  396. font-size: 16px;
  397. font-weight: bold;
  398. cursor: move;
  399. padding: 10px;
  400. }
  401.  
  402. #` + this.window_id + ` {
  403. border: 3px solid #1f9cff;
  404. height: ` + data.height + `%;
  405. width: ` + data.width + `%;
  406. top: ` + ((100 - data.height) / 2) + `%;
  407. left: ` + ((100 - data.width) / 2) + `%;
  408. position: fixed;
  409. z-index: 11000;
  410. background: white;
  411. min-width: 250px;
  412. min-height: 250px;
  413. resize: both;
  414. overflow: auto;
  415. line-height: unset;
  416. overflow-y: hidden;`
  417. + (data.font != undefined ?
  418. (data.font.size != undefined ? "font-size: " + data.font.size + ";" : "") +
  419. (data.font.family != undefined ? "font-family: " + data.font.family + ";" : "")
  420. : "") +
  421. `}
  422.  
  423. #` + this.window_id + ` > #top {
  424. //padding: 10px;
  425. //height: 20px;
  426. background: #1f9cff;
  427. position: absolute;
  428. width: 100%;
  429. }
  430. `;
  431. }else if(data.theme == "winXP"){
  432. section_color = "#226ce7";
  433. subsection_color = "#4094ff";
  434. style += `
  435. #` + this.window_id + ` > #top > .btn {
  436. height: 20px;
  437. width: 20px;
  438. float: right;
  439. margin-right: 5px;
  440. margin-top: 5px;
  441. display: inline-block;
  442. font-size: 16px;
  443. text-align: center;
  444. color: white;
  445. cursor: pointer;
  446. color: white;
  447. border-radius: 2px;
  448. padding: 2px;
  449. border: 1px solid white;
  450. background: linear-gradient(135deg, #7EAED6 0%, #1B72FF 50%, #1655BE 100%);
  451. }
  452. #` + this.window_id + ` > #top > #window_minimize:hover, #` + this.window_id + ` > #top > #window_maximize:hover {
  453. background: linear-gradient(135deg, #6a93b5 0%, #1862da 50%, #124499 100%);
  454. }
  455. #` + this.window_id + ` > #top > #window_close {
  456. background: linear-gradient(135deg, #F1A689 0%, #C0442A 50%, #C2311E 100%);
  457. }
  458. #` + this.window_id + ` > #top > #window_close:hover {
  459. background: linear-gradient(135deg, #c3846c 0%, #a43923 50%, #982415 100%);
  460. }
  461.  
  462. #` + this.window_id + ` > #top > .title {
  463. margin: auto;
  464. font-size: 16px;
  465. font-weight: bold;
  466. cursor: move;
  467. padding: 10px;
  468. color: white;
  469. }
  470.  
  471. #` + this.window_id + ` {
  472. border-left: 3px solid #0056e4;
  473. border-right: 3px solid #0056e4;
  474. border-bottom: 3px solid #0056e4;
  475. height: ` + data.height + `%;
  476. width: ` + data.width + `%;
  477. top: ` + ((100 - data.height) / 2) + `%;
  478. left: ` + ((100 - data.width) / 2) + `%;
  479. position: fixed;
  480. z-index: 11000;
  481. background: white;
  482. min-width: 250px;
  483. min-height: 250px;
  484. border-radius: 8px;
  485. resize: both;
  486. overflow: auto;
  487. line-height: unset;
  488. overflow-y: hidden;`
  489. + (data.font != undefined ?
  490. (data.font.size != undefined ? "font-size: " + data.font.size + ";" : "") +
  491. (data.font.family != undefined ? "font-family: " + data.font.family + ";" : "")
  492. : "") +
  493. `}
  494.  
  495. #` + this.window_id + ` > #top {
  496. //padding: 10px;
  497. //height: 20px;
  498. border-radius: 5px 5px 0px 0px;
  499. background: linear-gradient(to bottom, #4094ff 0%, #0056e4 13%, #0056e4 71%, #16428b 100%);
  500. position: absolute;
  501. width: 100%;
  502. }
  503. `;
  504. }
  505. style += `
  506. #` + this.window_id + ` > #footer {
  507. text-align: right;
  508. margin: 0px 0px 4px -20px;
  509. height: 40px;
  510. border-top-left-radius: 4px;
  511. border-top-right-radius: 4px;
  512. position: absolute;
  513. width: 100%;
  514. bottom: 0;
  515. pointer-events: none;
  516. }
  517.  
  518. #` + this.window_id + ` > #footer > button {
  519. background-color: #f1f1f1;
  520. border: none;
  521. color: black;
  522. padding: 12px 40px;
  523. font-size: 14px;
  524. cursor: pointer;
  525. margin-left: 5px;
  526. pointer-events: all;
  527. }
  528.  
  529. #` + this.window_id + ` > #footer > button:hover {
  530. background-color: RoyalBlue;
  531. color: white;
  532. }
  533. #` + this.window_id + ` > #footer > button:disabled {
  534. background-color: darkgrey;
  535. color: white;
  536. }
  537. #` + this.window_id + ` > #content {
  538. padding: 10px;
  539. margin-top: 40px;
  540. overflow-y: scroll;
  541. height: calc(100% - 75px);
  542. overflow-wrap: break-word;
  543. }
  544.  
  545. #` + this.window_id + ` > #content > input,#` + this.window_id + ` > #content > select {`
  546. + (data.font != undefined ?
  547. (data.font.size != undefined ? "font-size: " + data.font.size + ";" : "") +
  548. (data.font.family != undefined ? "font-family: " + data.font.family + ";" : "")
  549. : "") +
  550. `}
  551.  
  552. #` + this.window_id + ` > #content > br {
  553. display: block;
  554. margin-top: 4px;
  555. content: " ";
  556. }
  557.  
  558. #` + this.window_id + ` > #theme_dropdown {
  559. float: left;
  560. bottom: 5px;
  561. position: absolute;
  562. left: 5px;
  563. border: none;
  564. -webkit-appearance: none;
  565. -moz-appearance: none;
  566. appearance: none;
  567. color: gray;
  568. background-color: transparent;
  569. }
  570. #` + this.window_id + ` > #theme_dropdown > option {
  571. color: black;
  572. }
  573. .no-margin {
  574. margin: 0px;
  575. }
  576. .wrap-collapsible {
  577. margin-bottom: 1.2rem 0;
  578. }
  579.  
  580. .toggle {
  581. display: none;
  582. }
  583.  
  584. .lbl-toggle {
  585. display: block;
  586. cursor: pointer;
  587. transition: all 0.25s ease-out;
  588. }
  589. .lbl-toggle h2, .lbl-toggle h4 {
  590. display: inline;
  591. }
  592.  
  593. .lbl-toggle:hover {
  594. color: white;
  595. }
  596.  
  597. .lbl-toggle::before {
  598. content: ' ';
  599. display: inline-block;
  600.  
  601. border-top: 5px solid transparent;
  602. border-bottom: 5px solid transparent;
  603. border-left: 5px solid currentColor;
  604. vertical-align: middle;
  605. margin-right: .7rem;
  606. transform: translateY(-2px);
  607.  
  608. transition: transform .2s ease-out;
  609. }
  610.  
  611. .toggle:checked + .lbl-toggle::before {
  612. transform: rotate(90deg) translateX(-3px);
  613. }
  614.  
  615. .collapsible-content {
  616. max-height: 0px;
  617. overflow: hidden;
  618. transition: max-height .25s ease-in-out;
  619. }
  620.  
  621. .toggle:checked + .lbl-toggle + .collapsible-content {
  622. max-height: unset;
  623. }
  624.  
  625. .collapsible-content .content-inner {
  626. //background: rgba(161, 161, 161, 0.2);
  627. //border: 1px solid black;
  628. }
  629. `;
  630. style += "<style>";
  631. $('head').append(style);
  632. if(data.theme_section_color == undefined || data.theme_section_color == false){
  633. section_color = "#c9c9c9";
  634. subsection_color = "#f1f1f1";
  635. }
  636. var content = "";
  637.  
  638. if(this.isArray(data.content)){
  639. var section_collapsible = false;
  640. var subsection_collapsible = false;
  641. var collapsible_id = 1;
  642. for(i = 0; i < data.content.length; i++){
  643. if(this.isObject(data.content[i])){
  644. var label_first = undefined;
  645. Object.keys(data.content[i]).forEach(function(key){
  646. if(label_first != undefined) return;
  647.  
  648. if(key == "label") label_first = true;
  649. else if(key == "type") label_first = false;
  650. });
  651.  
  652. var label = this.replaceAll(data.content[i].label, " ", "&nbsp;&nbsp;");
  653.  
  654. var object = data.content[i];
  655.  
  656. if(object.style != undefined) object.style = " style='" + object.style + "'";
  657. else object.style = "";
  658.  
  659. if(object.require != undefined) object.style += " require='" + object.require + "'";
  660. switch(object.type){
  661. case "p":
  662. content += "<p class='no-margin'" + object.style + ">" + label + "</p>";
  663. break;
  664. case "h1":
  665. content += "<h1 class='no-margin'" + object.style + ">" + label + "</h1>";
  666. break;
  667. case "h2":
  668. content += "<h2 class='no-margin'" + object.style + ">" + label + "</h2>";
  669. break;
  670. case "h3":
  671. content += "<h3 class='no-margin'" + object.style + ">" + label + "</h3>";
  672. break;
  673. case "h4":
  674. content += "<h4 class='no-margin'" + object.style + ">" + label + "</h4>";
  675. break;
  676. case "section":
  677. if(object.align == undefined) object.align = "center";
  678. if(object.background == undefined) object.background = section_color;
  679. if(subsection_collapsible){
  680. content += "</div></div></div>";
  681. subsection_collapsible = false;
  682. }
  683. if(section_collapsible){
  684. content += "</div></div></div>";
  685. section_collapsible = false;
  686. }
  687. if(object.collapsible != undefined && object.collapsible){
  688. content += "<div class='wrap-collapsible'><input id='collapsible" + collapsible_id + "' class='toggle' type='checkbox' " + (object.collapsed != undefined && object.collapsed == false ? "checked" : "") + "><label style='margin: 5px 0px 0px 0px; background: " + object.background + "; text-align: " + object.align + ";' for='collapsible" + collapsible_id + "' class='lbl-toggle'><h2>" + label + "</h2></label><div class='collapsible-content'><div class='content-inner'>";
  689. section_collapsible = true;
  690. collapsible_id++;
  691. }else{
  692. content += "<div width='100%' style='margin: 5px 0px; background: " + object.background + "; text-align: " + object.align + ";'><h2 class='no-margin'>" + label + "</h2></div>";
  693. }
  694. break;
  695. case "subsection":
  696. if(object.align == undefined) object.align = "center";
  697. if(object.background == undefined) object.background = subsection_color;
  698. if(subsection_collapsible){
  699. content += "</div></div></div>";
  700. subsection_collapsible = false;
  701. }
  702. if(object.collapsible != undefined && object.collapsible){
  703. content += "<div class='wrap-collapsible'><input id='collapsible" + collapsible_id + "' class='toggle' type='checkbox' " + (object.collapsed != undefined && object.collapsed == false ? "checked" : "") + "><label style='margin: 5px 0px 0px 0px; background: " + object.background + "; text-align: " + object.align + ";' for='collapsible" + collapsible_id + "' class='lbl-toggle'><h4>" + label + "</h4></label><div class='collapsible-content'><div class='content-inner'>";
  704. subsection_collapsible = true;
  705. collapsible_id++;
  706. }else{
  707. content += "<div width='100%' style='margin: 5px 0px; background: " + object.background + "; text-align: " + object.align + ";'><h4 class='no-margin'>" + label + "</h4></div>";
  708. }
  709. break;
  710. case "text":
  711. var value = this.getElseSet(object.id, object.default, "");
  712. content += this.join(label_first, label, "<input id='" + object.id + "'" + object.style + " type='text' value='" + value + "' />");
  713.  
  714. content += "<br>";
  715. break;
  716. case "password":
  717. var value = this.getElseSet(object.id, object.default, "");
  718. content += this.join(label_first, label, "<input id='" + object.id + "'" + object.style + " type='password' value='" + value + "' />");
  719.  
  720. content += "<br>";
  721. break;
  722. case "checkbox":
  723. var value = this.getElseSet(object.id, object.default, false);
  724. if(value == "true" || value == true) value = true;
  725. else value = false;
  726.  
  727. label = "<label for='" + object.id + "'>" + label + "</label>";
  728. content += this.join(label_first, label, "<input id='" + object.id + "'" + object.style + " default='" + value + "' type='checkbox' " + (value ? "checked" : "") + "/>");
  729.  
  730. content += "<br>";
  731. break;
  732. case "select":
  733. var value = this.getElseSet(object.id, object.default, "");
  734.  
  735. var select = " <select" + object.style + " id='" + object.id + "'>";
  736. object.options.forEach(function(opt){
  737. if(opt == value){
  738. select += "<option selected>" + opt + "</option>";
  739. }else{
  740. select += "<option>" + opt + "</option>";
  741. }
  742. });
  743. select += "</select> ";
  744.  
  745. content += this.join(label_first, label, select);
  746.  
  747. content += "<br>";
  748. break;
  749. case "numeric":
  750. var value = this.getElseSet(object.id, object.default, 0);
  751. var element = "<input id='" + object.id + "'" + object.style + " type='number' value='" + value + "'";
  752. if(object.min != undefined) element += " min='" + object.min + "'";
  753. if(object.max != undefined) element += " max='" + object.max + "'";
  754. element += " />";
  755. content += this.join(label_first, label, element);
  756.  
  757. content += "<br>";
  758. break;
  759. case "color":
  760. var value = this.getElseSet(object.id, object.default, "#FFFFFF");
  761.  
  762. content += this.join(label_first, label, "<input id='" + object.id + "'" + object.style + " type='color' value='" + value + "' />");
  763.  
  764. content += "<br>";
  765. break;
  766. default: break;
  767. }
  768. }else{
  769. content += "<p>" + data.content[i] + "</p>";
  770. }
  771. }
  772. if(subsection_collapsible){
  773. content += "</div></div></div>";
  774. section_collapsible = false;
  775. }
  776. if(section_collapsible){
  777. content += "</div></div></div>";
  778. section_collapsible = false;
  779. }
  780. }else{
  781. content = data.content;
  782. }
  783. //content += "<br style='height: 25px;' />";
  784. content += "<br><br><br>";
  785. var buttons = "";
  786.  
  787. if(data.completeresetbutton == undefined || data.completeresetbutton == true || data.completeresetbutton == "true"){
  788. buttons += "<button id='completeResetButton'><i class='fa fa-trash'></i></button>";
  789. }
  790.  
  791. if(data.revertbutton == undefined || data.revertbutton == true || data.revertbutton == "true"){
  792. buttons += "<button id='revertButton'><i class='fa fa-undo'></i></button>";
  793. }
  794.  
  795. if(data.savebutton == undefined || data.savebutton == true || data.savebutton == "true"){
  796. buttons += "<button id='saveButton'><i class='fa fa-save'></i></button>";
  797. }
  798.  
  799. var topbuttons = "";
  800. if(data.top == undefined || data.top.close == undefined || data.top.close == "true"){
  801. if(data.theme == "mac") topbuttons += '<span id="window_close" class="btn" style="background:#ED594A; margin-right: 20px;"><i class="fa fa-times" style="vertical-align: sub;"></i></span>';
  802. else if(data.theme == "win10") topbuttons += '<span id="window_close" class="btn" style="margin-right: 0px;"><i class="fa fa-times"></i></span>';
  803. else if(data.theme == "winXP") topbuttons += '<span id="window_close" class="btn"><i class="fa fa-times"></i></span>';
  804. }
  805. if(data.top == undefined || data.top.maximize == undefined || data.top.maximize == "true"){
  806. if(data.theme == "mac") topbuttons += '<span id="window_maximize" class="btn" style="background:#FDD800;"><i class="fa fa-window-maximize" style="vertical-align: sub;"></i></span>';
  807. else if(data.theme == "win10" || data.theme == "winXP") topbuttons += '<span id="window_maximize" class="btn"><i class="fa fa-window-maximize"></i></span>';
  808. }
  809. if(data.top == undefined || data.top.minimize == undefined || data.top.minimize == "true"){
  810. if(data.theme == "mac") topbuttons += '<span id="window_minimize" class="btn" style="background:#5AC05A;"><i class="fa fa-window-minimize" style="vertical-align: sub;"></i></span>';
  811. else if(data.theme == "win10" || data.theme == "winXP") topbuttons += '<span id="window_minimize" class="btn"><i class="fa fa-window-minimize"></i></span>';
  812. }
  813.  
  814. $('body').append(`
  815. <div id="` + this.window_id + `" style='display: none;' class="window">
  816. <div id="top">
  817. ` + topbuttons +
  818. `<p class="title">` + data.title + `</p>
  819. </div>
  820.  
  821. <div id="content">
  822. ` + content + `
  823. </div>
  824.  
  825. <div id="footer">
  826. ` + buttons + `
  827. </div>
  828. ` +
  829. (data.theme_selector ? `<select id="theme_dropdown" value="Theme">
  830. <option value="std" style="display: none;">Theme</option>
  831. <option value="mac">Mac</option>
  832. <option value="win10">Windows 10</option>
  833. <option value="winXP">Windows XP</option>
  834. </select>` : "") + `
  835. </div>
  836. `);
  837.  
  838. this.makeDragable($('#' + this.window_id)[0], $('#' + this.window_id).find("#top")[0], true);
  839.  
  840. var confirm_close = "Unsaved changes. Discard changes?";
  841. var confirm_revert = "Reset all changes?";
  842. var confirm_reset = "Bring settings back to factory settings?";
  843. if(data.confirm_close != undefined) confirm_close = data.confirm_close;
  844. if(data.confirm_revert != undefined) confirm_revert = data.confirm_revert;
  845. if(data.confirm_reset != undefined) confirm_reset = data.confirm_reset;
  846.  
  847. $('#' + this.window_id).find('#revertButton').click(function(){
  848. if(confirm(confirm_revert)) configurationWindow.revertChanges();
  849. });
  850. $('#' + this.window_id).find('#saveButton').click(function(){
  851. configurationWindow.saveChanges();
  852. $('#' + configurationWindow.window_id).find('#saveButton').css("background", "lime");
  853. setTimeout(function(){
  854. $('#' + configurationWindow.window_id).find('#saveButton').css("background", "");
  855. }, 1000);
  856. });
  857.  
  858. $('#' + this.window_id).find('#completeResetButton').click(function(){
  859. if(confirm(confirm_reset)) configurationWindow.ResetSettings();
  860. });
  861.  
  862. $('#' + this.window_id).find('#window_close').click(function(){
  863. configurationWindow.close();
  864. });
  865.  
  866. //================ WINDOW RESIZE BUTTONS ===================//
  867. $('#' + this.window_id).find('#window_maximize').click(function(){
  868. if(configurationWindow.maximized && !configurationWindow.minimized)
  869. configurationWindow.normalize();
  870. else
  871. configurationWindow.maximize();
  872. });
  873.  
  874. $('#' + this.window_id).find('#window_minimize').click(function(){
  875. configurationWindow.minimize();
  876. });
  877.  
  878. $('#' + this.window_id).find("#top").dblclick(function(){
  879. if(configurationWindow.minimized){
  880. if(configurationWindow.maximized)
  881. configurationWindow.maximize();
  882. else
  883. configurationWindow.normalize();
  884. }else{
  885. if(configurationWindow.maximized)
  886. configurationWindow.normalize();
  887. else
  888. configurationWindow.maximize();
  889. }
  890. configurationWindow.clearSelection();
  891. });
  892.  
  893. //==================== THEME SELECTOR =======================//
  894. $('#' + this.window_id).find("#theme_dropdown").change(function(){
  895. if(! configurationWindow.close()) return;
  896. GM_setValue("config_theme", this.value);
  897. configurationWindow.create(configurationWindow.data);
  898. configurationWindow.open();
  899. });
  900.  
  901. //==================== FIELD CHANGE LISTENER =====================//
  902. $('#' + this.window_id).find("#content").find("input[type=text], input[type=number], input[type=password], input[type=color]").change(function(){
  903. if($(this).attr("value") != $(this).val())
  904. $(this).css("border", "#fff400 solid 2px");
  905. else
  906. $(this).css("border", "");
  907.  
  908. configurationWindow.updateChanged();
  909. });
  910. $('#' + this.window_id).find("#content").find("input[type=number]").change(function(){
  911. if($(this).attr("min") != undefined && $(this).val() < parseFloat($(this).attr("min")))
  912. $(this).val($(this).attr("min"));
  913. else if($(this).attr("max") != undefined && $(this).val() > parseFloat($(this).attr("max"))){
  914. $(this).val($(this).attr("max"));
  915. }
  916. configurationWindow.updateChanged();
  917. });
  918.  
  919.  
  920. $('#' + this.window_id).find("#content").find("select").change(function(){
  921. if(this.value != $(this).find("option[selected]").val())
  922. $(this).css("border", "#fff400 solid 2px");
  923. else
  924. $(this).css("border", "");
  925.  
  926. configurationWindow.updateChanged();
  927. });
  928.  
  929. $('#' + this.window_id).find("#content").find('input[type=checkbox]:not(.toggle)').change(function() {
  930. if(this.checked != ($(this).attr("default") == "true")){
  931. $(this).css("outline", "#fff400 solid 3px");
  932. }else{
  933. $(this).css("outline", "");
  934. }
  935. $('[require="' + this.id + '"]').prop("disabled", !this.checked);
  936. configurationWindow.updateChanged();
  937. });
  938. $('#' + this.window_id).find("#content").find('input[type=checkbox]:not(.toggle)').trigger("change");
  939. $(document).keyup(function(e) {
  940. if (e.keyCode == 27) {
  941. configurationWindow.close();
  942. }
  943. });
  944. this.updateChanged();
  945. }
  946. };