-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
several bug correction, refractoring
- Loading branch information
Showing
7 changed files
with
209 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function pickerRatio(worker, stringResult, lastContrastState, ratio) | ||
{ | ||
var tabResult = stringResult.split(";"); | ||
tabResult[5] = "PICKER"; | ||
var isValidRatio = ratio.isValidRatio(tabResult[0], tabResult[1], tabResult[3]); | ||
if (isValidRatio) | ||
tabResult[2] = "valid-ratio"; | ||
else | ||
tabResult[2] = "invalid-ratio"; | ||
if (tabResult[4] === "CLICK") | ||
worker.port.emit("click-components", tabResult); | ||
else if ((lastContrastState == null || lastContrastState !== tabResult[2]) | ||
&& tabResult[4] === "LIVE") | ||
worker.port.emit("live-components", tabResult); | ||
return tabResult[2]; | ||
} | ||
|
||
function destroyWorker(isDestroy, isDestroyfgPicker, isDestroybgPicker, | ||
tabWorker, tabfgPickerWorker, tabbgPickerWorker) { | ||
workerToDestroy(isDestroy, tabWorker, "selector-unchecked"); | ||
workerToDestroy(isDestroyfgPicker, tabfgPickerWorker, "unchecked-picker"); | ||
workerToDestroy(isDestroybgPicker, tabbgPickerWorker, "unchecked-picker"); | ||
} | ||
|
||
function workerToDestroy(workerState, tabWorker, emitString) { | ||
if (workerState == false) { | ||
if (tabWorker !== null) { | ||
tabWorker.port.emit(emitString); | ||
tabWorker.destroy(); | ||
workerState = true; | ||
} | ||
} | ||
} | ||
|
||
|
||
exports.pickerRatio = pickerRatio; | ||
exports.destroyWorker = destroyWorker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function stateButton(worker, | ||
selectionInProgressTabs, | ||
fgPickerInProgressTabs, | ||
bgPickerInProgressTabs, tabs) { | ||
var isCurrentTabHasSelectionInProgress = getStateProgressTab(selectionInProgressTabs, tabs); | ||
var isCurrentTabHasfgPickerInProgress = getStateProgressTab(fgPickerInProgressTabs, tabs); | ||
var isCurrentTabHasbgPickerInProgress = getStateProgressTab(bgPickerInProgressTabs, tabs); | ||
emitButtonState(worker, | ||
isCurrentTabHasSelectionInProgress, | ||
"start-selector-button", | ||
"stop-selector"); | ||
emitButtonState(worker, | ||
isCurrentTabHasfgPickerInProgress, | ||
"start-fgPicker-button", | ||
"stop-fgPicker"); | ||
emitButtonState(worker, | ||
isCurrentTabHasbgPickerInProgress, | ||
"start-bgPicker-button", | ||
"stop-bgPicker"); | ||
} | ||
|
||
function emitButtonState(worker, isTabInProgress, emitStringStart, emitStringStop) { | ||
if (isTabInProgress) | ||
worker.port.emit(emitStringStart); | ||
else | ||
worker.port.emit(emitStringStop) | ||
} | ||
|
||
function getStateProgressTab(progressTab, tabs) { | ||
for (var i=0;i<progressTab.length;i++){ | ||
if (progressTab[i].tabId === tabs.activeTab.id) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
function emitStopMessages(worker) { | ||
worker.port.emit("stop-selector"); | ||
worker.port.emit("stop-fgPicker"); | ||
worker.port.emit("stop-bgPicker"); | ||
} | ||
|
||
exports.stateButton = stateButton; | ||
exports.emitStopMessages = emitStopMessages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function componentToHex(c) { | ||
var hex = c.toString(16); | ||
return hex.length == 1 ? "0" + hex : hex; | ||
} | ||
|
||
function rgbToHex(r, g, b) { | ||
return componentToHex(r) + componentToHex(g) + componentToHex(b); | ||
} | ||
|
||
/* I can't call the chrome window from the content script. So, I call this from the | ||
// main script. | ||
//http://stackoverflow.com/questions/23888525/ | ||
//firefox-drawwindow-canvas-function-using-the-add-on-sdk/23893077 | ||
*/ | ||
function getCanvasColor(positionTab, chromewin) { | ||
var canvas = chromewin.document.createElementNS('http://www.w3.org/1999/xhtml', | ||
'canvas'); | ||
canvas.width = 1; | ||
canvas.height = 1; | ||
var context = canvas.getContext("2d"); | ||
context.drawWindow(chromewin, positionTab[0], positionTab[1], 1, 1, "white"); | ||
return context.getImageData(0, 0, 1, 1).data; | ||
} | ||
|
||
exports.rgbToHex = rgbToHex; | ||
exports.getCanvasColor = getCanvasColor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
function isValidRatio(fgColor, bgColor, minRatio) { | ||
return minRatio < getContrastRatio(fgColor, bgColor); | ||
} | ||
|
||
function getContrastRatio(fgColor, bgColor) { | ||
var fgLuminosity = getLuminosity(fgColor); | ||
var bgLuminosity = getLuminosity(bgColor); | ||
if (fgLuminosity > bgLuminosity) { | ||
return computeContrast(fgLuminosity, bgLuminosity); | ||
} else { | ||
return computeContrast(bgLuminosity, fgLuminosity); | ||
} | ||
}; | ||
|
||
function hexToRgb(hex) { | ||
var bigint = parseInt(hex, 16); | ||
var r = (bigint >> 16) & 255; | ||
var g = (bigint >> 8) & 255; | ||
var b = bigint & 255; | ||
|
||
return "rgb(" + r + ", " + g + ", " + b + ")"; | ||
} | ||
|
||
function getLuminosity(color) { | ||
var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(hexToRgb(color)); | ||
var red = parseInt(digits[2]); | ||
var green = parseInt(digits[3]); | ||
var blue = parseInt(digits[4]); | ||
var luminosity = | ||
getComposantValue(red) * 0.2126 | ||
+ getComposantValue(green) * 0.7152 | ||
+ getComposantValue(blue) * 0.0722; | ||
return luminosity; | ||
} | ||
|
||
function getComposantValue(composant) { | ||
var rsgb = composant / 255; | ||
if (rsgb <= 0.03928) { | ||
return rsgb / 12.92; | ||
} else { | ||
return Math.pow(((rsgb + 0.055) / 1.055), 2.4); | ||
} | ||
} | ||
|
||
function computeContrast(lighter, darker) { | ||
return ((lighter + 0.05) / (darker + 0.05)); | ||
} | ||
|
||
exports.getContrastRatio = getContrastRatio; | ||
exports.isValidRatio = isValidRatio; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters