Skip to content

Commit

Permalink
Existing extension
Browse files Browse the repository at this point in the history
Upload progress so far
  • Loading branch information
gsavvas committed Apr 12, 2014
1 parent 468e743 commit 3a8da20
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 0 deletions.
Binary file added 128-t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 16-t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 48-t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
if (!localStorage['saved']){
localStorage['letA'] = '#800000'; //maroon
localStorage['letE'] = '#008000'; //green
localStorage['letI'] = '#0000ff'; //blue
localStorage['letO'] = '#008080'; //teal
localStorage['letU'] = '#800080'; //purple

localStorage['saved'] = 'Y';

}


// Converts an integer (unicode value) to a char
function itoa(i)
{
return String.fromCharCode(i);
}

// Converts a char into to an integer (unicode value)
function atoi(a)
{
return a.charCodeAt();
}


chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.method == "getColors"){
var colorList = new Array();
for( x=0; x<26; x++){
colorList[x] = localStorage['let' + itoa( atoi('A') + x) ];
}
sendResponse({colors: colorList});
}
else{
sendResponse({}); // snub them.
}
});
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions jquery-1.7.2.min.js

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions jquery.highlight-3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* modified version of a highlight function for jquery, original developed by Johann Bukard; alterations done by Adam Savvas
MIT license also applies to modified version
*/

//original credit that went with highlight
/*
highlight v3
Highlights arbitrary terms.
<http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>
MIT license.
Johann Burkard
<http://johannburkard.de>
<mailto:[email protected]>
*/

jQuery.fn.highlight = function(pat, mcolor) {
function innerHighlight(node, pat) {
var skip = 0;
if (node.nodeType == 3) {
var pos = node.data.toUpperCase().indexOf(pat);
if (pos >= 0) {
var spannode = document.createElement('span');
//spannode.className = 'highlight';
spannode.style.color = mcolor
var middlebit = node.splitText(pos);
var endbit = middlebit.splitText(pat.length);
var middleclone = middlebit.cloneNode(true);
spannode.appendChild(middleclone);
middlebit.parentNode.replaceChild(spannode, middlebit);
skip = 1;
}
}
else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
for (var i = 0; i < node.childNodes.length; ++i) {
i += innerHighlight(node.childNodes[i], pat);
}
}
return skip;
}
return this.each(function() {
innerHighlight(this, pat.toUpperCase());
});
};
16 changes: 16 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Synesthetize",
"version": "1.11",
"manifest_version": 2,
"description": "Color code individual characters on pages you view -- induce color-graphemic synesthesia",
"options_page": "options.html",
"content_scripts": [
{ "matches": ["http://*/*","https://*/*","file:///*/*"],
"js": ["jquery-1.7.2.min.js","jquery.highlight-3.js","swap.js"],
"all_frames": false
}

],
"background": { "scripts": ["background.js"]},
"icons": { "128": "128-t.png" }
}
1 change: 1 addition & 0 deletions mystyles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.highlight { color: yellow }
40 changes: 40 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<html>
<head><title>Synaesthete options</title></head>
<body>
<script src="optsave.js"></script>
Set colors:
<form id="mform"><span id="letterA">
A: </span><input type="text" name="letA" value="#800000" id ="letA"/> <br /><span id="letterB">
B: </span><input type="text" name="letB" id="letB" /> <br /><span id="letterC">
C: </span><input type="text" name="letC" id="letC" /> <br /><span id="letterD">
D: </span><input type="text" name="letD" id="letD" /> <br /><span id="letterE">
E: </span><input type="text" name="letE" id="letE" /> <br /><span id="letterF">
F: </span><input type="text" name="letF" id="letF" /> <br /><span id="letterG">
G: </span><input type="text" name="letG" id="letG" /> <br /><span id="letterH">
H: </span><input type="text" name="letH" id="letH" /> <br /><span id="letterI">
I: </span><input type="text" name="letI" id="letI" /> <br /><span id="letterJ">
J: </span><input type="text" name="letJ" id="letJ" /> <br /><span id="letterK">
K: </span><input type="text" name="letK" id="letK" /> <br /><span id="letterL">
L: </span><input type="text" name="letL" id="letL" /> <br /><span id="letterM">
M: </span><input type="text" name="letM" id="letM" /> <br /><span id="letterN">
N: </span><input type="text" name="letN" id="letN" /> <br /><span id="letterO">
O: </span><input type="text" name="letO" id="letO" /> <br /><span id="letterP">
P: </span><input type="text" name="letP" id="letP" /> <br /><span id="letterQ">
Q: </span><input type="text" name="letQ" id="letQ" /> <br /><span id="letterR">
R: </span><input type="text" name="letR" id="letR" /> <br /><span id="letterS">
S: </span><input type="text" name="letS" id="letS" /> <br /><span id="letterT">
T: </span><input type="text" name="letT" id="letT" /> <br /><span id="letterU">
U: </span><input type="text" name="letU" id="letU" /> <br /><span id="letterV">
V: </span><input type="text" name="letV" id="letV" /> <br /><span id="letterW">
W: </span><input type="text" name="letW" id="letW" /> <br /><span id="letterX">
X: </span><input type="text" name="letX" id="letX" /> <br /><span id="letterY">
Y: </span><input type="text" name="letY" id="letY" /> <br /><span id="letterZ">
Z: </span><input type="text" name="letZ" id="letZ" /> <br />
</form>

