diff --git a/.gitignore b/.gitignore index f459290..171602b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ waspLineReader.zip -extension/contentScript.js -docs/contentScript.js \ No newline at end of file +extension/contentScript.js \ No newline at end of file diff --git a/build.sh b/build.sh index 12f6422..23cd309 100644 --- a/build.sh +++ b/build.sh @@ -1,5 +1,4 @@ cat libs/lineWrapDetector.js main.js > extension/contentScript.js -cp extension/contentScript.js docs/contentScript.js while getopts ":i" opt; do case $opt in diff --git a/docs/contentScript.js b/docs/contentScript.js index 8c7d09e..bcf998f 100644 --- a/docs/contentScript.js +++ b/docs/contentScript.js @@ -10,9 +10,6 @@ }; var wrapWordsInChildElement = function(el) { - if(el.parentElement.className=="js-detect-wrap"){ - return; - } if(el.nodeName == '#text') { var words = el.textContent.split(''); for(var i=0;i parseInt(x, 16) - ); -} - -// Color all lines in the page -function applyGradient(colors, color_text, gradient_size) -{ - const paragraphs = document.getElementsByTagName('p'); - const base_color = hex_to_rgb(color_text); - let coloridx = 0; - let lineno = 0; - - for (let paragraph of paragraphs) { - const lines = lineWrapDetector.getLines(paragraph); - - for (let line of lines) { - // Alternate between left and right for every color - const active_color = hex_to_rgb(colors[coloridx]); - - // Flip array around if on left to color correctly - const is_left = (lineno % 2 === 0); - if(is_left) { - line = Array.from(line).reverse(); +const GRADIENT_LENGTH_PERCENTAGE = 0.5; + +var ps = document.getElementsByTagName('p'); +for(let i=0; i(line.length-1)*GRADIENT_LENGTH_PERCENTAGE ? getGradient(k, line.length) : 0; + break; + case 1: //Blue beginning + blue = k<(line.length-1)*GRADIENT_LENGTH_PERCENTAGE ? getGradient(k, line.length) : 0; + break; + case 2: //Red ending + red = k>(line.length-1)*GRADIENT_LENGTH_PERCENTAGE ? getGradient(k, line.length) : 0; + break; + case 3: //Red beginning + red = k<(line.length-1)*GRADIENT_LENGTH_PERCENTAGE ? getGradient(k, line.length) : 0; + break; } - - // Color lines using lerp of RGB values - for (let loc in line) { - const t = 1 - (loc / (line.length * gradient_size / 50)); - const red = lerp(base_color[0], active_color[0], t); - const green = lerp(base_color[1], active_color[1], t); - const blue = lerp(base_color[2], active_color[2], t); - - line[loc].style.color = "rgb(" + (red|0) + "," + (green|0) + "," + (blue|0) + ")"; - } - - // Increment color index after every left/right pair, and lineno - // after every line - if (!is_left) { - coloridx = (coloridx + 1) % colors.length; - } - lineno += 1; + line[k].style.color="rgb("+red+","+green+","+blue+")"; } } } -// Listen for messages in background script -chrome.runtime.onMessage.addListener((message) => { - if (message.command === "apply_gradient") { - applyGradient( - message.colors, message.color_text, message.gradient_size - ); - } else if (message.command === "reset") { - // TODO: Make function to remove line detection spans - applyGradient( - [message.color_text], message.color_text, 0 - ); - } -}); - - -})(); \ No newline at end of file +function getGradient(k, len){ + return Math.round(Math.abs(255*(((k/(len-1))-GRADIENT_LENGTH_PERCENTAGE)/GRADIENT_LENGTH_PERCENTAGE))); +}