Skip to content

Commit

Permalink
Fix bug in the landing page caused by gh-pages not loading files in t…
Browse files Browse the repository at this point in the history
…he repo
  • Loading branch information
corollari committed Jun 7, 2018
1 parent b05cae8 commit 063dd0a
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 1 deletion.
122 changes: 122 additions & 0 deletions docs/contentScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
(function() {

var wrapWords = function(text, before, after, join) {
var join = join || '';
var words = text.split('');
for(var i=0;i<words.length;i++) {
words[i] = before + words[i] + after;
}
return words.join(join);
};

var wrapWordsInChildElement = function(el) {
if(el.nodeName == '#text') {
var words = el.textContent.split('');
for(var i=0;i<words.length;i++) {
if(words[i].length > 0) {
var span = document.createElement('span');
span.className = "js-detect-wrap";
span.innerText = words[i];
el.parentNode.insertBefore(span, el);
}
};
el.parentNode.removeChild(el);
}
else {
if(el.innerText){
el.innerHTML = wrapWords(el.innerText,'<span class="js-detect-wrap">','</span>');
}
}
};

var wrapWordsInElement = function(el) {
if(!el.firstChild) {
wrapWordsInChildElement(el);
}
else {
var siblings = [];
var s = el.firstChild;
do {
siblings.push(s);
}
while(s = s.nextSibling);

for(var i=0;i<siblings.length;i++) {
wrapWordsInElement(siblings[i]);
}
};
}

var getLines = function(el) {

wrapWordsInElement(el);

var spans = el.getElementsByClassName('js-detect-wrap');

var lastOffset = 0, line=[], lines = [], l=0;
for(var i=0;i<spans.length;i++) {
var offset = spans[i].offsetTop+spans[i].getBoundingClientRect().height;
if(offset == lastOffset) {
line.push(spans[i]);
}
else {
if(line.length > 0) lines[l++] = line;

line = [spans[i]];
}
lastOffset = offset;
}
lines.push(line);
return lines;
}

var detector = {
wrapWords: wrapWords
, wrapWordsInElement: wrapWordsInElement
, wrapWordsInChildElement: wrapWordsInChildElement
, getLines: getLines
};

if(typeof define == 'function') {
define(function() {
return detector;
});
}
else {
window.lineWrapDetector = detector;
}

})();

const GRADIENT_LENGTH_PERCENTAGE = 0.5;

var ps = document.getElementsByTagName('p');
for(let i=0; i<ps.length; i++){
var p = ps[i];
var lines = lineWrapDetector.getLines(p);
for(let j=0; j<lines.length; j++){
let line = lines[j];
let red = 0, blue = 0, green = 0;
for(let k=0; k<line.length; k++){
switch(j%4){
case 0: //Blue ending
blue = k>(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;
}
line[k].style.color="rgb("+red+","+green+","+blue+")";
}
}
}

function getGradient(k, len){
return Math.round(Math.abs(255*(((k/(len-1))-GRADIENT_LENGTH_PERCENTAGE)/GRADIENT_LENGTH_PERCENTAGE)));
}
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h1 class="animate-intro">
<script src="js/jquery-2.1.3.min.js"></script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
<script src="../extension/contentScript.js"></script>
<script src="contentScript.js"></script>

</body>

Expand Down

0 comments on commit 063dd0a

Please sign in to comment.