User:Canadabonk/sandbox.js: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 2:
if ($('#cosmostweaks-coloreditor').length) {
mw.util.addCSS(`
#cosmostweaks-coloreditor {
background-color: #eee;
color: black;
padding:10px1em;
color-scheme:light;
border:1px solid blacklightgrey;
}
}
#cosmostweaks-coloreditor td, #cosmostweaks-coloreditor th {
#cosmostweaks-coloreditor th {
border:1px solid black;
background-color:lightgrey;
}
}
#cosmostweaks-coloreditor th {
#cosmostweaks-coloreditor td, #cosmostweaks-coloreditor thdiv {
background-color:lightgrey;
display:flex;
}
justify-content:center;
`);
}
#cosmostweaks-coloreditor input[type='color'] {
padding:0;
border:0;
cursor:pointer;
}
#cosmostweaks-coloreditor input[type='color']:hover {
opacity:0.6;
}
#cosmostweaks-coloreditor pre {
margin:0;
background-color:white;
}
 
 
`);
const CSSvarsList = [
Line 46 ⟶ 62:
}
const lightCSS = mw.loader.addStyleTag(':root{}');
function createinput(color) {
const darkCSS = mw.loader.addStyleTag('.cosmostweaks-darkmode{}');
return `<input type="color" value="${color}"><input type="text" value="${color}">`;
}
function createinput(color, name) {
return `<input type="color" name="${name}-color" value="${color}"><input type="text" name="${name}-text" value="${color}">`;
}
Line 53 ⟶ 72:
text = "";
for (const x of CSSvarsList) {
text += `<tr data-row="${x}"><th>${x}</th><td class="lightcol"><div>${createinput(lightmodevars[x], 'light' + x)}</div></td><td class="darkcol"><div>${createinput(darkmodevars[x], 'dark' + x)}</div></td></tr>\n`;
}
return text;
}
function printcolors(list, name) {
colorlist = "";
for (const x in list) {
colorlist += x + ": " + list[x] + ';\n';
}
$(listclassname).text(colorlist);
switch(name) {
case ".lightmodevars":
lightCSS.innerHTML = `:root {\n${colorlist} }`;
break;
case ".darkmodevars":
darkCSS.innerHTML = `.cosmostweaks-darkmode {\n${colorlist} }`;
}
listclass = "." + list.constructor.name;
$(listclass).text(colorlist);
}
Line 72 ⟶ 97:
Paste the resulting code into your "Mediawiki:Gadget-cosmostweaks.css" to apply it.<br>
This tool can only work with hexcodes (like "#000000"). Swap them out for RGBA values with opacity in the CSS page, if desired.</p>
<table style="widthmargin:100%;border-collapse:collapseauto">
<tr><td style="width:30%"></td><th>Light mode</th><th>Dark mode</th></tr>
${CSSvarsRows()}
</table>
}<br>
<p>Light mode colors:</p>
<table style="width:100%;">
<ptr><th>Light mode colors:</pth><th>Dark mode colors:</th><tr>
<tr><td style="width:50%;">
<pre class="lightmodevars">
</pre></td>
<td>
<p>Dark mode colors:</p>
<pre class="darkmodevars">
</pre></td></tr></table>
`);
Line 87 ⟶ 115:
const
color = e.target.value,
variable = $(thise.target).closest('tr').attr('data-row');
console$(e.target).logattr('value', color);
$(e.target).siblings('input').attr('value', color);
switch($(thise.target).parentclosest('td').attr('class')) {
case 'lightcol':
lightmodevars[variable] = color;
printcolors(lightmodevars, ".lightmodevars");
break;
case 'darkcol':
darkmodevars[variable] = color;
printcolors(darkmodevars, ".darkmodevars");
}
});
printcolors(lightmodevars, ".lightmodevars");
printcolors(darkmodevars, ".darkmodevars");
}
});
250

edits