Diep.Style Ver 0.08
Press Esc twice to toggle this
`;
var colorPlane = function(id) {
return `{position:'left',width:300, height:200,onFineChange:'diepStyle.onColor(${id},this)'}`
}
colorObj.setClass = function() {
return `colorBlock colorBlock${this.th++}`
}
setObj.setClass = function() {
return `setting setting${this.th++}`
}
function resetRender(cmd) {
document.querySelectorAll('#styleSetting .render').forEach(function(elem) {
elem.outerHTML = ``
})
var it = document.querySelector('.renderBegin')
it.insertAdjacentHTML('afterend', getRenderBody());
it.remove();
nowSetting.renders.forEach(function(elem) {
diepStyle.command.fn(elem.cmd, elem.value);
});
listenerInit(cmd);
}
var bodyRender = getRenderBody();
var bodyColor = getColorBody();
var bodyImport = getImportBody();
function getRenderBody() {
var renders = nowSetting.renders;
var th = -1;
var html = `
Render Setting
${renders[++th].name} ${renders[th].value}
${renders[++th].name} ${renders[th].value}
${renders[++th].name}
${renders[++th].name} ${renders[th].value}
${renders[++th].name} ${renders[th].value}
${renders[++th].name}
${renders[++th].name}
${renders[++th].name}
${renders[++th].name}
`
return html;
}
function getColorBody() {
var it = '
Color Setting
\n' +
`
`
nowSetting.colors.forEach(function(elem, th) {
var id = elem.id;
it += `
`;
});
return it
}
function getImportBody() {
var html=
`
Import / Export Save
`
return html
}
var allBody =
`
${title}
${bodyRender} ${bodyColor} ${bodyImport}
`;
var getSaveBtns=function() {
var btn='';
for (var i = 0; i < 6; i++) {
if(i==0) {btn+=``;continue;}
btn+=``;
}
return btn;
}
var footer=
`
`
var id = 0;
var temp = `
${allBody} ${footer}
`;
document.querySelector('body').insertAdjacentHTML('afterend', temp);
addScript('https://greasyfork.org/scripts/27023-jscolor/code/JSColor.js?version=173802');
function addScript(src) {
var s = document.createElement('script');
s.setAttribute('src', src);
document.body.appendChild(s);
}
function listenerInit(cmd) {
;(function (){
var theName="grid_base_alpha";
document.querySelector(`input[name=${theName}]`).addEventListener('input',
function(e) {
var value = (e.target.value - e.target.value % 2) / 100
document.querySelector('.grid_base_value').innerHTML = value;
diepStyle.command.fn(theName, value);
});
})();
;(function (){
var theName="stroke_soft_color_intensity";
document.querySelector(`input[name=${theName}]`).addEventListener('input',
function(e) {
var value = (e.target.value - e.target.value % 5)/100
document.querySelector('.stroke_intensity_value').innerHTML = value;
diepStyle.command.fn(theName, value);
});
})();
;(function (){
var theName="stroke_soft_color";
document.querySelector(`input[name=${theName}]`).addEventListener('change',
function(e) {diepStyle.command.fn(theName, e.target.checked); });
})();
;(function (){
var theName="border_color_alpha";
document.querySelector(`input[name=${theName}]`).addEventListener('input',
function(e) {
var value = (e.target.value - e.target.value % 2) / 100
document.querySelector('.border_value').innerHTML = value;
diepStyle.command.fn(theName, value);
});
})();
;(function (){
var theName="ui_scale";
document.querySelector(`input[name=${theName}]`).addEventListener('input',
function(e) {
var value = (e.target.value - e.target.value % 2) / 100
document.querySelector(`.${theName}_value`).innerHTML = value;
diepStyle.command.fn(theName, value);
});
})();
;(function (){
var theName="ui";
document.querySelector(`input[name=${theName}]`).addEventListener('change',
function(e) {diepStyle.command.fn(theName, e.target.checked); });
})();
;(function (){
var theName="fps";
document.querySelector(`input[name=${theName}]`).addEventListener('change',
function(e) {diepStyle.command.fn(theName, e.target.checked); });
})();
;(function (){
var theName="raw_health_values";
document.querySelector(`input[name=${theName}]`).addEventListener('change',
function(e) {diepStyle.command.fn(theName, e.target.checked); });
})();
;(function (){
var theName="names";
document.querySelector(`input[name=${theName}]`).addEventListener('change',
function(e) {diepStyle.command.fn(theName, e.target.checked); });
})();
if(cmd=='reset') return;
document.querySelector('button.import').addEventListener('click',function(e) {
var example='[\n{"cmd":"ui_scale","value":"1.5"},'+
'\n{"id":"8","value":"888888"}\n]';
var gotValue=prompt('Enter The JSON\nExample:\n'+example,example.replace(/\s/g, ''));
if(!isJson(gotValue)){
alert('Code Incorrect\nPlz git gud and check your JSON');
return
};
var gotArr=JSON.parse(gotValue);
if(!gotArr) return;
gotArr.forEach(function(elem) {
nowSetting.colors=nowSetting.colors.map(function(now) {
if(elem.id && now.id==elem.id) now.color=elem.value;
if(!elem.id&&elem.cmd && now.cmd==elem.cmd) now.color=elem.value;
return now
});
nowSetting.renders=nowSetting.renders.map(function(now) {
if(elem.cmd && now.cmd==elem.cmd) now.value=elem.value;
return now
});
if(elem.cmd=='ui_replace_colors') {
var uiTH = nowSetting.colors.findIndex(elem => elem.name == 'UI Color1');
for (var i = 0; i < 8; i++) {
nowSetting.colors[uiTH + i].color=elem.value[i];
}
};
if(elem.theme){
if(elem.theme.name||elem.theme.author) nowSetting.theme=elem.theme;
}else{
elem.theme={};
};
});
document.querySelectorAll('.saveBtns button')[nowSetting.saveTH].click();
function isJson(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
if(typeof JSON.parse(str)=='object') return true;
}
});
document.querySelector('button.export').addEventListener('click',function(e) {
prompt('Copy the Json',diepStyle.export('one'));
});
document.querySelectorAll('.saveBtns button').forEach((elem, th) => {
elem.addEventListener('click', function() {
localStorage.pluginSave();
nowSetting=clone(saveList[th]);
nowSetting.saveTH=th;
diepStyle.resetColor();
diepStyle.resetRender('reset');
updateSaveBtns();
})
})
document.querySelector('.lock button').addEventListener('click',
function(e) {
nowSetting.lock=!nowSetting.lock;
updateSaveBtns();
});
document.querySelector('.reset button').addEventListener('click',
function(e) {
diepStyle.storageInit('reset');
diepStyle.resetColor();
diepStyle.resetRender('reset');
updateSaveBtns();
});
updateSaveBtns();
function updateSaveBtns() {
var theTH=nowSetting.saveTH;
var status=saveList[theTH];
var lockBtn=document.querySelector('.lock button');
var resetBtn=document.querySelector('.reset button');
if(theTH==0){
lockBtn.disabled = true;
resetBtn.disabled = true;
nowSetting.lock=true;
}else{
resetBtn.disabled = nowSetting.lock;
lockBtn.disabled = false;
}
if(resetBtn.disabled) {
document.querySelector('.table').classList.add('noClicks');
lockBtn.innerHTML='locked';
}else{
document.querySelector('.table').classList.remove('noClicks');
lockBtn.innerHTML='no lock';
}
;(function (){
document.querySelectorAll('.saveBtns button').forEach(function(elem, th) {
elem.classList.remove('chosenBtn');
if(theTH==th) elem.classList.add('chosenBtn');
})
})();
}
}
}
function loadColor() {
if(nowSetting.theme){
document.querySelector('.theme').classList.remove('hide');
var it=document.querySelector('.theme .name');
it.innerText='Theme '+nowSetting.theme.name;
it=document.querySelector('.theme .author');
it.innerText='by '+nowSetting.theme.author;
}else{
document.querySelector('.theme').classList.add('hide');
}
nowSetting.colors.some(function(elem, th) {
var target = document.querySelector(`.colorBlock${th}`);
if (!target || !target.querySelector('.cell input').jscolor) {
setTimeout(loadColor, 500);
return true
}
onColor(elem.id, elem.color);
target.querySelector('.cell').innerHTML = elem.name;
target.querySelector('.cell input').jscolor.fromString(elem.color);
})
}
function exportJSON(cmd) {
var toExport=[];
if(cmd=='one') toExport=write(nowSetting);
if(cmd=='all') saveList.forEach(elem=>toExport.push(write(elem)));
return JSON.stringify(toExport);
function write(now) {
var array=[];
now.colors.forEach(function(elem){
if(elem.id&&elem.id<50) array.push({id:elem.id,value:elem.color});
if(elem.id&&elem.id>=50&&elem.id<100) array.push({cmd:elem.cmd,value:elem.color});
if(!elem.id&&elem.cmd) array.push({cmd:elem.cmd,value:elem.color});
});
array.push({cmd:'ui_replace_colors',value:diepStyle.uiColorMap('array')});
now.renders.forEach(function(elem){
array.push({cmd:elem.cmd,value:elem.value});
});
if(now.theme){
array.unshift({theme:{
name:now.theme.name||'',
author:now.theme.author||''}});
}else{
array.unshift({theme:{name:'',author:''}});
}
return array
}
}
}
function onColor(id, e) {
var target = id;
var color=e.toString();
if (id >= 0 && id < 50) {
input.execute(`net_replace_color ${target} 0x${color}`)
} else if(id >= 50 && id < 100){
var cmd=diepStyle.colorMap.get(id).cmd
input.set_convar(cmd, `0x${color}`);
} else{
input.execute('ui_replace_colors'+diepStyle.uiColorMap('0x'));
}
nowSetting.colors = nowSetting.colors.map(function(elem) {
if (elem.id === id) elem.color = color;
return elem
})
}
function styleInit() {
addGlobalStyle(`#styleSetting{padding: 0.2em; margin:0.2em; position: absolute;top: 0;right: 0;width: 30%;
min-width:20em; background-color: rgba(200,200,200,0.8);display:none;border: 1px solid black;height: 92vh;}`);
addGlobalStyle(".table{ display: table; text-align: center; width: 99%;}");
addGlobalStyle(".row{ display: table-row; }");
addGlobalStyle(`.cell{ display: table-cell;}`);
addGlobalStyle(`.cell:not(.noBoard){ display: table-cell; padding: 0.1em 0.3em;border: 1px solid black;}`);
addGlobalStyle("input[type=checkbox],input[type=range]{transform: scale(1.2); }");
addGlobalStyle(`.pluginBody{height: 90%; overflow-y: auto;}`);
addGlobalStyle(`.colorBegin, .renderBegin, .importBegin,.header{font-size:1.2em; line-height:1.5em;}`);
addGlobalStyle(`.saveBtns button{margin: 0 1.5%; padding: 0.2em 0.5em;}`);
addGlobalStyle(`@-moz-document url-prefix() {.saveBtns button{margin: 0 1%;padding: 0.1em 0.3em;} } }`);
addGlobalStyle(`.otherBtns button{margin: 0 1.5%; padding: 0.2em 0.5em;}`);
addGlobalStyle(`.footer{text-align:center;height:10%; border: 1px solid black;}`);
addGlobalStyle(`.footer > *{margin:0.7vh 0;}`);
addGlobalStyle(`.backRed{background-color:#f14e54}`);
addGlobalStyle(`.chosenBtn{-webkit-filter: brightness(0.8);filter:brightness(0.8);}`)
addGlobalStyle(`.noClicks{pointer-events:none; -webkit-filter: opacity(50%); filter: opacity(50%);}`)
addGlobalStyle(`.hide{display:none}`)
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) {return;}
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}
}
}
function togglePanel(tf) {
if(tf){
try{
document.querySelector('#styleSetting').style.display = "block";
}catch(err){
var warn='\n\nYou can DELETE ALL PLUGIN SAVES to fix this'+
'\nType delete to confirm'+
'\nor cancel to download all saves';
var gotValue=prompt('Got an error\n'+err+warn);
if(gotValue=='delete'){
localStorage.removeItem('diepStyle');
alert('Deleted,refresh to take effect');
return
}else{
download('diep.style saves.txt',diepStyle.export('all'))
};
}
}else{
document.querySelector('#styleSetting').style.display = "none";
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
}
})();