Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Research Assist
- */
- var manualMode = false;
- var isSearching = false;
- var search = "";
- var prevSearch = "";
- var rAssist;
- setBookmarkRoot();
- /**
- * A function that sets the bookmark node for Research Assist (and creates it)
- */
- function setBookmarkRoot() {
- chrome.bookmarks.search({'title': 'Research Assist'}, function (tmp) {
- //console.log(tmp);
- if (tmp.length < 1) {
- chrome.bookmarks.create({'title': 'Research Assist'},
- function(newFolder) {
- //console.log("created root :" + newFolder.title);
- rAssist= newFolder;
- });
- } else {
- rAssist = tmp[0]; //node is hopefully in the first slot here...
- }
- });
- }
- chrome.webRequest.onCompleted.addListener(function(e){
- queryUrl = e.url.split("q=")[1] || e.url.split("t=")[1];
- query = queryUrl[0].split("%20").join(" ").split("+").join(" ");
- prevSearch = query;
- isSearching = !manualMode;
- if ( query.length == 0 )
- return;
- prevSearch = query;
- }, {urls: ["*://www.google.com/*q=*", "*://www.bing.com/*q=*", "*://www.yahoo.com/*t=*", "*://www.ask.com/*q=*", "*://search.aol.com/*q=*", "*://www.searchaol.com/*q=*", "*://*.wow.com/*q=*",
- "*://www.webcrawler.com/*q=*", "*://*.infospace.com/*q=*", "*://www.dogpile.com/*q=*"]});
- chrome.webRequest.onCompleted.addListener(function(e){
- if (isSearching && e.type=="main_frame") {
- console.log(e);
- var url = e.url;
- var title;
- console.log("trying to add", url, " ", e);
- chrome.tabs.query({active: true, currentWindow:true}, function (rTabs) {
- addResearchMark(url, rTabs[0].title || url);
- });
- }
- }, {urls: ["*://*/*"]});
- /**
- * Adds a "Research Mark" which is a bookmark and an entry in popup.html.
- * popup.html either needs to be dynamically populated or stored otherwise a reload event will fire losing all
- * of the current marks.
- */
- function addResearchMark(url, title) {
- if (document.getElementById("searches").innerHTML.search(url)==-1){ //if it's not in the list, add it.
- document.getElementById("searches").innerHTML += "<li><a href='"+ url + "'>" + title + " </a> </li> ";
- console.log("[#searches] adding item for ", url, title);
- }
- chrome.bookmarks.search({'url' : url, 'title' : title}, function (bma) {
- if (bma.length==0) {
- chrome.bookmarks.create({ 'parentId' : rAssist.id, 'title': title, 'url': url}, function(bm) {
- console.log("[Research Mark] adding item for ", bm.url, bm.title);
- });
- }
- });
- }
- /*
- chrome.history.onVisited.addListener(function (e) {
- if (isSearching) {
- var url = e.url;
- var title = e.title || e.url;
- addResearchMark(url, title);
- }
- });*/
- function pause() {
- isSearching = false;
- }
- function activate() {
- isSearching = true;
- }
- function manual() {
- if (manualMode) {
- document.getElementById("manualMode").innerHTML = "Automatic Mode";
- manualMode = true;
- } else {
- document.getElementById("manualMode").innerHTML = "Manual Mode";
- manualMode = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement