Skip to content

Commit 10ce9d9

Browse files
authoredAug 1, 2020
Cleaner picker, alpha in the picker
1 parent 8311cc6 commit 10ce9d9

File tree

1 file changed

+12
-33
lines changed

1 file changed

+12
-33
lines changed
 

‎Userscripts/Desmos/ColourPicker.js

+12-33
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ How to use:
1717
- Click the box at the top to open the picker
1818
- Move around and click to select colours
1919
- Type/backspace and enter to change the colour directly
20-
- Move the slider on the right of the save button to change the transparency.
21-
- Click the save button to the right of the box to save the colour
20+
- Click the button to the right of the box to save the colour
2221
- Saved colours appear when you press the cog icon at the top of expressions list and click the coloured circle for a given expression
2322
2423
When you save a desmos graph using custom colours the colours on the expressions will save!
@@ -40,13 +39,6 @@ setTimeout(function() {
4039
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
4140
}
4241

43-
function rgbaify(rgb,a) {
44-
if (/^#[0-9A-F]{6}$/i.test(rgb)) return rgb;
45-
46-
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
47-
return "rgba("+rgb[1]+','+rgb[2]+','+rgb[3]+','+Number(a)/100+')';
48-
}
49-
5042
var target = document.getElementsByClassName("dcg-header-desktop")[0];
5143
var hold = document.createElement ('span');
5244
target.insertBefore(hold, target.childNodes[2])
@@ -55,48 +47,35 @@ setTimeout(function() {
5547
zNode.setAttribute ('id', 'picker');
5648
zNode.setAttribute('value',"ffffff");
5749
zNode.jscolor = new jscolor(zNode);
58-
console.log(zNode.jscolor);
59-
zNode.style.width = '25%';
50+
zNode.jscolor.alpha = 1;
51+
zNode.jscolor.option('hash',false);
52+
zNode.style.width = '40%';
6053
zNode.style.height = '45%';
6154
hold.appendChild(zNode);
6255

6356
var gp = document.getElementById('picker')
64-
var tr = "100";
6557

6658
zNode = document.createElement ('span');
6759
zNode.setAttribute ('id', 'cstore');
6860
zNode.setAttribute ('role', 'button');
6961
zNode.setAttribute ('class', "dcg-btn-green");
70-
zNode.innerHTML = "<div style = \"font-size: 85%; position: relative; left:-180%; top:-20%\">Save</div>";
71-
zNode.setAttribute ('style',"position: relative; width:11.25%; left:2.5%; top:10%; height:50%");
72-
hold.appendChild(zNode);
73-
74-
zNode = document.createElement('input');
75-
zNode.setAttribute ('id', 'ctrans');
76-
zNode.type = 'range';
77-
zNode.min = 0;
78-
zNode.max = 100;
79-
zNode.value = 100;
80-
zNode.step = 1;
81-
zNode.setAttribute ('style',"position: relative; width:15%; left:5%; top:5%; height:22.5%");
82-
zNode.oninput = function () {
83-
tr = this.value;
84-
}
62+
zNode.setAttribute ('text', "Save");
63+
zNode.setAttribute ('style',"position: relative; width:11.25%; left:2.5%; top:15%; height:45%");
8564
hold.appendChild(zNode);
8665

8766
document.getElementById('cstore').addEventListener("click", makeColour, false);
8867
function makeColour(zEvent){
89-
var gcol = gp.jscolor.toRGBString();
90-
if (gcol) {
91-
var col = tr+rgb2hex(gcol);
92-
var acol = rgbaify(gcol,tr);
68+
var col = gp.jscolor.toHEXString()+'|'+gp.jscolor.channel('A');
69+
var acol = gp.jscolor.toRGBAString()
70+
if (gp.jscolor.channel('A')=='1'){
71+
var gcol = gp.jscolor.toHEXString()
9372
for (var c in unsafeWindow.Calc.colors) {
94-
if (unsafeWindow.Calc.colors[c] == acol) {
73+
if (unsafeWindow.Calc.colors[c] == gcol) {
9574
return;
9675
}
9776
}
98-
unsafeWindow.Calc.colors[col] = acol;
9977
}
78+
unsafeWindow.Calc.colors[col] = acol;
10079
}
10180

10281
}, 0);

0 commit comments

Comments
 (0)
Please sign in to comment.