<br>
<button>Save</button>

<span id="status"></span>
</body>
</html>
73 changes: 73 additions & 0 deletions optsave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Saves options to localStorage.

// Converts an integer (unicode value) to a char
function itoa(i)
{
return String.fromCharCode(i);
}

// Converts a char into to an integer (unicode value)
function atoi(a)
{
return a.charCodeAt();
}

// Restores select box state to saved value from localStorage.
function restore_options() {

var mform = document.getElementById("mform");
for( var x= 0; x < 26; x++) {
var mlet = "let" + itoa( atoi('A') + x);
var mbox = mform.elements[mlet] //document.getElementByID(mlet);
//var index = mbox.selectedIndex;
//var mbox = document.getElementById("let" + mlet );

//document.write(mcolor)
var mspan = document.getElementById( "letter" + itoa( atoi('A') + x) ) ;
if (localStorage[mlet]){
mbox.value = localStorage[mlet];
mspan.style.color = localStorage[mlet];
} else{
mbox.value = "";
mspan.style.color = '#000000'
}

}
}

function save_options() {

var mform = document.getElementById("mform")
for( var x= 0; x < 26; x++) {
var mlet = "let" + itoa( atoi('A') + x);
//document.write(mlet)
var mbox = mform.elements[mlet] //document.getElementByID(mlet);
//var index = mbox.selectedIndex;
//var mbox = document.getElementById("let" + mlet );
var mcolor = mbox.value;
//document.write(mcolor)
localStorage[mlet] = mcolor;
//mform.elements[mlet].color = mcolor
}


var status = document.getElementById("status");
status.innerHTML = "Options Saved!";
/* setTimeout(function() {
status.innerHTML = "";
}, 1750);*/
localStorage['saved'] = "Y"
restore_options();
}


function clickHandler(e) {
setTimeout(save_options, 1000);
}
// Add event listeners once the DOM has fully loaded by listening for the
// `DOMContentLoaded` event on the document, and adding your listeners to
// specific elements when it triggers.
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('button').addEventListener('click', clickHandler);
restore_options()
});
60 changes: 60 additions & 0 deletions swap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Converts an integer (unicode value) to a char
function itoa(i)
{
return String.fromCharCode(i);
}

// Converts a char into to an integer (unicode value)
function atoi(a)
{
return a.charCodeAt();
}

//just an array of number to letter mappings
var letters = new Array()
for( x=0; x<26; x++){
letters[x] = itoa( atoi('a') + x);
}

//get array of letters and their corresponding colors
chrome.extension.sendRequest({method: "getColors"}, function(response) {
console.log(response.colors);

for( x=0; x<26; x++){
var let = itoa( atoi('A') + x);
var mlet = "let" + let;
//document.write('letter:' + let+ ' the stored result is: ' + localStorage[mlet] + "<br>" );
if(response.colors[x]){
$('body').highlight(let,response.colors[x]);
}

}



});

/*
//set defaults if not yet defined
if (!localStorage['saved']){
localStorage['letA'] = '#800000'; //maroon
localStorage['letE'] = '#008000'; //green
localStorage['letI'] = '#0000ff'; //blue
localStorage['letO'] = '#008080'; //teal
localStorage['letU'] = '#800080'; //purple
localStorage['saved'] = 'Y'
}
*/
/*
//for each letter, if it's not
for( x=0; x<26; x++){
var let = itoa( atoi('A') + x);
var mlet = "let" + let;
//document.write('letter:' + let+ ' the stored result is: ' + localStorage[mlet] + "<br>" );
if(localStorage[mlet]){
$('*').highlight(let,localStorage[mlet]);
}
}
*/

0 comments on commit 3a8da20

Please sign in to comment.