Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Updated extension to use new sendmessage apis.
Browse files Browse the repository at this point in the history
  • Loading branch information
normano committed Sep 7, 2012
1 parent 20807eb commit a4c9236
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 218 deletions.
12 changes: 6 additions & 6 deletions dataExtractor.js
@@ -1,6 +1,6 @@
// Send request to extension to see if its online
var request = {request: "available"};
chrome.extension.sendRequest(request, initializeRequest);
chrome.extension.sendMessage(request, initializeRequest);

// Start up the data extraction
function initializeRequest(response)
Expand Down Expand Up @@ -30,9 +30,9 @@ function initializeRequest(response)
});

// Store articles from current tab
chrome.extension.sendRequest({request: "addTabData", data: articleData});
chrome.extension.sendMessage({request: "addTabData", data: articleData});
// Send the titles to the classifier
chrome.extension.sendRequest({request: "classify", data: articleData}, classify);
chrome.extension.sendMessage({request: "classify", data: articleData}, classify);
}

function classify(response)
Expand All @@ -55,14 +55,14 @@ function initializeRequest(response)
// If we clicked the more button to process dataset
if( element.text() === "More" )
{
chrome.extension.sendRequest({request: "train"});
chrome.extension.sendMessage({request: "train"});
return; // Nothing more needs to be done.
}

// We've clicked on an article, so label as interesting
var textNormalized = normalizeString(element.text());
var link = element.attr('href');
chrome.extension.sendRequest({request: "label", dataPoint: {title: textNormalized, link:link, label: 1}});
chrome.extension.sendMessage({request: "label", dataPoint: {title: textNormalized, link:link, label: 1}});

event.preventDefault(); // Yeah....
window.open(link, '_newtab');
Expand All @@ -71,7 +71,7 @@ function initializeRequest(response)
function pageUnload(event)
{
// Remove the stored tab's data
chrome.extension.sendRequest({request: "removeTabData"});
chrome.extension.sendMessage({request: "removeTabData"});
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions main.js
Expand Up @@ -6,7 +6,7 @@ var defaultObj = {
var hnClassifier = null;

///// Load from IndexedDB
var dbVersion = 0.1;
var dbVersion = 1;
var indexedDB = window.indexedDB || window.webkitIndexedDB;
var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
var dbReq = indexedDB.open('newsRecommender', dbVersion);
Expand Down Expand Up @@ -80,7 +80,7 @@ function dbVersionChange(event)
}
else
{
objStore = newsRecDB.transaction(['websites'], IDBTransaction.READ_WRITE).objectStore("websites");
objStore = newsRecDB.transaction(['websites'], "readwrite").objectStore("websites");
}

//console.log(objStore);
Expand Down Expand Up @@ -133,7 +133,7 @@ function initalize()
// Attach listeners
chrome.tabs.onUpdated.addListener(tabUpdated);
chrome.pageAction.onClicked.addListener(clickedPageAction);
chrome.extension.onRequest.addListener(sendRequestHandler);
chrome.extension.onMessage.addListener(sendRequestHandler);

///// Start sanity checks
if(online === null)
Expand Down Expand Up @@ -390,7 +390,7 @@ function sendRequestHandler(messageData, sender, sendResponse){
function dbSaveClassObjs(website, classObjs)
{
//localStorage.setItem('classObjs', JSON.stringify(classObjs));
var dbTrans = newsRecDB.transaction(['websites'],IDBTransaction.READ_WRITE).objectStore('websites');
var dbTrans = newsRecDB.transaction(['websites'], "readwrite").objectStore('websites');
dbTrans.put({name: website, data: classObjs});
}

Expand Down

0 comments on commit a4c9236

Please sign in to comment.