Last active
December 22, 2016 18:03
-
-
Save colintsteele/7aa66ca40eadfcec8dd8c2b7a282be07 to your computer and use it in GitHub Desktop.
chrome extension for name processing and hyperlinking
This file contains hidden or 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
//send to Alchemy | |
//send to Google Custom Search API | |
function | |
$.ajax({ | |
//API key and search engine id are embedded in url | |
//Process returns URL of first image result equal to face | |
url: "https://www.googleapis.com/customsearch/v1?key=AIzaSyBh1mbRlS0Mutavt8PuoIytqpn0Bsn_JIM&cx=013039004155227536814:lobto-0zlua&", | |
data: { | |
'q' : 'bush', //Change to name variable | |
'num' : '1', | |
'imgSize' : 'medium', | |
'searchType' : 'image', | |
'imgType':'face', | |
}, | |
type: "GET", | |
success: function(response) { | |
console.dir(response)}}); | |
function | |
$.ajax({ | |
url: "https://gateway-a.watsonplatform.net/calls/url/URLGetCombinedData?apikey=6c8944b20948847c3923961cac83b128fe1dbd03", | |
data: { | |
'outputMode' : 'json', | |
'extract' : 'entities', | |
'sentiment' : '1', | |
'maxRetrieve' : '12', | |
//'text' : "In civil law jurisdictions, a nominate contract is a standardized contractual relationship that has a special designation attached to it (e.g., purchase and sale, lease, loan, insurance), as opposed to innominate contracts (which are not standardized and therefore have no set name).[1] The obligor and obligee have rights and obligations specially prescribed by law. Nominate contracts are usually statutorily required to include certain express terms (essentialia)—depending on their kind—and are construed to include terms implied in law.", | |
//'url' : 'https://en.wikipedia.org/wiki/Billy_corgan', | |
}, | |
cache: false, | |
type: "POST", | |
success: function(response) { | |
var names = [] | |
for (entity in response.entities){ | |
if (entity.type == "person"){ | |
names.push(entity) | |
} | |
} | |
}, | |
error: function(xhr) { | |
//we may want to re-enque this request if it fails, or display some button for the user to press to tell us to send the request, in case their internet went out or something | |
} | |
}); | |
//groups all text on page | |
all_text = "" | |
for( p_tag in $('p') ) { | |
all_text += p_tag.innerText //I think this may be outterHTML. To check, type $('p')[0] - the first p in the collection of ps - and see which method has our text. | |
} | |
//$('') for tags example: $('p') | |
//$('.') for classes example: $('.round_box_thingies') | |
//$('#') for ids example: $('#colin') | |
function identifyPerson(name){ | |
person = new Person(name) | |
} | |
//we probably also want a class to represent AllText | |
function Person(name){ | |
self.name = name | |
self.portrait = | |
function getPortrat(){ | |
return getWikipediaPortrat(); | |
} | |
function getWikipediaPortrait(){ | |
//wiki api -> self.name | |
//success -> return portrait | |
//error -> get google portrait | |
} | |
function getGooglePortrait(){ | |
//google search | |
} | |
} | |
function PageText(p_tags, names){//do we really just pass p_tags to this class to initialize it? | |
self.names = names; | |
self.all_ps = p_tags; | |
self.all_text = ""; | |
for(p in all_ps){ | |
self.all_text += p.outterHTML(); | |
} //idk | |
function tag_names(){ | |
all_words = self.text.deconstruct(); | |
give_spans(names);//output variable bad, could classify all_words, allows give_spans(names) and reconstruct() | |
reconstruct(); // as opposed to give_spans(names, allwords) and reconstruct(allwords) | |
} | |
} | |
//probably lives in our AllText class | |
function deconstruct(names){ | |
//assume sanitized | |
words = self.text.sanitize().split(' ') | |
//this is actually the give_spans method | |
for(name in names){ //these loops should probably be switched | |
for(i=0;i<words.size;i++){ | |
if(words[i] + words[i+1] == name)//exception for index out of range AND write comprise() function | |
word[i] = "<span class='name' id='"+name+""+i"'>"+word[i] //fuck ugly interpolation in ruby it looks like "<span id='#{name}#{i}'" | |
//reassigning first name to <span> + firstname | |
word[i+1] = ""+word[i+1]+"</span>" | |
next //we do next so that we don't do this logic again on the second name, we skip it to avoid errors and wasted time | |
} | |
} | |
} | |
function reconstruct(alltext){ | |
all_text = "" | |
for word in alltext | |
all_text += word | |
return all_text | |
} | |
function put_names(name){ | |
portrait = Name.portrait | |
nameoxes = getElementsFor(name) | |
hyperlink_name_boxes(name_boxes) | |
render_name_boxes | |
render_boxes | |
} | |
if (displayed) { | |
element.css('display','none'); | |
if | |
} else { | |
element.css('display','block'); | |
} | |
//get the text on the page | |
//https://np.reddit.com/r/politics/comments/5j114m/harvard_professor_says_there_are_grave_concerns/dbchug5/ | |
for( myiterator in $('.md < p' ) ) | |
for(i = 0; i <= 12 ;i++){ | |
if(i>=2) | |
// V this <p breaks the query for some reason | |
all_text += $('.md < p' )[i].innerHtml | |
} | |
all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//send to Google Custom Search API
function
$.ajax({
//API key and search engine id are embedded in url
//Process returns URL of first image result equal to face