Fix an issue with new color code causing incorrect behavior with

converting colors to hex codes
This commit is contained in:
Zixaphir 2014-01-04 14:27:05 -07:00
parent dbf89dcaef
commit 3d97b39f1b
4 changed files with 25 additions and 17 deletions

View File

@ -1,5 +1,5 @@
/*
* appchan x - Version 2.7.4 - 2014-01-02
* appchan x - Version 2.7.4 - 2014-01-04
*
* Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE

View File

@ -22,7 +22,7 @@
// ==/UserScript==
/*
* appchan x - Version 2.7.4 - 2014-01-02
* appchan x - Version 2.7.4 - 2014-01-04
*
* Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
@ -13642,7 +13642,7 @@
};
colorToHex = function(color) {
var digits, hex;
var digits, hex, len;
if (color.substr(0, 1) === '#') {
if (color.length !== 4) {
return color.slice(1);
@ -13650,11 +13650,14 @@
return shortToLong(color.substr(1, 3));
}
}
if (/[0-9a-f]{3}/i.test(color)) {
if (color.length === 6) {
return color;
} else {
return shortToLong(color);
len = color.length;
if (len === 3 || len === 6) {
if (/[0-9a-f]{3}/i.test(color)) {
if (color.length === 6) {
return color;
} else {
return shortToLong(color);
}
}
}
if (digits = color.match(/(.*?)rgba?\((\d+), ?(\d+), ?(\d+)(.*?)\)/)) {

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript
/*
* appchan x - Version 2.7.4 - 2014-01-02
* appchan x - Version 2.7.4 - 2014-01-04
*
* Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
@ -13653,7 +13653,7 @@
};
colorToHex = function(color) {
var digits, hex;
var digits, hex, len;
if (color.substr(0, 1) === '#') {
if (color.length !== 4) {
return color.slice(1);
@ -13661,11 +13661,14 @@
return shortToLong(color.substr(1, 3));
}
}
if (/[0-9a-f]{3}/i.test(color)) {
if (color.length === 6) {
return color;
} else {
return shortToLong(color);
len = color.length;
if (len === 3 || len === 6) {
if (/[0-9a-f]{3}/i.test(color)) {
if (color.length === 6) {
return color;
} else {
return shortToLong(color);
}
}
}
if (digits = color.match(/(.*?)rgba?\((\d+), ?(\d+), ?(\d+)(.*?)\)/)) {

View File

@ -16,8 +16,10 @@ class Color
else
return shortToLong color.substr(1, 3)
if /[0-9a-f]{3}/i.test color
return if color.length is 6 then color else shortToLong color
len = color.length
if len in [3, 6]
if /[0-9a-f]{3}/i.test color
return if color.length is 6 then color else shortToLong color
if digits = color.match /(.*?)rgba?\((\d+), ?(\d+), ?(\d+)(.*?)\)/
# [R, G, B] to 0xRRGGBB