Created
September 1, 2014 05:48
-
-
Save cheesinglee/fde144dae701b05bed9e to your computer and use it in GitHub Desktop.
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
function fetchModel(){ | |
chrome.storage.sync.get({ | |
username: "BigML Username", | |
apikey: "BigML API Key" | |
}, | |
function(items){ | |
var models_url = "https://bigml.io/andromeda/model?name=kiva-model;username=" + items.username + ";api_key=" + items.apikey ; | |
var xmlHttp = new XMLHttpRequest() ; | |
xmlHttp.open("GET",models_url,false) ; | |
xmlHttp.send(null) ; | |
if (xmlHttp.status == 200){ | |
var resp = JSON.parse(xmlHttp.responseText) ; | |
var model = resp.objects[0].resource ; | |
chrome.storage.sync.set({model:model}) | |
} | |
else{ | |
alert("Could not list BigML models, your credentials may be incorrect.") | |
chrome.tabs.query({title:"Kiva Predictor Options"},function(result){ | |
if (result.length == 0){ | |
chrome.tabs.create({url:"options.html"}) | |
} | |
}) ; | |
} | |
}) | |
} | |
function firstRun(){ | |
chrome.tabs.create({url:"options.html"}) | |
} | |
chrome.runtime.onInstalled.addListener(firstRun) ; | |
chrome.runtime.onStartup.addListener(fetchModel) ; | |
chrome.runtime.onMessage.addListener(function(request,sender,sendResponse){ | |
if (request.greeting == "fetchmodel"){ | |
fetchModel() ; | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment