diff --git a/background.js b/background.js
index 1102663..2fceaa1 100644
--- a/background.js
+++ b/background.js
@@ -1,7 +1,7 @@
/**
* Created by gdev on 3/19/2017.
*/
-var highlightTabs;
+ var highlightTabs;
var tabsBackground;
var currWindow;
var timeOut;
@@ -9,7 +9,7 @@ var lastTab;
var urls = [];
var tabToHilite;
var openAt;
-var firstPage;
+var firstPage = "";
var invokedWind;
var startTime;
var pagesToOpen = [];
@@ -20,19 +20,23 @@ var options = ['tabsBackground', 'highlightTabs', 'timeOut', 'tabToLoad'];
var loading_images = ['ajax-loader_LB.gif',
- 'ajax-loader_LT.gif',
- 'ajax-loader_RT.gif',
- 'ajax-loader_RB.gif'];
-
+ 'ajax-loader_LT.gif',
+ 'ajax-loader_RT.gif',
+ 'ajax-loader_RB.gif'];
+
var image_index = 0;
var tabLoadTimeout = 60;
-
+
var keep_switching_icon;
function rotateIcon(rotate)
-{
+{
keep_switching_icon = rotate === undefined ? keep_switching_icon : rotate;
const image = keep_switching_icon ? "icons/" + loading_images[image_index] : "icons/ic_title_black_24dp_1x.png";
- chrome.browserAction.setIcon({path: image});
+ //console.log("currWindow--" + currWindow + "---" + invokedWind);
+ //if (currWindow === invokedWind) {
+ chrome.browserAction.setIcon({path: image});
+ //}
+
image_index = (image_index + 1) % loading_images.length;
if ( keep_switching_icon )
@@ -41,83 +45,101 @@ function rotateIcon(rotate)
}
}
chrome.storage.sync.get( options, function(items) {
- highlightTabs = items.highlightTabs;
- tabsBackground = items.tabsBackground;
- timeOut = items.timeOut * 1000;
- tabToLoad = items.tabToLoad;
- console.log("time out--" + tabToLoad);
+ highlightTabs = items.highlightTabs;
+ tabsBackground = items.tabsBackground;
+ timeOut = items.timeOut * 1000;
+ tabToLoad = items.tabToLoad;
+ console.log("time out--" + tabToLoad);
});
chrome.windows.getCurrent(function(win){
currWindow = win.id;
});
chrome.storage.sync.get(function(data) {
- console.log("data sync " + JSON.stringify(data));
-});
+ console.log("data sync " + JSON.stringify(data));
+});
chrome.storage.onChanged.addListener(function(changes, area) {
- console.log("in bkgd page" + JSON.stringify(changes));
- //console.log("currWindow from bkg" + currWindow);
-
+ console.log("in bkgd page" + JSON.stringify(changes));
+ //console.log("currWindow from bkg" + currWindow);
+
if (area == "sync" && "urlsToOpen" in changes) {
- urls = changes.urlsToOpen.newValue;
- if (typeof urls != "undefined" && urls !== null && urls.length > 0) {
- pagesToOpen = urls;
- tabToHilite = [changes.currTab.newValue.index];
- openAt = changes.currTab.newValue.index;
- invokedWind = changes.invokedWindow.newValue;
- console.log("invoked from " + invokedWind + "\n urls-" + urls.length);
- console.log("list of urls to open--" + urls);
- if (!changes.opnSmeTb.newValue) {
- if (Array.isArray(urls)) {
- currentTask = true;
- openAt ++;
- startTime = new Date().getTime();
- chrome.tabs.create({url: urls[0], active : !tabsBackground, index: parseInt(openAt), windowId : invokedWind}, function(tab){
- tabToHilite.push(tab.index);
- openAt ++;
- //console.log(JSON.stringify(tab));
- firstPage = tab.id;
- lastTab = tab.id;
- console.log("reset" + openAt + urls[0]);
- // chrome.browserAction.setIcon({path:"icons/ajax-loader.gif"});
- //keep_switching_icon = true;
- //console.log(keep_switching_icon);
- rotateIcon(true);
- chrome.tabs.onRemoved.addListener(function (tabId , info) {
- if (tabId === lastTab) {
- chrome.storage.sync.set({loading: false}, function() {});
- rotateIcon(false);
- }
- });
-
- });
- } else {
- openAt ++;
- chrome.tabs.create({url: urls, active : !tabsBackground, index: parseInt(openAt), windowId : invokedWind}, function(tab){
- tabToHilite.push(tab.index);
- });
- chrome.storage.sync.set({loading: false}, function() {});
- }
- } else {
- chrome.tabs.update(changes.currTab.newValue.id, {url: urls[0]});
- chrome.storage.sync.set({loading: false}, function() {});
- }
-
- if (highlightTabs) {
- chrome.tabs.highlight({tabs: tabToHilite, windowId: invokedWind}, function(){
- if (chrome.runtime.error) {
- console.log("Runtime error.");
- }
- });
- }
-
- }
- chrome.storage.sync.set({urlsToOpen: [], currTab : "", invokedWindow : "", opnSmeTb : ""}, function() {});
- }
- if (chrome.runtime.error) {
- console.log("ddd Runtime error.");
+ urls = changes.urlsToOpen.newValue;
+ if (typeof urls != "undefined" && urls !== null && urls.length > 0) {
+ pagesToOpen = urls;
+ tabToHilite = [changes.currTab.newValue.index];
+ openAt = changes.currTab.newValue.index;
+ invokedWind = changes.invokedWindow.newValue;
+ console.log("invoked from " + invokedWind + "\n urls-" + urls.length);
+ console.log("list of urls to open--" + urls);
+ console.log(tabToLoad);
+ if (!changes.opnSmeTb.newValue) {
+ if (Array.isArray(urls)) {
+ currentTask = true;
+ openAt ++;
+ startTime = new Date().getTime();
+ //var url = urls[0];
+ var loopLimit = urls.length < parseInt(tabToLoad) ? urls.length : parseInt(tabToLoad);
+ for (var x = 0;x < loopLimit; x++) {
+ console.log("link----------------" + urls[x]);
+ url = urls[x];
+ chrome.tabs.create({url: url, active : !tabsBackground, index: parseInt(openAt), windowId : invokedWind}, function(tab){
+ tabToHilite.push(tab.index);
+ //openAt ++;
+
+ //pagesToOpen.shift();
+ //console.log(JSON.stringify(tab));
+ if (firstPage === "") {
+ console.log("x equal to zero");
+ firstPage = tab.id;
+
+ }
+ lastTab = tab.id;
+ console.log("reset" + openAt + url);
+ // chrome.browserAction.setIcon({path:"icons/ajax-loader.gif"});
+ //keep_switching_icon = true;
+ //console.log(keep_switching_icon);
+ rotateIcon(true);
+
+ chrome.tabs.onRemoved.addListener(function (tabId , info) {
+ if (tabId === lastTab) {
+ chrome.storage.sync.set({loading: false}, function() {});
+ rotateIcon(false);
+ //chrome.browserAction.setIcon({path: "icons/ic_title_black_24dp_1x.png", tabId : tabId});
+ }
+ });
+
+ });
+ openAt ++;
+
+ }
+
+ } else {
+ openAt ++;
+ chrome.tabs.create({url: urls, active : !tabsBackground, index: parseInt(openAt), windowId : invokedWind}, function(tab){
+ tabToHilite.push(tab.index);
+ });
+ chrome.storage.sync.set({loading: false}, function() {});
+ }
+ } else {
+ chrome.tabs.update(changes.currTab.newValue.id, {url: urls[0]});
+ chrome.storage.sync.set({loading: false}, function() {});
+ }
+
+ if (highlightTabs) {
+ chrome.tabs.highlight({tabs: tabToHilite, windowId: invokedWind}, function(){
+ if (chrome.runtime.error) {
+ console.log("Runtime error.");
+ }
+ });
+ }
+
+ }
+ chrome.storage.sync.set({urlsToOpen: [], currTab : "", invokedWindow : "", opnSmeTb : ""}, function() {});
}
-
+ if (chrome.runtime.error) {
+ console.log("ddd Runtime error.");
+ }
+
});
var parentUrl = "";
@@ -132,74 +154,88 @@ var parentTitle = "";
});*/
chrome.tabs.onUpdated.addListener(function(tabId , changeInfo, info) {
- console.log("Test " + tabId + "--" + JSON.stringify(info) + "--" + JSON.stringify(changeInfo));
- if (parentUrl === "") {
- parentUrl = info.url;
- parentTitle = info.title;
- //chrome.storage.sync.set({parentUrl: parentUrl}, function() {});
- }
-
- console.log("urls ln" + pagesToOpen.length);
- if (info.status === "loading" && tabId === lastTab) {
- var now = new Date().getTime();
- console.log(now - startTime);
- console.log(timeOut);
- if (now - startTime > timeOut) {
- chrome.browserAction.setIcon({path:"icons/ic_title_black_24dp_1x.png"});
- chrome.storage.sync.set({loading: false}, function() {});
- rotateIcon(false);
- currentTask = false;
- }
- }
- console.log(lastTab + "--tt--" + openAt);
-
- if (currentTask) {
- if (info.status === "complete" && tabId === lastTab && pagesToOpen.length > 1) {
- console.log("firstPage--" + firstPage);
- if (firstPage !== "") {
- chrome.tabs.update(firstPage, {active: true});
- firstPage = "";
- }
- console.log("k is-" + k);
- if (k === parseInt(tabToLoad)) {
- console.log("k is 2" + new Date().getTime());
- k = 0;
- }
- for ( ;k < parseInt(tabToLoad); k++) {
- console.log("k inside for--" + k + "---" + new Date().getTime());
- pagesToOpen.shift();
- chrome.tabs.create({url: pagesToOpen[0], active : false, index: parseInt(openAt), windowId : invokedWind}, function(tab) {
- lastTab = tab.id;
- tabToHilite.push(tab.index);
- openAt ++;
- });
- if (pagesToOpen.length == 1) {
- return;
- }
- }
-
- }
- if (info.status === "complete" && tabId === lastTab && pagesToOpen.length == 1) {
- chrome.browserAction.setIcon({path:"icons/ic_title_black_24dp_1x.png"});
- //chrome.runtime.sendMessage({msg: "completed"}, function(response) {});
- chrome.storage.sync.set({loading: false}, function() {});
- //keep_switching_icon = false;
- rotateIcon(false);
- currentTask = false;
- }
- }
+ console.log("Test " + tabId + "--" + JSON.stringify(info) + "--" + JSON.stringify(changeInfo));
+ if (parentUrl === "") {
+ parentUrl = info.url;
+ parentTitle = info.title;
+ //chrome.storage.sync.set({parentUrl: parentUrl}, function() {});
+ }
+
+ console.log("urls ln" + pagesToOpen.length);
+ if (info.status === "loading" && tabId === lastTab) {
+ var now = new Date().getTime();
+ console.log(now - startTime);
+ console.log(timeOut);
+ if (now - startTime > timeOut) {
+ chrome.browserAction.setIcon({path:"icons/ic_title_black_24dp_1x.png"});
+ chrome.storage.sync.set({loading: false}, function() {});
+ rotateIcon(false);
+ currentTask = false;
+ }
+ }
+ console.log(lastTab + "--tt--" + openAt);
+
+ if (currentTask) {
+ if (info.status === "complete" && tabId === lastTab && pagesToOpen.length > 1) {
+ console.log("firstPage--" + firstPage);
+ if (firstPage !== "") {
+ chrome.tabs.update(firstPage, {active: true});
+ firstPage = "";
+ console.log("before-------------" + pagesToOpen.length);
+ for (var i = 0 ; i < parseInt(tabToLoad) - 1; i ++) {
+ pagesToOpen.shift();
+ }
+ console.log("after-------------" + pagesToOpen.length);
+ }
+ console.log("k is-" + k);
+ if (k === parseInt(tabToLoad)) {
+ console.log("k is 2" + new Date().getTime());
+ k = 0;
+ }
+
+ for ( ;k < parseInt(tabToLoad); k++) {
+ console.log("k inside for--" + k + "---" + new Date().getTime() + "--------" + pagesToOpen[0]);
+ pagesToOpen.shift();
+ console.log(pagesToOpen.length);
+ if (pagesToOpen.length > 0 ){
+ chrome.tabs.create({url: pagesToOpen[0], active : false, index: parseInt(openAt), windowId : invokedWind}, function(tab) {
+ lastTab = tab.id;
+ tabToHilite.push(tab.index);
+ //openAt ++;
+ });
+ }
+
+ openAt ++;
+ if (pagesToOpen.length === 1) {
+ return;
+ }
+ }
+
+ }
+ if (info.status === "complete" && tabId === lastTab && pagesToOpen.length <= 1) {
+ console.log("current task done...");
+ chrome.browserAction.setIcon({path:"icons/ic_title_black_24dp_1x.png"});
+ //chrome.runtime.sendMessage({msg: "completed"}, function(response) {});
+ chrome.storage.sync.set({loading: false}, function() {});
+ //keep_switching_icon = false;
+ rotateIcon(false);
+ currentTask = false;
+ }
+ }
});
/*
chrome.browserAction.onClicked.addListener(function(tab) {
console.log("call adi");
- //chrome.tabs.executeScript(null, {file: "content_script.js"});
+ chrome.tabs.executeScript({file: "./popup.js"});
+
+
});*/
/*
chrome.runtime.onMessage.addListener(function(req, sender, sendres){
console.log("in lstnr");
-
-
+
+
});*/
diff --git a/content_script.js b/content_script.js
index 1f9b822..2182928 100644
--- a/content_script.js
+++ b/content_script.js
@@ -1,91 +1,478 @@
var jsonObj = {};
//jsonObj["current"] = "search";
-//jsonObj["description"] = "google search";
+ //jsonObj["description"] = "google search";
var sites = [];
-var queryString;
+var queryString = "";
var hrefAdded = [];
-//google
-$("div#rso > div._NId:first").find("div.g").find("div.rc").find("h3 > a").each(function (index) {
- console.log("Title: " + this.text);
- console.log($(this));
- //$(this).append("
My new line text");
- console.log('me done');
- var obj = {};
- obj[this.text] = $(this).attr('href');
- sites.push(obj);
- hrefAdded.push($(this).attr('href'));
-
-
-});
+function refreshObj() {
+ chrome.storage.local.get('googleSearch', function(searchResult){
+ console.log("result orig-" + JSON.stringify(searchResult));
+ if (searchResult.googleSearch) {
+ jsonObj = searchResult.googleSearch;
+ }
+
+ if (location.origin.indexOf('cnn') > -1) {
+ queryString = "";
+ //cnn
+ var urlBase = location.origin;
+ console.log(urlBase);
+ $("div.cd__content").find("h3 > a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+ //var urlBase = location.origin;
+ //console.log(urlBase);
+ if (hrefAdded.indexOf($(this).attr('href')) === -1) {
+ console.log("not in hrefadded array");
+ // var partialUrl = $(this).attr('href');
+ //var fullUrl = urlBase + partialUrl;
+ //console.log(fullUrl);
+ obj[this.text] = location.origin + $(this).attr('href');
+ sites.push(obj);
+ }
+
+ });
+ //jsonObj['cnn'] = sites;
+ var newObj = {};
+ newObj["current"] = location.origin;
+ newObj["tree"] = false;
+ newObj["sites"] = sites; //[newEntryObj];
+ jsonObj['cnn'] = newObj;
+ /*console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ //chrome.storage.local.set({'googleSearch': "", 'queryString' : "", 'searchEngine' : ""}, function() {});
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });*/
+ } else if (location.origin.indexOf('google') > -1) {
+ //refreshObj();
+ queryString = document.getElementsByName("q")[0].value;
+
+ //google
+ $("div#rso > div._NId:first").find("div.g").find("div.rc").find("h3 > a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+
+ obj[this.text] = $(this).attr('href');
+ sites.push(obj);
+ hrefAdded.push($(this).attr('href'));
+
+
+ });
+
+ $("div#rso").find("div > g-section-with-header").find("h3").find("a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+ if (hrefAdded.indexOf($(this).attr('href')) === -1) {
+ obj[this.text] = $(this).attr('href');
+ sites.push(obj);
+ }
+
+
+ });
+
+ $("div.srg").find("h3 > a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+ if (hrefAdded.indexOf($(this).attr('href')) === -1) {
+ obj[this.text] = $(this).attr('href');
+ sites.push(obj);
+ }
+
+ });
+ console.log("Orig object...\n" + JSON.stringify(jsonObj));
+ //jsonObj['google'] = sites;
+ var newObj = {};
+ newObj["current"] = location.origin;
+ newObj["tree"] = false;
+ newObj["sites"] = sites; //[newEntryObj];
+ jsonObj['google'] = newObj;
+ console.log("Final object...\n" + JSON.stringify(jsonObj));
+ /*console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });*/
+ sites = [];
+ } else if (location.origin.indexOf('bing') > -1){
+ //refreshObj();
+ queryString = document.getElementsByName("q")[0].value;
+ //bing //ol.b_results
+
+ $("ol#b_results > li.b_algo").find("h2 > a").each(function () {
+ console.log("Title: " + this.text);
+ var lnk = $(this).attr('href');
+ console.log("from: " + JSON.stringify(lnk));
+ var obj = {};
+ obj[this.text] = $(this).attr('href');
+ sites.push(obj);
+ });
+ //jsonObj['bing'] = sites;
+ var newObj = {};
+ newObj["current"] = location.origin;
+ newObj["tree"] = false;
+ newObj["sites"] = sites; //[newEntryObj];
+ jsonObj['bing'] = newObj;
+ /*console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });*/
+
+ } else if (location.origin.indexOf('yahoo') > -1) {
+
+ queryString = document.getElementsByName("p")[0].value;
+ //yahoo
+ $("div#web").find("h3 > a").each(function () {
+ console.log("Title: " + this.text);
+ var lnk = $(this).attr('href');
+ console.log("from: " + JSON.stringify(lnk));
+ var obj = {};
+ obj[this.text] = $(this).attr('href');
+ sites.push(obj);
+ });
+ //jsonObj['yahoo'] = sites;
+ var newObj = {};
+ newObj["current"] = location.origin;
+ newObj["tree"] = false;
+ newObj["sites"] = sites; //[newEntryObj];
+ jsonObj['yahoo'] = newObj;
+ /*console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });*/
+ } else if (location.origin.indexOf('youtube') > -1) {
+
+ queryString = document.getElementsByName("search_query")[0].value;
+ //youtube //find("ytd-video-renderer")
+ $("div#contents").find("h3 > a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+ if (hrefAdded.indexOf($(this).attr('href')) === -1) {
+ obj[this.text] = location.origin + $(this).attr('href');
+ sites.push(obj);
+ }
+
+ //div#title-wrapper
+ });
+ console.log("Orig object...\n" + JSON.stringify(jsonObj));
+ //jsonObj['youtube'] = sites;
+ var newObj = {};
+ newObj["current"] = location.origin;
+ newObj["tree"] = false;
+ newObj["sites"] = sites; //[newEntryObj];
+ jsonObj['youtube'] = newObj;
+ console.log("Final object...\n" + JSON.stringify(jsonObj));
+ /*console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });*/
+ } else if (location.origin.indexOf('stackoverflow') > -1) {
+ var groupedObj = {};
+ if (document.getElementsByName("q")) {
+ queryString = document.getElementsByName("q")[0].value;
+ }
+ //stackoverflow
+ var urlBase = location.origin;
+ console.log(urlBase);
+ if (queryString === "") {
+ $("div.summary").find("h3 > a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+ //var urlBase = location.origin;
+ //console.log(urlBase);
+ if (hrefAdded.indexOf($(this).attr('href')) === -1) {
+ console.log("not in hrefadded array");
+ // var partialUrl = $(this).attr('href');
+ //var fullUrl = urlBase + partialUrl;
+ //console.log(fullUrl);
+ obj[this.text] = location.origin + $(this).attr('href');
+ //var subItems=[];
+
+ $(this).parent().next().find("a").each (function (){
+ var subItems = groupedObj[this.text];
+ if (subItems && subItems.length > 0) {
+ subItems.push(obj);
+ } else {
+ subItems = [];
+ subItems.push(obj);
+ }
+ groupedObj[this.text] = subItems;
+
+ });
+
+ //sites.push(obj);
+ }
+
+ });
+ } else {
+ $("div.result-link").find("span > a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+ //var urlBase = location.origin;
+ //console.log(urlBase);
+ if (hrefAdded.indexOf($(this).attr('href')) === -1) {
+ console.log("not in hrefadded array");
+ // var partialUrl = $(this).attr('href');
+ //var fullUrl = urlBase + partialUrl;
+ //console.log(fullUrl);
+ obj[this.text] = location.origin + $(this).attr('href');
+ sites.push(obj);
+ }
+
+ });
+ }
+
+ //jsonObj['stackoverflow'] = sites;
+ var newObj = {};
+ newObj["current"] = location.origin;
+ newObj["tree"] = true;
+ newObj["sites"] = groupedObj; //sites; //[newEntryObj];
+ jsonObj['stackoverflow'] = newObj;
+ /*console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ //chrome.storage.local.set({'googleSearch': "", 'queryString' : "", 'searchEngine' : ""}, function() {});
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });*/
+ } else if (location.origin.indexOf('washingtonpost') > -1) {
+
+
+ //washingtonpost
+ $("div.headline").find("a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+ if (hrefAdded.indexOf($(this).attr('href')) === -1) {
+ obj[this.text] = $(this).attr('href');
+ sites.push(obj);
+ }
+
+ //div#title-wrapper
+ });
+
+ console.log("Orig object...\n" + JSON.stringify(jsonObj));
+ var newObj = {};
+ newObj["current"] = location.origin;
+ newObj["tree"] = false;
+ newObj["sites"] = sites; //[newEntryObj];
+ jsonObj['washingtonpost'] = newObj;
+ //jsonObj['washingtonpost'] = sites;
+ console.log("Final object...\n" + JSON.stringify(jsonObj));
+
+ }
+ console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });
+ sites = [];
+ });
+
+ //console.log("obj new-" + JSON.stringify(jsonObj));
+}
-$("div#rso").find("div > g-section-with-header").find("h3").find("a").each(function (index) {
- console.log("Title: " + this.text);
- console.log($(this));
- //$(this).append("
My new line text");
- console.log('me done');
- var obj = {};
- if (hrefAdded.indexOf($(this).attr('href')) === -1) {
- obj[this.text] = $(this).attr('href');
- sites.push(obj);
- }
+
+
+
+
+
+window.addEventListener ("load", myMain, false);
+
+function myMain (evt) {
+ //refreshObj();
+
+
+ /*if (location.origin.indexOf('cnn') > -1) {
+ refreshObj();
+ queryString = "";
+ //cnn
+ var urlBase = location.origin;
+ console.log(urlBase);
+ $("div.cd__content").find("h3 > a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+ //var urlBase = location.origin;
+ //console.log(urlBase);
+ if (hrefAdded.indexOf($(this).attr('href')) === -1) {
+ console.log("not in hrefadded array");
+ // var partialUrl = $(this).attr('href');
+ //var fullUrl = urlBase + partialUrl;
+ //console.log(fullUrl);
+ obj[this.text] = location.origin + $(this).attr('href');
+ sites.push(obj);
+ }
+
+ });
+ jsonObj['cnn'] = sites;
+ console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ //chrome.storage.local.set({'googleSearch': "", 'queryString' : "", 'searchEngine' : ""}, function() {});
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });
+ }*/
+
+
+
+
+
+
+
+ //chrome.runtime.sendMessage({cnnLoading: "complete"});
+ /*chrome.storage.local.set({'cnnLoading': "complete"}, function() {
+ console.log('Cnn loading complete..');
+ });*/
+}
-});
-$("div.srg").find("h3 > a").each(function (index) {
- console.log("Title: " + this.text);
- console.log($(this));
- //$(this).append("
My new line text");
- console.log('me done');
- var obj = {};
- if (hrefAdded.indexOf($(this).attr('href')) === -1) {
- obj[this.text] = $(this).attr('href');
- sites.push(obj);
- }
-});
-//bing //ol.b_results
-$("ol#b_results > li.b_algo").find("h2 > a").each(function () {
- console.log("Title: " + this.text);
- var lnk = $(this).attr('href');
- console.log("from: " + JSON.stringify(lnk));
- var obj = {};
- obj[this.text] = $(this).attr('href');
- sites.push(obj);
-});
-//yahoo
-$("div#web").find("h3 > a").each(function () {
- console.log("Title: " + this.text);
- var lnk = $(this).attr('href');
- console.log("from: " + JSON.stringify(lnk));
- var obj = {};
- obj[this.text] = $(this).attr('href');
- sites.push(obj);
-});
+/*
-//youtube //find("ytd-video-renderer")
-$("div#contents").find("h3 > a").each(function (index) {
- console.log("Title: " + this.text);
- console.log($(this));
- //$(this).append("
My new line text");
- console.log('me done');
- var obj = {};
- if (hrefAdded.indexOf($(this).attr('href')) === -1) {
- obj[this.text] = location.origin + $(this).attr('href');
- sites.push(obj);
- }
-
- //div#title-wrapper
-});
-jsonObj['sites'] = sites;
if (location.origin.indexOf('yahoo') > -1) {
- queryString = document.getElementsByName("p")[0].value;
+ refreshObj();
+ queryString = document.getElementsByName("p")[0].value;
+ //yahoo
+ $("div#web").find("h3 > a").each(function () {
+ console.log("Title: " + this.text);
+ var lnk = $(this).attr('href');
+ console.log("from: " + JSON.stringify(lnk));
+ var obj = {};
+ obj[this.text] = $(this).attr('href');
+ sites.push(obj);
+ });
+ jsonObj['yahoo'] = sites;
+ console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });
} else if (location.origin.indexOf('youtube') > -1) {
- queryString = document.getElementsByName("search_query")[0].value;
-} else {
- queryString = document.getElementsByName("q")[0].value;
-}
+ refreshObj();
+ queryString = document.getElementsByName("search_query")[0].value;
+ //youtube //find("ytd-video-renderer")
+ $("div#contents").find("h3 > a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+ if (hrefAdded.indexOf($(this).attr('href')) === -1) {
+ obj[this.text] = location.origin + $(this).attr('href');
+ sites.push(obj);
+ }
+
+ //div#title-wrapper
+ });
+ jsonObj['youtube'] = sites;
+ console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });
+} else if (location.origin.indexOf('cnn') > -1) {
+ queryString = "";
+} else if (location.origin.indexOf('google') > -1) {
+ refreshObj();
+ queryString = document.getElementsByName("q")[0].value;
+
+ //google
+ $("div#rso > div._NId:first").find("div.g").find("div.rc").find("h3 > a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+
+ obj[this.text] = $(this).attr('href');
+ sites.push(obj);
+ hrefAdded.push($(this).attr('href'));
+
+
+ });
+
+ $("div#rso").find("div > g-section-with-header").find("h3").find("a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+ if (hrefAdded.indexOf($(this).attr('href')) === -1) {
+ obj[this.text] = $(this).attr('href');
+ sites.push(obj);
+ }
+
+
+ });
+
+ $("div.srg").find("h3 > a").each(function (index) {
+ console.log("Title: " + this.text);
+ console.log($(this));
+ //$(this).append("
My new line text");
+ console.log('me done');
+ var obj = {};
+ if (hrefAdded.indexOf($(this).attr('href')) === -1) {
+ obj[this.text] = $(this).attr('href');
+ sites.push(obj);
+ }
+
+ });
+ jsonObj['google'] = sites;
+ console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });
+} else if (location.origin.indexOf('bing') > -1){
+ refreshObj();
+ queryString = document.getElementsByName("q")[0].value;
+ //bing //ol.b_results
+
+ $("ol#b_results > li.b_algo").find("h2 > a").each(function () {
+ console.log("Title: " + this.text);
+ var lnk = $(this).attr('href');
+ console.log("from: " + JSON.stringify(lnk));
+ var obj = {};
+ obj[this.text] = $(this).attr('href');
+ sites.push(obj);
+ });
+ jsonObj['bing'] = sites;
+ console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });
+
+}*/
//var queryString = document.getElementsByName("q")[0].value; //"p" for yahoo
/*console.log("jjjjj" + queryString);
console.log(location.pathname);
@@ -96,159 +483,172 @@ console.log(location.pathname);
console.log(location.origin);*/
//var urlquery = '';
//urlquery = location.origin + location.pathname + '?q=' + queryString;
-console.log("Final object...\n" + JSON.stringify(jsonObj));
-chrome.storage.sync.set({'googleSearch': sites, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
- console.log('Settings saved');
-});
+/*if (location.origin.indexOf('cnn') === -1) {
+ jsonObj['cnn'] = sites;
+ console.log("Final object...\n" + JSON.stringify(jsonObj));
+ console.log("queryStr--" + queryString);
+ chrome.storage.local.set({'googleSearch': jsonObj, 'queryString' : queryString, 'searchEngine' : location.origin}, function() {
+ console.log('Settings saved');
+ });
+}*/
var fromGS = {};
$("div.srg").find("h3 > a").click(function () {
- fromGS = $(this).attr('href');
- console.log("from: " + JSON.stringify(fromGS));
-
+ fromGS = $(this).attr('href');
+ console.log("from: " + JSON.stringify(fromGS));
+
});
$('a').click(function(){
- //alert('u r going to ' + $(this).attr('href') + '..jst li dt..');
+
+ //alert('u r going to ' + $(this).attr('href') + '..jst li dt..');
});
-var urlArr = [];
-$('a').each(function(){
- urlArr.push($(this).attr('href'));
- //alert('u r going to ' + $(this).attr('href') + '..jst li dt..');
+var urlArr = [];//[id^="yui_"]
+$('a').each(function(index){
+ //urlArr.push($(this).attr('href'));
+ //alert('u r going to ' + $(this).attr('href') + '..jst li dt..');
+ //console.log('u r going to ' + $(this).attr('href') + '..jst li dt..' );
+ //console.log( $(this));
});
-console.log("showing..\n" + urlArr);
+//console.log("showing..\n" + urlArr);
+
-//chrome.runtime.sendMessage({todo: "show_text"});
chrome.runtime.onMessage.addListener(function(req, sender, sendres){
- console.log("in lsner lll" + location.origin);
- /*if (request.greeting == "hello")*/
+ if (req.exec) {
+ refreshObj();
+ return;
+ }
+
+ //console.log("in lsner lll" + location.origin);
+ /*if (request.greeting == "hello")*/
var url = new URL(location.origin);
- var name = url.hostname.split('.')[1];
- //if (req.highlight) {
- //alert(req.selectedItems);
- console.log("in lsner" + req.selectedItems);
-
- if (name === 'google') {
- highlightTextG(req.selectedItems, req.highlight);
- } else if (name === 'yahoo') {
- highlightTextY(req.selectedItems, req.highlight);
- } else if (name === 'bing') {
- highlightTextB(req.selectedItems, req.highlight);
- } else if (name === 'youtube') {
- highlightTextYT(req.selectedItems, req.highlight);
- }
-
+ var name = url.hostname.split('.')[1];
+ //if (req.highlight) {
+ //alert(req.selectedItems);
+
+ //console.log("in lsner" + req.selectedItems);
+
+ if (name === 'google') {
+ highlightTextG(req.selectedItems, req.highlight);
+ } else if (name === 'yahoo') {
+ highlightTextY(req.selectedItems, req.highlight);
+ } else if (name === 'bing') {
+ highlightTextB(req.selectedItems, req.highlight);
+ } else if (name === 'youtube') {
+ highlightTextYT(req.selectedItems, req.highlight);
+ }
+
});
function highlightTextG(selectedItems, highlight) {
-
- console.log("in highlight");
- //$("div.srg").find("h3 > a").each(function (index) {
- $("div#rso > div._NId:first").find("div.g").find("div.rc").find("h3 > a").each(function (index) {
- //console.log("in first search.." + selectedItems);
- //console.log("in first search.." + $(this).attr('href'));
- if(selectedItems === $(this).attr('href')) {
- if (highlight) {
- //console.log("going to highlight,,,");
- $(this.parentNode.nextSibling).css("background-color","#E2DDDD");
- } else {
- //console.log("going to de highlight,,,");
- $(this.parentNode.nextSibling).css("background-color","");
- }
-
- console.log($(this));
- console.log($(this.parentNode.nextSibling));
- }
- });
-
- $("div#rso").find("div > g-section-with-header").find("h3").find("a").each(function (index) {
- console.log("in 2nd search..");
- if(selectedItems === $(this).attr('href')) {
- if (highlight) {
- $("div#rso").find("div > g-section-with-header").css("background-color","#E2DDDD");
-
- //$(this.parentNode.nextSibling).css("background-color","#E2DDDD");
- } else {
- $("div#rso").find("div > g-section-with-header").css("background-color","");
- }
-
- console.log($(this));
- console.log($("div#rso").find("div > g-section-with-header > g-scrolling-carousel"));
- }
-
- });
- $("div.srg").find("h3 > a").each(function (index) {
- console.log("in 3rd search..");
- if(selectedItems === $(this).attr('href')) {
- if (highlight) {
- $(this.parentNode.nextSibling).css("background-color","#E2DDDD");
- } else {
- $(this.parentNode.nextSibling).css("background-color","");
- }
-
- console.log($(this));
- console.log($(this.parentNode.nextSibling));
- }
- });
+
+ //console.log("in highlight");
+ //$("div.srg").find("h3 > a").each(function (index) {
+ $("div#rso > div._NId:first").find("div.g").find("div.rc").find("h3 > a").each(function (index) {
+ //console.log("in first search.." + selectedItems);
+ //console.log("in first search.." + $(this).attr('href'));
+ if(selectedItems === $(this).attr('href')) {
+ if (highlight) {
+ //console.log("going to highlight,,,");
+ $(this.parentNode.nextSibling).css("background-color","#E2DDDD");
+ } else {
+ //console.log("going to de highlight,,,");
+ $(this.parentNode.nextSibling).css("background-color","");
+ }
+
+ //console.log($(this));
+ //console.log($(this.parentNode.nextSibling));
+ }
+ });
+
+ $("div#rso").find("div > g-section-with-header").find("h3").find("a").each(function (index) {
+ //console.log("in 2nd search..");
+ if(selectedItems === $(this).attr('href')) {
+ if (highlight) {
+ $("div#rso").find("div > g-section-with-header").css("background-color","#E2DDDD");
+
+ //$(this.parentNode.nextSibling).css("background-color","#E2DDDD");
+ } else {
+ $("div#rso").find("div > g-section-with-header").css("background-color","");
+ }
+
+ //console.log($(this));
+ //console.log($("div#rso").find("div > g-section-with-header > g-scrolling-carousel"));
+ }
+
+ });
+ $("div.srg").find("h3 > a").each(function (index) {
+ //console.log("in 3rd search..");
+ if(selectedItems === $(this).attr('href')) {
+ if (highlight) {
+ $(this.parentNode.nextSibling).css("background-color","#E2DDDD");
+ } else {
+ $(this.parentNode.nextSibling).css("background-color","");
+ }
+
+ //console.log($(this));
+ //console.log($(this.parentNode.nextSibling));
+ }
+ });
}
function highlightTextY(selectedItems, highlight) {
-
- console.log("in highlight");
- $("div#web").find("h3 > a").each(function () {
- if(selectedItems === $(this).attr('href')) {
- if (highlight) {
- $(this.parentNode.parentNode.nextSibling.nextSibling).css("background-color","#E2DDDD");
- } else {
- $(this.parentNode.parentNode.nextSibling.nextSibling).css("background-color","");
- }
- console.log($(this));
- console.log($(this.parentNode.parentNode.nextSibling.nextSibling));
- }
-
- });
-
+
+ //console.log("in highlight");
+ $("div#web").find("h3 > a").each(function () {
+ if(selectedItems === $(this).attr('href')) {
+ if (highlight) {
+ $(this.parentNode.parentNode.nextSibling.nextSibling).css("background-color","#E2DDDD");
+ } else {
+ $(this.parentNode.parentNode.nextSibling.nextSibling).css("background-color","");
+ }
+ //console.log($(this));
+ //console.log($(this.parentNode.parentNode.nextSibling.nextSibling));
+ }
+
+ });
+
}
function highlightTextB(selectedItems, highlight) {
-
- console.log("in highlight");
- $("ol#b_results > li.b_algo").find("h2 > a").each(function () {
- if(selectedItems === $(this).attr('href')) {
- console.log($(this));
- console.log($(this.parentNode.nextSibling));
- if (highlight) {
- $(this.parentNode.parentNode).find("div.b_caption").css("background-color","#E2DDDD");
- } else {
- $(this.parentNode.parentNode).find("div.b_caption").css("background-color","");
- }
-
- }
-
- });
-
+
+ //console.log("in highlight");
+ $("ol#b_results > li.b_algo").find("h2 > a").each(function () {
+ if(selectedItems === $(this).attr('href')) {
+ //console.log($(this));
+ //console.log($(this.parentNode.nextSibling));
+ if (highlight) {
+ $(this.parentNode.parentNode).find("div.b_caption").css("background-color","#E2DDDD");
+ } else {
+ $(this.parentNode.parentNode).find("div.b_caption").css("background-color","");
+ }
+
+ }
+
+ });
+
}
function highlightTextYT(selectedItems, highlight) {
-
- console.log("in highlight" + selectedItems);
- $("div#contents").find("ytd-video-renderer").find("h3 > a").each(function (index) {
- console.log($(this).attr('href'));
- if(selectedItems.indexOf($(this).attr('href')) > -1) {
- console.log($(this));
- console.log($(this.parentNode.nextSibling));
- console.log($(this.parentNode.parentNode));
- if (highlight) {
- $(this.parentNode.parentNode).css("background-color","#E2DDDD");
- } else {
- $(this.parentNode.parentNode).css("background-color","");
- }
-
- }
-
- });
-
+
+ //console.log("in highlight" + selectedItems);
+ $("div#contents").find("ytd-video-renderer").find("h3 > a").each(function (index) {
+ //console.log($(this).attr('href'));
+ if(selectedItems.indexOf($(this).attr('href')) > -1) {
+ //console.log($(this));
+ //console.log($(this.parentNode.nextSibling));
+ //console.log($(this.parentNode.parentNode));
+ if (highlight) {
+ $(this.parentNode.parentNode).css("background-color","#E2DDDD");
+ } else {
+ $(this.parentNode.parentNode).css("background-color","");
+ }
+
+ }
+
+ });
+
}
\ No newline at end of file
diff --git a/manifest.json b/manifest.json
index eb31b7c..f3f25c7 100644
--- a/manifest.json
+++ b/manifest.json
@@ -16,7 +16,9 @@
"chrome_style": true
},
"background": {
- "scripts": ["background.js"]
+ "scripts": [
+ "background.js"
+ ]
},
"commands": {
"toggle-feature": {
@@ -32,10 +34,26 @@
}
}
},
- "content_scripts": [{
- "matches": ["https://www.google.com/*"],
- "js": ["jquery-1.8.0.min.js", "content_script.js"]
- }],
+ "content_scripts": [
+ {
+ "matches": [
+ "https://www.google.co.in/*",
+ "https://www.google.com/*",
+ "https://search.yahoo.com/*",
+ "https://www.bing.com/*",
+ "https://www.youtube.com/*",
+ "https://in.yahoo.com/*",
+ "http://www.cnn.com/*",
+ "https://stackoverflow.com/*",
+ "https://www.washingtonpost.com/*"
+ ],
+ "js": [
+ "jquery-1.8.0.min.js",
+ "content_script.js"
+ ],
+ "run_at": "document_end"
+ }
+ ],
"browser_action": {
"default_title": "Open my pages.",
"default_icon": "icons/ic_title_black_24dp_1x.png",
diff --git a/options.html b/options.html
index 9d1cf1c..807ca47 100644
--- a/options.html
+++ b/options.html
@@ -1,26 +1,26 @@
- My Preferences Options
-
+
@@ -30,29 +30,34 @@
-->
diff --git a/options.js b/options.js
index 2cfbb52..2152548 100644
--- a/options.js
+++ b/options.js
@@ -2,338 +2,346 @@
* Created by gdev on 3/18/2017.
*/
-function save_options() {
- var jsonData = document.getElementById('jsonData').value;
- var tabsBackground = document.getElementById('tabsBackground').checked;
+ function save_options() {
+ var jsonData = document.getElementById('jsonData').value;
+ var tabsBackground = document.getElementById('tabsBackground').checked;
var highlightTabs = document.getElementById('highlightTabs').checked;
- var selectAll = document.getElementById('selectAll').checked;
- var timeOut = document.getElementById('timeOut').value;
- var tabToLoad = document.getElementById('tabToLoad').value;
- //var searchSites = document.getElementById('searchSites').value;
-
- if (jsonData.trim() === '') {
- return;
- }
- const dataLen = jsonData.replace(/\s/g, '').length;
- var jsonObj = {};
- document.getElementById("error").innerHTML = "";
- try {
- jsonObj = JSON.parse(jsonData);
- const objLen = JSON.stringify(jsonObj).replace(/\s/g, '').length;
- if (dataLen > objLen) {
- throw new Error("The given json seems to have duplicate keys..Please check and try again");
- }
- validJson(jsonObj);
- var domValues = Object.values(jsonObj);
- domValues.forEach(function(val){
- //alert(val);
- var keys = Object.keys(val);
- //alert(keys);
- if (keys.indexOf('sites') === -1 || keys.indexOf('current') === -1) {
- //alert ("in if");
- throw new Error("The given json seems to have different schema..Please check and try again");
- }
- });
- } catch(err) {
- //alert (err);
- document.getElementById("error").innerHTML = err.message;
- return;
- }
-
- chrome.storage.sync.set({
- jsonData: jsonObj,
- tabsBackground: tabsBackground,
- highlightTabs: highlightTabs,
- selectAll: selectAll,
- timeOut : timeOut,
- tabToLoad : tabToLoad},
- function() {
- // Update status to let user know options were saved.
- var status = document.getElementById('status');
- status.textContent = 'Options saved.';
- setTimeout(function() {
- status.textContent = '';
- }, 750);
- });
-
+ var selectAll = document.getElementById('selectAll').checked;
+ var timeOut = document.getElementById('timeOut').value;
+ var tabToLoad = document.getElementById('tabToLoad').value;
+ //var loadFrom = document.getElementsByName('loadFrom')[0].checked ? document.getElementsByName('loadFrom')[0].value : document.getElementsByName('loadFrom')[1].value;
+ //var searchSites = document.getElementById('searchSites').value;
+alert(tabToLoad);
+ if (jsonData.trim() === '') {
+ return;
+ }
+ const dataLen = jsonData.replace(/\s/g, '').length;
+ var jsonObj = {};
+ document.getElementById("error").innerHTML = "";
+ try {
+ jsonObj = JSON.parse(jsonData);
+ const objLen = JSON.stringify(jsonObj).replace(/\s/g, '').length;
+ if (dataLen > objLen) {
+ throw new Error("The given json seems to have duplicate keys..Please check and try again");
+ }
+ validJson(jsonObj);
+ var domValues = Object.values(jsonObj);
+ domValues.forEach(function(val){
+ //alert(val);
+ var keys = Object.keys(val);
+ //alert(keys);
+ if (keys.indexOf('sites') === -1 || keys.indexOf('current') === -1) {
+ //alert ("in if");
+ throw new Error("The given json seems to have different schema..Please check and try again");
+ }
+ });
+ } catch(err) {
+ //alert (err);
+ document.getElementById("error").innerHTML = err.message;
+ return;
+ }
+
+ chrome.storage.sync.set({
+ jsonData: jsonObj,
+ tabsBackground: tabsBackground,
+ highlightTabs: highlightTabs,
+ selectAll: selectAll,
+ timeOut : timeOut,
+ tabToLoad : tabToLoad},
+ function() {
+ // Update status to let user know options were saved.
+ var status = document.getElementById('status');
+ status.textContent = 'Options saved.';
+ setTimeout(function() {
+ status.textContent = '';
+ }, 750);
+ });
+
}
function checkIfArrayIsUnique(myArray) {
- return myArray.length === new Set(myArray).size;
+ return myArray.length === new Set(myArray).size;
}
function validJson(jsonObj) {
- //alert (jsonObj);
- //alert("all keys-" + Object.values(jsonObj));
- const keys = Object.keys(jsonObj);
- //alert(keys);
- //alert("check" + checkIfArrayIsUnique (keys))
- /*if (!checkIfArrayIsUnique (keys)) {
- alert("The given json seems to have duplicate keys..Please correct and try again");
- //throw new Error("The given json seems to have duplicate keys..Please correct and try again");
- }*/
- //var baseUrl;
- for (var item in jsonObj) {
- //alert(item);
- var current = jsonObj[item]['current'];
- var sites = jsonObj[item]['sites'];
- var linkObj;
-
- for (var index in sites) {
- //alert(JSON.stringify(sites[index]));
- if (Array.isArray(sites[index])) {
- //alert("is array" + JSON.stringify(sites[index][0]));
- sites[index].forEach(function(siteItem){
- //linkObj = siteItem;
- //alert("Link-A-" + JSON.stringify(linkObj));
- if (typeof siteItem === 'object') {
- if (typeof Object.values(siteItem)[0] === 'object') {
- linkObj = Object.values(siteItem)[0].url;
- alert("Link-A--1-" + JSON.stringify(linkObj));
- } else {
- linkObj = Object.values(siteItem)[0];
- alert("Link-A--2-" + JSON.stringify(linkObj));
- }
- }
- if (linkObj.indexOf("http") === -1) {
- linkObj = getBaseURL(current) + linkObj;
- }
- if (doesUrlRepeat(linkObj, jsonObj, current)) {
- return;
- }
- });
- } else if (typeof sites[index] === 'object') {
- if (typeof Object.values(sites[index])[0] === 'object') {
- linkObj = Object.values(sites[index])[0].url;
- alert("Link-B-" + linkObj);
- } else {
- linkObj = Object.values(sites[index])[0];
- alert("Link-C-" + linkObj);
- }
- if (linkObj.indexOf("http") === -1) {
- linkObj = getBaseURL(current) + linkObj;
- }
- if (doesUrlRepeat(linkObj, jsonObj, current)) {
- return;
- }
- } else {
- linkObj = sites[index];
- alert("Link-D-" + linkObj);
- if (linkObj.indexOf("http") === -1) {
- linkObj = getBaseURL(current) + linkObj;
- }
- if (doesUrlRepeat(linkObj, jsonObj, current)) {
- return;
- }
- }
-
-
- /*if (typeof sites[index] === 'object') {
- //alert("is obj-" + JSON.stringify(Object.values(sites[index])));
- if (typeof Object.values(sites[index])[0] === 'object') {
- linkObj = Object.values(sites[index])[0].url;
- } else {
- linkObj = Object.values(sites[index])[0];
- }
- } else {
- linkObj = sites[index];
- }*/
- /*if (doesUrlRepeat(linkObj, jsonObj, current)) {
- return;
- }*/
- }
-
- }
+ //alert (jsonObj);
+ //alert("all keys-" + Object.values(jsonObj));
+ const keys = Object.keys(jsonObj);
+ //alert(keys);
+ //alert("check" + checkIfArrayIsUnique (keys))
+ /*if (!checkIfArrayIsUnique (keys)) {
+ alert("The given json seems to have duplicate keys..Please correct and try again");
+ //throw new Error("The given json seems to have duplicate keys..Please correct and try again");
+ }*/
+ //var baseUrl;
+ for (var item in jsonObj) {
+ //alert(item);
+ var current = jsonObj[item]['current'];
+ var sites = jsonObj[item]['sites'];
+ var linkObj;
+
+ for (var index in sites) {
+ //alert(JSON.stringify(sites[index]));
+ if (Array.isArray(sites[index])) {
+ //alert("is array" + JSON.stringify(sites[index][0]));
+ sites[index].forEach(function(siteItem){
+ //linkObj = siteItem;
+ //alert("Link-A-" + JSON.stringify(linkObj));
+ if (typeof siteItem === 'object') {
+ if (typeof Object.values(siteItem)[0] === 'object') {
+ linkObj = Object.values(siteItem)[0].url;
+ //alert("Link-A--1-" + JSON.stringify(linkObj));
+ } else {
+ linkObj = Object.values(siteItem)[0];
+ //alert("Link-A--2-" + JSON.stringify(linkObj));
+ }
+ }
+ if (linkObj.indexOf("http") === -1) {
+ linkObj = getBaseURL(current) + linkObj;
+ }
+ if (doesUrlRepeat(linkObj, jsonObj, current)) {
+ return;
+ }
+ });
+ } else if (typeof sites[index] === 'object') {
+ if (typeof Object.values(sites[index])[0] === 'object') {
+ linkObj = Object.values(sites[index])[0].url;
+ //alert("Link-B-" + linkObj);
+ } else {
+ linkObj = Object.values(sites[index])[0];
+ //alert("Link-C-" + linkObj);
+ }
+ if (linkObj.indexOf("http") === -1) {
+ linkObj = getBaseURL(current) + linkObj;
+ }
+ if (doesUrlRepeat(linkObj, jsonObj, current)) {
+ return;
+ }
+ } else {
+ linkObj = sites[index];
+ //alert("Link-D-" + linkObj);
+ if (linkObj.indexOf("http") === -1) {
+ linkObj = getBaseURL(current) + linkObj;
+ }
+ if (doesUrlRepeat(linkObj, jsonObj, current)) {
+ return;
+ }
+ }
+
+
+ /*if (typeof sites[index] === 'object') {
+ //alert("is obj-" + JSON.stringify(Object.values(sites[index])));
+ if (typeof Object.values(sites[index])[0] === 'object') {
+ linkObj = Object.values(sites[index])[0].url;
+ } else {
+ linkObj = Object.values(sites[index])[0];
+ }
+ } else {
+ linkObj = sites[index];
+ }*/
+ /*if (doesUrlRepeat(linkObj, jsonObj, current)) {
+ return;
+ }*/
+ }
+
+ }
}
function getBaseURL(current) {
- var baseUrl;
- if (current.indexOf(',') === -1) {
- if (current.indexOf('http://') !== -1 || current.indexOf('https://') !== -1) {
- baseUrl = current;
- } else {
- baseUrl = 'http://' + current;
- }
- }
- return baseUrl;
+ var baseUrl;
+ if (current.indexOf(',') === -1) {
+ if (current.indexOf('http://') !== -1 || current.indexOf('https://') !== -1) {
+ baseUrl = current;
+ } else {
+ baseUrl = 'http://' + current;
+ }
+ }
+ return baseUrl;
}
function doesUrlRepeat(linkObj, jsonObj, current) {
- var firstOccurance = true;
-
- for (var item in jsonObj) {
- var curr = jsonObj[item]['current'];
- var sites = jsonObj[item]['sites'];
-
- /*sites.forEach(function (site) {
- alert ("for each " + JSON.stringify(site));
- });
-
- for (var index in sites) {
- alert ("for loop " + JSON.stringify(sites[sites]));
- }*/
- //alert("current--" + current + "--curr--" + curr);
- //if (curr !== current) {
- for (var index in sites) {
- if (Array.isArray(sites[index])) {
- sites[index].forEach(function(siteItem){
- //linkObj = siteItem;
- //alert("Link-A-" + JSON.stringify(linkObj));
- var url;
- if (typeof siteItem === 'object') {
- if (typeof Object.values(siteItem)[0] === 'object') {
- url = Object.values(siteItem)[0].url;
- //alert("Link-A--1-" + JSON.stringify(linkObj));
- } else {
- url = Object.values(siteItem)[0];
- //alert("Link-A--2-" + JSON.stringify(linkObj));
- }
- }
- if (url.indexOf("http") === -1) {
- url = getBaseURL(curr) + url;
- }
- alert("link--" + linkObj + "\n" + "site--" + url);
- if (linkObj === url) {
- alert("me here AA");
- //alert("The url " + linkObj + "is defined under " + current + " and " + curr + "..Please correct and try again");
- if (!firstOccurance) {
- let mesg;
- if (curr === current) {
- mesg = "The url " + linkObj + " is defined twice under " + current + "..Please correct and try again.";
- } else {
- mesg = "The url " + linkObj + " is defined under " + current + " and " + curr + "..Please correct and try again.";
- }
- throw new Error(mesg);
- return true;
- }
- firstOccurance = false;
-
- }
- });
- } else if (typeof sites[index] === 'object') {
- var url;
- if (typeof Object.values(sites[index])[0] === 'object') {
- url = Object.values(sites[index])[0].url;
- } else {
- url = Object.values(sites[index])[0];
- }
- if (url.indexOf("http") === -1) {
- url = getBaseURL(curr) + url;
- }
- alert("link--" + linkObj + "\n" + "site--" + url);
-
- if (linkObj === url) {
- alert("me here A");
- //alert("The url " + linkObj + "is defined under " + current + " and " + curr + "..Please correct and try again");
- if (!firstOccurance) {
- let mesg;
- if (curr === current) {
- mesg = "The url " + linkObj + " is defined twice under " + current + "..Please correct and try again.";
- } else {
- mesg = "The url " + linkObj + " is defined under " + current + " and " + curr + "..Please correct and try again.";
- }
- throw new Error(mesg);
- return true;
- }
- firstOccurance = false;
- }
-
- } else {
- var url = sites[index];
- if (url.indexOf("http") === -1) {
- url = getBaseURL(curr) + url;
- }
- alert("link--" + linkObj + "\n" + "site--" + url);
-
- if (linkObj === url) {
- alert("me here B");
- // alert("The url " + linkObj + "is defined under " + current + " and " + curr + "..Please correct and try again");
- if (!firstOccurance) {
- let mesg;
- if (curr === current) {
- mesg = "The url " + linkObj + " is defined twice under " + current + "..Please correct and try again.";
- } else {
- mesg = "The url " + linkObj + " is defined under " + current + " and " + curr + "..Please correct and try again.";
- }
- throw new Error(mesg);
- return true;
- }
- firstOccurance = false;
- }
- }
- }
- //}
- }
- return false;
+ var firstOccurance = true;
+
+ for (var item in jsonObj) {
+ var curr = jsonObj[item]['current'];
+ var sites = jsonObj[item]['sites'];
+
+ /*sites.forEach(function (site) {
+ alert ("for each " + JSON.stringify(site));
+ });
+
+ for (var index in sites) {
+ alert ("for loop " + JSON.stringify(sites[sites]));
+ }*/
+ //alert("current--" + current + "--curr--" + curr);
+ //if (curr !== current) {
+ for (var index in sites) {
+ if (Array.isArray(sites[index])) {
+ sites[index].forEach(function(siteItem){
+ //linkObj = siteItem;
+ //alert("Link-A-" + JSON.stringify(linkObj));
+ var url;
+ if (typeof siteItem === 'object') {
+ if (typeof Object.values(siteItem)[0] === 'object') {
+ url = Object.values(siteItem)[0].url;
+ //alert("Link-A--1-" + JSON.stringify(linkObj));
+ } else {
+ url = Object.values(siteItem)[0];
+ //alert("Link-A--2-" + JSON.stringify(linkObj));
+ }
+ }
+ if (url.indexOf("http") === -1) {
+ url = getBaseURL(curr) + url;
+ }
+ //alert("link--" + linkObj + "\n" + "site--" + url);
+ if (linkObj === url) {
+ //alert("me here AA");
+ //alert("The url " + linkObj + "is defined under " + current + " and " + curr + "..Please correct and try again");
+ if (!firstOccurance) {
+ let mesg;
+ if (curr === current) {
+ mesg = "The url " + linkObj + " is defined twice under " + current + "..Please correct and try again.";
+ } else {
+ mesg = "The url " + linkObj + " is defined under " + current + " and " + curr + "..Please correct and try again.";
+ }
+ throw new Error(mesg);
+ return true;
+ }
+ firstOccurance = false;
+
+ }
+ });
+ } else if (typeof sites[index] === 'object') {
+ var url;
+ if (typeof Object.values(sites[index])[0] === 'object') {
+ url = Object.values(sites[index])[0].url;
+ } else {
+ url = Object.values(sites[index])[0];
+ }
+ if (url.indexOf("http") === -1) {
+ url = getBaseURL(curr) + url;
+ }
+ //alert("link--" + linkObj + "\n" + "site--" + url);
+
+ if (linkObj === url) {
+ //alert("me here A");
+ //alert("The url " + linkObj + "is defined under " + current + " and " + curr + "..Please correct and try again");
+ if (!firstOccurance) {
+ let mesg;
+ if (curr === current) {
+ mesg = "The url " + linkObj + " is defined twice under " + current + "..Please correct and try again.";
+ } else {
+ mesg = "The url " + linkObj + " is defined under " + current + " and " + curr + "..Please correct and try again.";
+ }
+ throw new Error(mesg);
+ return true;
+ }
+ firstOccurance = false;
+ }
+
+ } else {
+ var url = sites[index];
+ if (url.indexOf("http") === -1) {
+ url = getBaseURL(curr) + url;
+ }
+ //alert("link--" + linkObj + "\n" + "site--" + url);
+
+ if (linkObj === url) {
+ //alert("me here B");
+ // alert("The url " + linkObj + "is defined under " + current + " and " + curr + "..Please correct and try again");
+ if (!firstOccurance) {
+ let mesg;
+ if (curr === current) {
+ mesg = "The url " + linkObj + " is defined twice under " + current + "..Please correct and try again.";
+ } else {
+ mesg = "The url " + linkObj + " is defined under " + current + " and " + curr + "..Please correct and try again.";
+ }
+ throw new Error(mesg);
+ return true;
+ }
+ firstOccurance = false;
+ }
+ }
+ }
+ //}
+ }
+ return false;
}
// Restores tabsBackground state using the preferences
// stored in chrome.storage.
function restore_options() {
chrome.storage.sync.get( "jsonData", function(items) {
- var content = document.getElementById('jsonData');
- var text = document.createTextNode(JSON.stringify(items.jsonData, null, "\t"));
- //alert(library.json.prettyPrint(JSON.stringify(items.jsonData, null, "\t")));
- //var text = document.createTextNode(library.json.prettyPrint(JSON.stringify(items.jsonData, null, "\t")));
- //var text = document.createTextNode(library.json.prettyPrint(account));
-
- content.appendChild(text);
-
+ var content = document.getElementById('jsonData');
+ var text = document.createTextNode(JSON.stringify(items.jsonData, null, "\t"));
+ //alert(library.json.prettyPrint(JSON.stringify(items.jsonData, null, "\t")));
+ //var text = document.createTextNode(library.json.prettyPrint(JSON.stringify(items.jsonData, null, "\t")));
+ //var text = document.createTextNode(library.json.prettyPrint(account));
+
+ content.appendChild(text);
+
});
- chrome.storage.sync.get({
+ chrome.storage.sync.get({
tabsBackground: true,
highlightTabs: true,
- selectAll: true,
- timeOut: 30,
- tabToLoad : 2
+ selectAll: true,
+ timeOut: 30,
+ tabToLoad : 2
}, function(items) {
document.getElementById('tabsBackground').checked = items.tabsBackground;
document.getElementById('highlightTabs').checked = items.highlightTabs;
- document.getElementById('selectAll').checked = items.selectAll;
- document.getElementById('timeOut').value = items.timeOut;
- document.getElementById('tabToLoad').value = items.tabToLoad;
- //document.getElementById('searchSites').value = items.searchSites;
-
-
+ document.getElementById('selectAll').checked = items.selectAll;
+ document.getElementById('timeOut').value = items.timeOut;
+ document.getElementById('tabToLoad').value = items.tabToLoad;
+ /*alert(items.loadFrom);
+ if (items.loadFrom === 'config'){
+ document.getElementsByName('loadFrom')[0].checked = true;
+ } else {
+ document.getElementsByName('loadFrom')[1].checked = true;
+ } */
+
+ //document.getElementById('searchSites').value = items.searchSites;
+
+
});
}
function replacer(key, value) {
- alert(JSON.stringify(key));
- alert(JSON.stringify(value));
- return "" + value + "";
+ alert(JSON.stringify(key));
+ alert(JSON.stringify(value));
+ return "" + value + "";
}
var account = { active: true, codes: [48348, 28923, 39080], city: "London" };
if (!library)
- var library = {};
+ var library = {};
library.json = {
- replacer: function(match, pIndent, pKey, pVal, pEnd) {
- var key = '';
- var val = '';
- var str = '';
- var r = pIndent || '';
- if (pKey)
- r = r + key + pKey.replace(/[": ]/g, '') + ': ';
- if (pVal)
- r = r + (pVal[0] == '"' ? str : val) + pVal + '';
- return r + (pEnd || '');
- },
- prettyPrint: function(obj) {
- var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg;
- return JSON.stringify(obj, null, 3)
- .replace(/&/g, '&').replace(/\\"/g, '"')
- .replace(//g, '>')
- .replace(jsonLine, library.json.replacer);
- }
-};
-
+ replacer: function(match, pIndent, pKey, pVal, pEnd) {
+ var key = '';
+ var val = '';
+ var str = '';
+ var r = pIndent || '';
+ if (pKey)
+ r = r + key + pKey.replace(/[": ]/g, '') + ': ';
+ if (pVal)
+ r = r + (pVal[0] == '"' ? str : val) + pVal + '';
+ return r + (pEnd || '');
+ },
+ prettyPrint: function(obj) {
+ var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg;
+ return JSON.stringify(obj, null, 3)
+ .replace(/&/g, '&').replace(/\\"/g, '"')
+ .replace(//g, '>')
+ .replace(jsonLine, library.json.replacer);
+ }
+ };
+
function cancel_options () {
- window.close();
+ window.close();
}
-
-
+
+
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save_options);
document.getElementById('cancel').addEventListener('click', cancel_options);
@@ -347,18 +355,18 @@ function save_options() {
var urls={};
urls[prefDomain] = [prefUrl];
-
+
chrome.storage.sync.get( "preferedPages", function(items) {
alert("items" + JSON.stringify(items));
var origObj = items.preferedPages;
alert("before" + JSON.stringify(origObj));
-
+
if (origObj[prefDomain]) {
origObj[prefDomain].push(prefUrl);
} else {
origObj[prefDomain] = [prefUrl];
}
-
+
urls = origObj;
alert("final--" + JSON.stringify(urls));
chrome.storage.sync.set({preferedPages: origObj}, function() {
@@ -387,22 +395,22 @@ function restore_options() {
var tr = document.createElement("TR");
tr.setAttribute("id", "heading");
table.appendChild(tr);
-
+
var col1 = document.createElement("TD");
var cell1 = document.createTextNode("Domain");
col1.appendChild(cell1);
tr.appendChild(col1);
-
+
var col2 = document.createElement("TD");
var cell2 = document.createTextNode("Preferred URL");
col2.appendChild(cell2);
tr.appendChild(col2);
-
+
var col3 = document.createElement("TD");
var cell3 = document.createTextNode("Delete");
col3.appendChild(cell3);
tr.appendChild(col3);
-
+
table.style.border = "thin solid #000000";
//tr.style.border = "thin solid #000000";
col1.style.border = "thin solid #000000";
@@ -439,17 +447,17 @@ function restore_options() {
dataRow.appendChild(col3);
rowIndex++;
});
-
- });
+
+ });
//content.appendChild(text);
-
+
});
}
function delete_selected_options() {
alert("in delete");
var allChBx = document.getElementsByName("delete_chkbx");
-
+
chrome.storage.sync.get( "preferedPages", function(items) {
alert("items" + JSON.stringify(items));
var origObj = items.preferedPages;
@@ -489,8 +497,8 @@ function delete_selected_options() {
//items.preferedPages.prefDomain.push(prefUrl);
//alert("after changing" + items.preferedPages.prefDomain.push(prefUrl));
});
-
-
+
+
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save_options);
diff --git a/popup.html b/popup.html
index 2f3ec76..7aa8f14 100644
--- a/popup.html
+++ b/popup.html
@@ -6,53 +6,89 @@
-->
- Select pages to view
-
-
-
+ Select pages to view
+
+
+
- Advertisement
+ Advertisement
-
-
-
-
-
-
-
Open in Same Tab
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
Open in Same Tab
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/popup.js b/popup.js
index 7b18918..e754918 100644
--- a/popup.js
+++ b/popup.js
@@ -15,9 +15,12 @@ var searchSites;
var searchEngine;
var baseUrl;
var anonymus;
-var options = ['tabsBackground', 'highlightTabs', 'jsonData', 'selectAll', 'loading', 'googleSearch', 'parentUrl', 'queryString', 'searchEngine', 'anonymus'];
-var google = ['www.google.co.in', 'www.google.com', 'search.yahoo.com', 'www.bing.com', 'www.youtube.com'];
-
+var newtab;
+var loadFrom;
+var showTree;
+var options = ['tabsBackground', 'highlightTabs', 'jsonData', 'selectAll', 'loading', 'googleSearch', 'parentUrl', 'queryString', 'anonymus']; //'searchEngine',, 'loadFrom'
+//var readPage = ['www.google.co.in', 'www.google.com', 'search.yahoo.com', 'www.bing.com', 'www.youtube.com', 'edition.cnn.com'];
+var readPage = ['google', 'search.yahoo', 'bing', 'youtube', 'cnn', 'stackoverflow', 'washingtonpost'];
chrome.storage.sync.get( options, function(items) {
@@ -27,12 +30,21 @@ chrome.storage.sync.get( options, function(items) {
selectAll = items.selectAll;
loading = items.loading;
console.log("in sync get" + loading);
- googleSearch = items.googleSearch;
+ //googleSearch = items.googleSearch;
+ //console.log("in sync get search--" + googleSearch);
parentUrl = items.parentUrl;
- queryString = items.queryString;
+ //queryString = items.queryString;
//searchSites = items.searchSites;
- searchEngine = items.searchEngine;
+ //searchEngine = items.searchEngine;
anonymus = items.anonymus;
+ //loadFrom = items.loadFrom;
+});
+
+chrome.storage.local.get( options, function(items) {
+ googleSearch = items.googleSearch;
+ console.log("in sync get search--" + googleSearch);
+ queryString = items.queryString;
+ // searchEngine = items.searchEngine;
});
function closeWindow (e) {
@@ -58,49 +70,79 @@ function closeWindow (e) {
function clickHandler(e) {
//loading = true;
- const allUrls = document.getElementsByName("link");
+ document.getElementById("openbtn").disabled = true;
+
+ //
const urlsToOpen = [];
const tabToHilite = [currentTab.index];
const openAt = currentTab.index + 1;
- var anonymus;
+ var anonymusValues;
try {
- if (allUrls.length === 0) {
- console.log("link undefined " + allUrls);
- anonymus = document.getElementById("anonymus").value;
- const urls = anonymus.split('\n');
- urls.forEach(function (url) {
- if (url.startsWith('http') || url.startsWith('https')) {
- urlsToOpen.push(url);
- } else {
- throw new Error("The url " + url + " does not have protocol " + "..Please specify and try again");
- //return ;
- }
+ if(showTree) {
+ const detNodes = document.getElementsByName("detail");
+ console.log(detNodes);
+ /*this.childNodes[0].childNodes[1]
+var allLi = obj.parentNode.nextSibling.childNodes;
+allLi.forEach(function(li){
+ //console.log(li);
+ if (set) {
+ console.log(li);
+ li.childNodes[0]*/
+ detNodes.forEach(function (detNode){
+ if (detNode.open) {
+ var allLi = detNode.childNodes[1].childNodes;
+ allLi.forEach(function(li){
+ console.log(li.childNodes[1].href);
+ if (li.childNodes[0].checked) {
+ urlsToOpen.push(li.childNodes[1].href);
+ }
+ });
+ }
});
+
} else {
- allUrls.forEach (function (url) {
- console.log(url);
- if (url.checked) {
- urlsToOpen.push(url.value);
- console.log("came till here");
- /*chrome.tabs.create({url: url.value, active : !tabsBackground, index: openAt}, function(tab){
- tabToHilite.push(tab.index);
- openAt ++;
- });*/
- var itemValue = url.value;
- if (searchPage) {
- chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {highlight:false, selectedItems: itemValue}, function(response) {
- console.log(response.farewell);
- });
- });
+ const allUrls = document.getElementsByName("link");
+ //console.log(allUrls);
+ if (allUrls.length === 0) {
+ console.log("link undefined " + allUrls);
+ anonymusValues = document.getElementById("anonymus").value;
+ const urls = anonymusValues.split('\n');
+ urls.forEach(function (url) {
+ if (url.startsWith('http') || url.startsWith('https')) {
+ urlsToOpen.push(url);
+ } else {
+ throw new Error("The url " + url + " does not have protocol " + "..Please specify and try again");
+ //return ;
}
- } else {
- console.log("came till here in else");
- }
- });
+ });
+ } else {
+ allUrls.forEach (function (url) {
+ console.log(url);
+ if (url.checked) {
+ urlsToOpen.push(url.value);
+ console.log("came till here");
+ /*chrome.tabs.create({url: url.value, active : !tabsBackground, index: openAt}, function(tab){
+ tabToHilite.push(tab.index);
+ openAt ++;
+ });*/
+ var itemValue = url.value;
+ if (searchPage) {
+ chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {highlight:false, selectedItems: itemValue}, function(response) {
+ console.log(response.farewell);
+ });
+ });
+ }
+
+ } else {
+ console.log("came till here in else");
+ }
+ });
+ }
}
+
} catch (err) {
document.getElementById("error").innerHTML = err.message;
return;
@@ -111,29 +153,30 @@ function clickHandler(e) {
/*if (highlightTabs) {
chrome.tabs.highlight({tabs: tabToHilite}, function(){});
}*/
+
chrome.storage.sync.set({urlsToOpen: [], currTab : "", invokedWindow : "", opnSmeTb : "", loading: false}, function() {});
var opnSmeTab = document.getElementById("sametabChkbx").checked;
- chrome.storage.sync.set({urlsToOpen: urlsToOpen, currTab: currentTab, invokedWindow: invokedWindow, opnSmeTb: opnSmeTab, loading: true, anonymus : anonymus}, function() {
+ chrome.storage.sync.set({urlsToOpen: urlsToOpen, currTab: currentTab, invokedWindow: invokedWindow, opnSmeTb: opnSmeTab, loading: true, anonymus : anonymusValues}, function() {
if (chrome.runtime.error) {
console.log("Runtime error.");
}
});
- window.close();
+ //window.close();
}
function selectall () {
const allUrls = document.getElementsByName("link");
- var parentNode;
+ var parentNode = allUrls[0].parentNode.parentNode.childNodes;
if (document.getElementById('selectall').checked) {
allUrls.forEach (function (url) {
if (currentUrl !== url.value) {
url.checked = true;
url.nextSibling.nextSibling.style.fontWeight = "bold";
document.getElementById("openbtn").disabled = false;
- document.getElementById("sametab").hidden = true;
+ document.getElementById("sametab").disabled = true;
document.getElementById("sametabChkbx").checked = false;
}
- parentNode = url.parentNode.parentNode.childNodes;
+
console.log("kkkkkk-" + url.value);
var itemValue = url.value;
if (searchPage) {
@@ -145,6 +188,8 @@ function selectall () {
}
});
+
+ /*
var howmany = document.getElementById("howmany");
var selNums = howManyChecked(parentNode);
howmany.textContent = selNums + " selected.";
@@ -160,14 +205,14 @@ function selectall () {
document.getElementsByName('site')[0].disabled = true;
document.getElementsByName('site')[1].disabled = true;
document.getElementsByName('site')[2].disabled = true;
- }
+ }*/
} else {
allUrls.forEach (function (url) {
url.checked = false;
console.log(url.parentNode);
url.nextSibling.nextSibling.style.fontWeight = "normal";
document.getElementById("openbtn").disabled = true;
- document.getElementById("sametab").hidden = true;
+ document.getElementById("sametab").disabled = true;
document.getElementById("sametabChkbx").checked = false;
var itemValue = url.value;
if (searchPage) {
@@ -179,7 +224,7 @@ function selectall () {
}
});
- var howmany = document.getElementById("howmany");
+ /*var howmany = document.getElementById("howmany");
howmany.textContent = "0 selected.";
if (document.getElementById('searchAgain')) {
document.getElementById('searchAgain').disabled = false;
@@ -191,11 +236,11 @@ function selectall () {
}
document.getElementsByName('site')[0].disabled = false;
document.getElementsByName('site')[1].disabled = false;
- document.getElementsByName('site')[2].disabled = false;
+ document.getElementsByName('site')[2].disabled = false; */
//document.getElementById('searchAgain').disabled = false;
}
-
+ changeSelection(parentNode);
}
function linkClick () {
@@ -230,10 +275,10 @@ function chkBoxClick (ele) {
});
if (none) {
console.log("only one");
- document.getElementById("sametab").hidden = false;
+ document.getElementById("sametab").disabled = false;
document.getElementById("sametabChkbx").checked = true;
} else {
- document.getElementById("sametab").hidden = true;
+ document.getElementById("sametab").disabled = true;
document.getElementById("sametabChkbx").checked = false;
}
@@ -261,39 +306,48 @@ function chkBoxClick (ele) {
document.getElementById('searchbtn').disabled = true;
document.getElementById('searchTextBox').disabled = true;
}
- document.getElementsByName('site')[0].disabled = true;
- document.getElementsByName('site')[1].disabled = true;
- document.getElementsByName('site')[2].disabled = true;
+ if (document.getElementsByName('site')[0]) {
+ document.getElementsByName('site')[0].disabled = true;
+ document.getElementsByName('site')[1].disabled = true;
+ document.getElementsByName('site')[2].disabled = true;
+ }
//document.getElementById('searchAgain').disabled = true;
} else {
this.labels[0].style.fontWeight="normal";
document.getElementById("openbtn").disabled = true;
- document.getElementById("sametab").hidden = true;
+ document.getElementById("sametab").disabled = true;
document.getElementById("sametabChkbx").checked = false;
if (atleastOneChecked(this.parentNode.parentNode.childNodes)) {
document.getElementById("openbtn").disabled = false;
}
if (moreThanOneChecked(this.parentNode.parentNode.childNodes)) {
console.log("more than one checked");
- document.getElementById("sametab").hidden = true;
+ document.getElementById("sametab").disabled = true;
document.getElementById("sametabChkbx").checked = false;
} else {
- document.getElementById("sametab").hidden = false;
+ document.getElementById("sametab").disabled = false;
document.getElementById("sametabChkbx").checked = true;
}
- var itemValue = this.value;
+ var selItems = this.value;
if (searchPage) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {highlight:false, selectedItems: itemValue}, function(response) {
+ chrome.tabs.sendMessage(tabs[0].id, {highlight:false, selectedItems: selItems}, function(response) {
console.log(response.farewell);
});
});
}
}
+ changeSelection(this.parentNode.parentNode.childNodes);
+ //console.log("len--" + this.parentNode.parentNode.childNodes.length);
+}
+
+function changeSelection (listNodes) {
+
var howmany = document.getElementById("howmany");
- var selNums = howManyChecked(this.parentNode.parentNode.childNodes);
+ var selNums = howManyChecked(listNodes);
+ console.log(listNodes.length + "***" + selNums);
howmany.textContent = selNums + " selected.";
if (selNums === 0) {
if (document.getElementById('searchAgain')) {
@@ -304,9 +358,12 @@ function chkBoxClick (ele) {
document.getElementById('searchbtn').disabled = false;
document.getElementById('searchTextBox').disabled = false;
}
- document.getElementsByName('site')[0].disabled = false;
- document.getElementsByName('site')[1].disabled = false;
- document.getElementsByName('site')[2].disabled = false;
+ if (document.getElementsByName('site')[0]) {
+ document.getElementsByName('site')[0].disabled = false;
+ document.getElementsByName('site')[1].disabled = false;
+ document.getElementsByName('site')[2].disabled = false;
+ }
+
//document.getElementById('searchAgain').disabled = false;
} else {
if (document.getElementById('searchAgain')) {
@@ -317,18 +374,20 @@ function chkBoxClick (ele) {
document.getElementById('searchbtn').disabled = true;
document.getElementById('searchTextBox').disabled = true;
}
- document.getElementsByName('site')[0].disabled = true;
- document.getElementsByName('site')[1].disabled = true;
- document.getElementsByName('site')[2].disabled = true;
+ if (document.getElementsByName('site')[0]) {
+ document.getElementsByName('site')[0].disabled = true;
+ document.getElementsByName('site')[1].disabled = true;
+ document.getElementsByName('site')[2].disabled = true;
+ }
//document.getElementById('searchAgain').disabled = true;
}
- if (selNums < this.parentNode.parentNode.childNodes.length) {
+ console.log("selected--" + selNums + "--list len--" + listNodes.length);
+ if (selNums < listNodes.length) {
document.getElementById('selectall').checked = false;
}
- if (selNums === this.parentNode.parentNode.childNodes.length) {
+ if (selNums === listNodes.length) {
document.getElementById('selectall').checked = true;
}
- //console.log("len--" + this.parentNode.parentNode.childNodes.length);
}
function howManyChecked(liNodes) {
@@ -382,7 +441,22 @@ function addUrl() {
var name = hostNameArray[1];//domain.split('.')[0];
//var jsonObj = {};*/
var name = getDomainName(tab.url);
-
+ let textBox = document.getElementById('anonymus');
+ var newObjArr = [];
+ if (textBox) {
+ console.log(textBox.value);
+ if (textBox.value !== '') {
+ var values = textBox.value.split('\n');
+ values.forEach(function (value){
+ var obj = {};
+ var key = getKeyFromURL(value.split('/'));
+ obj[key] = value;
+ newObjArr.push(obj);
+ });
+ }
+ //var newURLs = textBox.value ? textBox.value.replace('\n', ',') : '';
+ console.log(newObjArr);
+ }
chrome.storage.sync.get( "jsonData", function(items) {
console.log(JSON.stringify(items));
var origObj = items.jsonData;
@@ -393,26 +467,37 @@ function addUrl() {
}*/
//var prefForDom = origObj[fullDomain] || origObj[name];
var prefForDom = getPreferences(fullDomain, name, origObj);
- console.log(prefForDom + " --- llllllll");
+ console.log("==" + prefForDom + "--- llllllll");
var newEntryObj = {};
var path = url.pathname.split('/');
- if (path.length === 0) {
- newEntryObj[name] = currentUrl;
+ var key = getKeyFromURL(path);
+ /*if (path.length === 0) {
+ //newEntryObj[name] = currentUrl;
+ key = name;
} else {
if (path[path.length-1].indexOf('=') === -1) {
- newEntryObj[path[path.length-1]] = currentUrl;
+ //newEntryObj[path[path.length-1]] = currentUrl;
+ key = path[path.length-1];
} else {
- newEntryObj[path[1]] = currentUrl;
+ //newEntryObj[path[1]] = currentUrl;
+ key = path[1];
}
}
-
+ if (key === '') {
+ key = 'Home';
+ }*/
+ newEntryObj[key] = currentUrl;
+ console.log(newEntryObj);
+ //if (newObjArr.length > 0) {
+ newObjArr.push(newEntryObj);
+ //}
//path[path.length];
//var nameKey = url.pathname.endsWith('/') ? url.pathname[url.pathname.length - 2] : url.pathname[url.pathname.length - 1];
console.log(path.length);
console.log("dom-" + path + "--" + path[path.length-1]);
-
if (prefForDom) {
+ console.log('in if');
if (Array.isArray(prefForDom)) {
prefForDom.push(newEntryObj);
} else {
@@ -428,11 +513,12 @@ function addUrl() {
} else {
+ console.log('in else');
//origObj[name] = [currentUrl];
var newObj = {};
newObj["current"] = name;
newObj["description"] = name;
- newObj["sites"] = [newEntryObj];
+ newObj["sites"] = newObjArr; //[newEntryObj];
origObj[name] = newObj;
}
//origObj[name] = [currentUrl];
@@ -453,6 +539,27 @@ function addUrl() {
});
}
+function getKeyFromURL (path) {
+ //var path = url.pathname.split('/');
+ console.log(path);
+ var key;
+ if (path.length === 0) {
+ //newEntryObj[name] = currentUrl;
+ key = name;
+ } else {
+ if (path[path.length-1].indexOf('=') === -1) {
+ //newEntryObj[path[path.length-1]] = currentUrl;
+ key = path[path.length-1];
+ } else {
+ //newEntryObj[path[1]] = currentUrl;
+ key = path[1];
+ }
+ }
+ if (key === '') {
+ key = 'Home';
+ }
+ return key;
+}
function searchAgain () {
var urlSite = '';
@@ -548,7 +655,7 @@ function sortListDir() {
} else {
/*If no switching has been done AND the direction is "asc",
set the direction to "desc" and run the while loop again.*/
- if (switchcount == 0 && dir == "asc") {
+ if (switchcount === 0 && dir == "asc") {
dir = "desc";
switching = true;
@@ -591,8 +698,17 @@ function searchInSite (queryString) {
}
window.close();
}
-document.addEventListener('beforeunload', function (event) {
+
+
+
+document.addEventListener('onbeforeunload', function (event) {
console.log("unload..");
+ //localStorage.removeItem(key);
+ //window.localStorage.removeItem("googleSearch");
+ /*window.onbeforeunload = function() {
+
+ return '';
+ };*/
const allUrls = document.getElementsByName("link");
var parentNode;
allUrls.forEach (function (url) {
@@ -709,18 +825,39 @@ function saveSelection() {
});
});
});
+
+ /*const allUrls = document.getElementsByName("link");
+ var parentNode = allUrls[0].parentNode.parentNode.childNodes;
+ changeSelection(parentNode);*/
}
function editTextArea () {
let txtAreaContent = this.value;
console.log("in txt are" + txtAreaContent);
if (txtAreaContent === '') {
- document.getElementById('openbtn').hidden = "hidden";
+ document.getElementById('openbtn').disabled = true;
document.getElementById("error").innerHTML = "";
} else {
- document.getElementById('openbtn').hidden = "";
+ document.getElementById('openbtn').disabled = false;
}
}
+
+function findInArray(array, item) {
+ //var found = false;
+ for (var x = 0; x < array.length; x ++) {
+ console.log(array[x] + " ---" + item);
+ console.log(item.indexOf(array[x]));
+
+ if (item.indexOf(array[x]) > -1) {
+ //found = true;
+ //return found;
+
+ return true;
+ }
+ }
+ return false;
+}
+
document.addEventListener('DOMContentLoaded', function () {
/* var bgPage = chrome.extension.getBackgroundPage();
console.log("before");
@@ -735,216 +872,360 @@ document.addEventListener('DOMContentLoaded', function () {
//document.getElementById('searchAgain').addEventListener('click', searchAgain);
document.getElementById('sortListDir').addEventListener('click', sortListDir);
//document.getElementById('searchbtn').addEventListener('click', searchInSite);
- onclick="()"
+ //onclick="()";
console.log("lod--" + loading);
console.log("jsondata--" + jsonData);
var content = document.getElementById('content');
//chrome.storage.sync.set({loading: false}, function() {});
//chrome.storage.sync.set({parentUrl: ""}, function() {});
- getCurrentTabUrl(function(tab) {
- currentUrl = tab.url;
- if (currentUrl === "chrome://newtab/") {
- window.close();
- return;
- }
+ window.addEventListener ("load", popupMain, false);
- var url = new URL(tab.url);
- var fullDomain = url.hostname;
- console.log("dom-" + fullDomain);
- var hostNameArray = fullDomain.split(".");
-
- console.log(hostNameArray.length);
- //var domain = getDomain(currentUrl);
- var name = getDomainName(tab.url); //hostNameArray[1]; //domain.split('.')[0];
- console.log("currentUrl --" + currentUrl);
- console.log("name --" + name);
- console.log("lod--" + loading);
- console.log("jsondata--" + jsonData);
- if (loading) {
- window.close();
- return;
- }
- var prefForDom;
- console.log("test--" + isFromSearch(currentUrl));
- if (google.indexOf (url.hostname) > -1 || isFromSearch(currentUrl)) {
- console.log("inside google");
- if (googleSearch === undefined || Object.keys(googleSearch).length === 0) {
- //console.log("google seach list is empty");
- //window.close();
- //return;
- var text = document.createTextNode("No previous search results found. Please try a fresh search.");
- document.getElementById('openbtn').hidden = "hidden";
- //document.getElementById('cancelbtn').hidden = "hidden";
- document.getElementById('selectall').hidden = "hidden";
- document.getElementById('selectall').nextSibling.nodeValue = "";
- document.getElementById('sortListDir').hidden = "hidden";
- console.log(document.getElementById('sortListDir').nextSibling.nodeValue + "fffk");
-
- document.getElementById('sortListDir').nextSibling.nodeValue = "";
- //document.getElementById('searchAgain').hidden = "hidden";
- //document.getElementById('addbtn').hidden = "";
- content.appendChild(text);
- return;
- }
- console.log("Check1 " + JSON.stringify(googleSearch));
- prefForDom = googleSearch;
- console.log("check2-" + prefForDom + "-");
- document.getElementById('addbtn').hidden = "hidden";
- document.getElementById('savebtn').hidden = "hidden";
- //document.getElementById('searchbtn').hidden = "hidden";
- //document.getElementById('searchText').hidden = "hidden";
- content.style.width = "600px";
- document.getElementById('body').style.width = "603px";
- searchPage = true;
- if (googleSearch === "") {
- console.log("Search list is empty");
- }
- var engineName = getDomainName(searchEngine); //new URL(searchEngine).hostname.split('.')[1];//domain.split('.')[0];
- var div = document.createElement('div');
- div.setAttribute("align", "center");
- var engineLogo = document.createElement("IMG");
- console.log("get favicon--" + searchEngine);
- engineLogo.setAttribute("src", 'chrome://favicon/'+ searchEngine);
- //engineLogo.setAttribute("src", '/icons/' + engineName + '.ico');
- engineLogo.style.cssFloat = 'middle';
- div.appendChild(engineLogo);
- //var domain = getDomain(searchEngine);
- //var engineName = new URL(searchEngine).hostname.split('.')[1];//domain.split('.')[0];
-
- var searchEngineTxt = document.createTextNode(" " + engineName + " results.");
- div.appendChild(searchEngineTxt);
- content.appendChild(div);
- }
+});
- if (prefForDom === undefined) {
- prefForDom = getPreferences(url.hostname, name); //jsonData[url.hostname] || jsonData[name];
- //content.style.width = "200px";
- //ocument.getElementById('searchAgain').hidden = "hidden";
- searchPage = false;
- }
+function popupMain(evt) {
+ chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {exec:true}, function(response) {
+ getCurrentTabUrl(function(tab) {
+ currentUrl = tab.url;
+ if (currentUrl === "chrome://newtab/") {
+ //window.close();
+ //return;
+ newtab = true;
+ } else {
+ newtab = false;
+ }
+ var url = new URL(tab.url);
+ var fullDomain = url.hostname;
+ console.log("dom-" + fullDomain);
+ var hostNameArray = fullDomain.split(".");
+
+ console.log(hostNameArray.length);
+ //var domain = getDomain(currentUrl);
+ var name = getDomainName(tab.url); //hostNameArray[1]; //domain.split('.')[0];
+ console.log("currentUrl --" + currentUrl);
+ console.log("name --" + name);
+ console.log("lod--" + loading);
+ console.log("jsondata--" + jsonData);
+ if (loading) {
+ window.close();
+ return;
+ }
+ var prefForDom;
+ //console.log("test--" + isFromSearch(currentUrl));
+ console.log("loadFrom-" + loadFrom);
+ console.log("going to else part -- " + JSON.stringify(tab));
+ var fromPage = true;
+
+ prefForDom = getPreferences(url.hostname, name);
+ console.log(prefForDom != undefined);
+ console.log(findInArray(readPage, url.hostname));
+ if (prefForDom != undefined && findInArray(readPage, url.hostname)) {
+ console.log("inside if....");
+ //if (loadFrom === 'config') {
+ fromPage = false;
+ //}
+ createLoadOptions(content, "config");
+ }
+ if (!newtab) {
+ if (fromPage) {
+ console.log("from page" + name);
+ console.log(findInArray(readPage, url.hostname) + "---" + isFromSearch(currentUrl, name));
+ if (findInArray(readPage, url.hostname) || isFromSearch(currentUrl, name)) {
+ console.log("inside google");
+ searchEngine = name;
+ //to do run content script from here //move this to top, put every thing inside callbak
+
+
+ if (googleSearch === undefined || Object.keys(googleSearch).length === 0){ // || searchEngine.indexOf(url.hostname) === -1
+ //console.log("google seach list is empty");
+ //window.close();
+ //return;
+ var text = document.createTextNode("No previous search results found. Please try a fresh search.");
+ document.getElementById('openbtn').disabled = true;
+ //document.getElementById('cancelbtn').hidden = "hidden";
+ document.getElementById('selectall').disabled = true;
+ document.getElementById('selectall').nextSibling.nodeValue = "";
+ document.getElementById('sortListDir').disabled = true;
+ console.log(document.getElementById('sortListDir').nextSibling.nodeValue + "fffk");
+
+ //document.getElementById('sortListDir').nextSibling.nodeValue = "";
+ //document.getElementById('searchAgain').hidden = "hidden";
+ //document.getElementById('addbtn').hidden = "";
+ content.appendChild(text);
+ return;
+
+ }
+ console.log("Check1 " + JSON.stringify(googleSearch));
+ prefForDom = googleSearch[name]['sites'];
+ console.log("check2-" + prefForDom + "-");
+ document.getElementById('addbtn').disabled = true;
+ document.getElementById('savebtn').disabled = true;
+ //document.getElementById('searchbtn').hidden = "hidden";
+ //document.getElementById('searchText').hidden = "hidden";
+ content.style.width = "600px";
+ document.getElementById('body').style.width = "603px";
+ searchPage = true;
+ if (googleSearch === "") {
+ console.log("Search list is empty");
+ }
+
+ var engineName = name; //getDomainName(searchEngine); //new URL(searchEngine).hostname.split('.')[1];//domain.split('.')[0];
+ var div = document.createElement('div');
+ div.setAttribute("align", "center");
+ var engineLogo = document.createElement("IMG");
+ console.log("get favicon--" + name);
+ engineLogo.setAttribute("src", 'chrome://favicon/'+ name); //searchEngine);
+ //engineLogo.setAttribute("src", '/icons/' + engineName + '.ico');
+ engineLogo.style.cssFloat = 'middle';
+ div.appendChild(engineLogo);
+ //var domain = getDomain(searchEngine);
+ //var engineName = new URL(searchEngine).hostname.split('.')[1];//domain.split('.')[0];
+
+ var searchEngineTxt = document.createTextNode(" " + engineName + " results.");
+ div.appendChild(searchEngineTxt);
+ content.appendChild(div);
+ }
+ }
+
+
+ if (prefForDom === undefined) {
+ prefForDom = getPreferences(url.hostname, name); //jsonData[url.hostname] || jsonData[name];
+ //content.style.width = "200px";
+ //document.getElementById('searchAgain').hidden = "hidden";
+ searchPage = false;
+ }
+
+
+
+
+ console.log(jsonData);
+ console.log(prefForDom);
+ if(prefForDom){
+ //console.log(typeof allurls);
+ loadList(prefForDom, content, name);
+ } else {
+ console.log("domain not set...");
+ noConfigFound(content);
+ /*var text = document.createTextNode("Domain not set in preference.");
+ document.getElementById('openbtn').hidden = "hidden";
+ document.getElementById('selectall').hidden = "hidden";
+ document.getElementById('selectall').nextSibling.nodeValue = "";
+ document.getElementById('sortListDir').hidden = "hidden";
+ document.getElementById('sortListDir').nextSibling.nodeValue = "";
+ document.getElementById('anonymus').hidden = "";
+ content.appendChild(text);*/
+
+ }
- console.log(jsonData);
- console.log(prefForDom);
- if(prefForDom){
- //console.log(typeof allurls);
- if (Array.isArray(prefForDom)) {
- console.log("pref dom is an array")
- if (prefForDom.length > 0) {
- content.appendChild(createList(prefForDom));
} else {
- noConfigFound(content);
+ var mesg = "Bank Page.";
+ noConfigFound(content, mesg);
}
- } else {
- content.appendChild(createDropDown(prefForDom, name));
- var label = document.createElement('label');
- var txt = document.createTextNode("Options ");
- label.setAttribute("for", "typeSelect");
- label.appendChild(txt);
- label.style.marginLeft = "25px";
- content.insertBefore(label,document.getElementById("typeSelect"));
- var type = document.getElementById("typeSelect");
- //type.style.marginLeft = "25px";
- var selectedType = type.options[type.selectedIndex].value;
- content.appendChild(createList(prefForDom[selectedType]));
- }
- //document.getElementsByName("link").addEventListener('click', chkBoxClick);
- if (selectAll) {
- document.getElementById('selectall').checked = true;
- }
- createRadio(content);
- //document.getElementById('addbtn').hidden = "hidden";
- } else {
- console.log("domain not set...");
- noConfigFound(content);
- /*var text = document.createTextNode("Domain not set in preference.");
- document.getElementById('openbtn').hidden = "hidden";
- document.getElementById('selectall').hidden = "hidden";
- document.getElementById('selectall').nextSibling.nodeValue = "";
- document.getElementById('sortListDir').hidden = "hidden";
- document.getElementById('sortListDir').nextSibling.nodeValue = "";
- document.getElementById('anonymus').hidden = "";
- content.appendChild(text);*/
+ });
- }
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', chrome.extension.getURL('utube.json'));
+ xhr.responseType = "text";
+
+ xhr.onreadystatechange = function() {
+ console.log("here");
+ if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
+ //console.log(xhr.responseText);
+ //utubeData = xhr.responseText;
+ utubeData = JSON.parse(xhr.responseText);
+ console.log(utubeData);
+ if (utubeData !== undefined) {
+ var adStuff = document.getElementById('adStuff');
+ //var utubeData = chrome.runtime.getURL("utube.json");
+ console.log(utubeData);
+ var keys = Object.keys(utubeData);
+ var ranNum = randomIntFromInterval(0, 9);
+ console.log("Me random" + ranNum);
+ var utube = document.createElement('a');
+ utube.textContent = keys[ranNum];
+ utube.href = utubeData[keys[ranNum]];
+ utube.onclick = utubeClick;
+ adStuff.appendChild(utube);
+ adStuff.appendChild(document.createElement('br'));
+ /*keys.forEach(function (key) {
+ //console.log(data);
+ var utube = document.createElement('a');
+ utube.textContent = key;
+ utube.href = utubeData[key];
+ utube.onclick = utubeClick;
+ adStuff.appendChild(utube);
+ adStuff.appendChild(document.createElement('br'));
+ });*/
+ }
+ }
+ };
+ xhr.send();
+ //
+ //console.log("margin" + document.getElementById("selectall").style.margin);
+ /*var delayMillis = 10000; //1 second
+ setTimeout(function() {
+ //your code to be executed after 1 second
+ }, delayMillis);*/
+ document.getElementById('mainStuff').hidden = false;
+ document.getElementById('progress').hidden = true;
+ console.log(response.farewell);
+ });
});
- var xhr = new XMLHttpRequest();
- xhr.open('GET', chrome.extension.getURL('utube.json'));
- xhr.responseType = "text";
-
- xhr.onreadystatechange = function() {
- console.log("here");
- if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
- //console.log(xhr.responseText);
- //utubeData = xhr.responseText;
- utubeData = JSON.parse(xhr.responseText);
- console.log(utubeData);
- if (utubeData !== undefined) {
- var adStuff = document.getElementById('adStuff');
- //var utubeData = chrome.runtime.getURL("utube.json");
- console.log(utubeData);
- var keys = Object.keys(utubeData);
- var ranNum = randomIntFromInterval(0, 9);
- console.log("Me random" + ranNum);
- var utube = document.createElement('a');
- utube.textContent = keys[ranNum];
- utube.href = utubeData[keys[ranNum]];
- utube.onclick = utubeClick;
- adStuff.appendChild(utube);
- adStuff.appendChild(document.createElement('br'));
- /*keys.forEach(function (key) {
- //console.log(data);
- var utube = document.createElement('a');
- utube.textContent = key;
- utube.href = utubeData[key];
- utube.onclick = utubeClick;
- adStuff.appendChild(utube);
- adStuff.appendChild(document.createElement('br'));
- });*/
+}
- }
- }
- };
- xhr.send();
- //
+function createLoadOptions(content, sele) {
+ var loadDiv = document.createElement("div");
+ loadDiv.style.width = '300px';
+ var label = document.createElement("label");
+ label.innerHTML = "Load from ";
+ label.style.marginLeft = "25px";
+ loadDiv.appendChild(label);
+
+ var radio = document.createElement("INPUT");
+ radio.setAttribute("type", "radio");
+ radio.setAttribute("value", "config");
+ radio.setAttribute("name", "loadFrom");
+ if (sele === 'config')
+ radio.checked = true;
+ radio.onclick = updateList;
+
+ label = document.createElement("label");
+ label.innerHTML = "Config";
+
+ loadDiv.appendChild(radio);
+ loadDiv.appendChild(label);
+
+ radio = document.createElement("INPUT");
+ radio.setAttribute("type", "radio");
+ radio.setAttribute("value", "page");
+ radio.setAttribute("name", "loadFrom");
+ if (sele === 'page')
+ radio.checked = true;
+
+ label = document.createElement("label");
+ label.innerHTML = "Page";
+ console.log("i m ann");
+ radio.onclick = updateList;
+ loadDiv.appendChild(radio);
+ loadDiv.appendChild(label);
+ content.appendChild(loadDiv);
- //console.log("margin" + document.getElementById("selectall").style.margin);
- /*var delayMillis = 10000; //1 second
+}
- setTimeout(function() {
- //your code to be executed after 1 second
+function updateList(ele) {
- }, delayMillis);*/
- document.getElementById('mainStuff').hidden = false;
- document.getElementById('progress').hidden = true;
-});
+ console.log(ele.srcElement.value);
+ if (ele.srcElement.value === 'page') {
+ var content = document.getElementById('content');
+ while (content.hasChildNodes()) {
+ content.removeChild(content.firstChild);
+ }
+ var searchContent = document.getElementById('searchContent');
+ while (searchContent.hasChildNodes()) {
+ searchContent.removeChild(searchContent.firstChild);
+ }
+ createLoadOptions(content, "page");
+ var name = getDomainName(currentUrl);
+ //prefForDom = googleSearch;
+ //console.log("check2-" + prefForDom + "-");
+ document.getElementById('addbtn').disabled = true;
+ document.getElementById('savebtn').disabled = true;
+ //document.getElementById('searchbtn').hidden = "hidden";
+ //document.getElementById('searchText').hidden = "hidden";
+ content.style.width = "600px";
+ document.getElementById('body').style.width = "603px";
+ searchPage = true;
+ if (googleSearch === "") {
+ console.log("Search list is empty");
+ }
+ var engineName = name;//getDomainName(searchEngine); //new URL(searchEngine).hostname.split('.')[1];//domain.split('.')[0];
+ var div = document.createElement('div');
+ div.setAttribute("align", "center");
+ var engineLogo = document.createElement("IMG");
+ console.log("get favicon--" + name);
+ engineLogo.setAttribute("src", 'chrome://favicon/'+ name); //searchEngine);
+ //engineLogo.setAttribute("src", '/icons/' + engineName + '.ico');
+ engineLogo.style.cssFloat = 'middle';
+ div.appendChild(engineLogo);
+ //var domain = getDomain(searchEngine);
+ //var engineName = new URL(searchEngine).hostname.split('.')[1];//domain.split('.')[0];
+
+ var searchEngineTxt = document.createTextNode(" " + engineName + " results.");
+ div.appendChild(searchEngineTxt);
+ content.appendChild(div);
+ console.log(googleSearch[name]['tree']);
+ showTree = googleSearch[name]['tree'];
+ document.getElementById('selectall').hidden = true;
+ document.getElementById('selectall').nextSibling.nodeValue = "";
+ document.getElementById('sortListDir').hidden = true;
+ document.getElementById('howmany').hidden = true;
+ console.log(googleSearch);
+ loadList(googleSearch[name]['sites'], content, name, googleSearch[name]['tree']);
+ } else if (ele.srcElement.value === 'config'){
+ console.log("config part");
+ var content = document.getElementById('content');
+ while (content.hasChildNodes()) {
+ content.removeChild(content.firstChild);
+ }
+ var searchContent = document.getElementById('searchContent');
+ while (searchContent.hasChildNodes()) {
+ searchContent.removeChild(searchContent.firstChild);
+ }
+ createLoadOptions(content, "config");
+ var url = new URL(currentUrl);
+ var name = getDomainName(currentUrl);
+ searchPage = false;
+ content.style.width = "200px";
+ document.getElementById('body').style.width = "400px";
+ document.getElementById('addbtn').disabled = false;
+ document.getElementById('savebtn').disabled = false;
+
+ document.getElementById('selectall').hidden = false;
+ document.getElementById('selectall').nextSibling.nodeValue = "All";
+ document.getElementById('sortListDir').hidden = false;
+ document.getElementById('howmany').hidden = false;
+ loadList(getPreferences(url.hostname, name), content, name);
+ }
+
+ //content.removeAll();
-function noConfigFound(content) {
+}
+
+function noConfigFound(content, msg) {
console.log("domain not set...");
+ var textContent = "\nYou may enter the URL's to open,one below the other,\nin the space given below and open them.";
+ if (msg) {
+ textContent = msg + textContent;
+ document.getElementById('addbtn').disabled = true;
+ } else {
+ textContent = "Domain not set in preference." + textContent;
+ }
const divTxt = document.createElement("div");
var pre = document.createElement("PRE");
- var text = document.createTextNode("Domain not set in preference.\nYou may enter the URL's to open,one below the other,\nin the space given below and open them.");
+ var text = document.createTextNode(textContent);//"Domain not set in preference.\nYou may enter the URL's to open,one below the other,\nin the space given below and open them.");
pre.appendChild(text);
divTxt.style.marginLeft = "25px";
- document.getElementById('openbtn').hidden = "hidden";
+ document.getElementById('openbtn').disabled = true;
//document.getElementById('cancelbtn').hidden = "hidden";
- document.getElementById('selectall').hidden = "hidden";
- document.getElementById('selectall').nextSibling.nodeValue = "";
- document.getElementById('sortListDir').hidden = "hidden";
- document.getElementById('sortListDir').nextSibling.nodeValue = "";
- //document.getElementById('addbtn').hidden = "";
+ document.getElementById('selectall').disabled = true;
+ //document.getElementById('selectall').nextSibling.nodeValue = "";
+ document.getElementById('sortListDir').disabled = true;
+ //document.getElementById('sortListDir').nextSibling.nodeValue = "";
+
+ document.getElementById('savebtn').disabled = true;
document.getElementById('anonymus').hidden = "";
if (anonymus) {
document.getElementById('anonymus').value = anonymus;
- document.getElementById('openbtn').hidden = "";
+ document.getElementById('openbtn').disabled = false;
}
document.getElementById('anonymus').onkeyup = editTextArea;
@@ -961,14 +1242,15 @@ function createRadio(content) {
//console.log("url hostname eng-" + engineUrl.hostname);
var engine;
if (searchPage) {
- engine = getDomainName(searchEngine); //engineUrl.hostname.split('.')[1];
+ //console.log(searchEngine + currentUrl);
+ engine = searchEngine; //getDomainName(searchEngine); //engineUrl.hostname.split('.')[1];
}
- var sitesArr = ['https://www.google.com/', 'https://search.yahoo.com/', 'https://www.bing.com/', 'https://www.youtube.com/']; //searchSites.split(',');
+ var sitesArr = ['https://www.google.com/', 'https://search.yahoo.com/', 'https://www.bing.com/']; //searchSites.split(',');//, 'https://www.youtube.com/'
var searchContent = document.getElementById('searchContent');
- var searchDiv = document.createElement('searchDiv');
+ var searchDiv = document.createElement('div');
searchDiv.id = "searchDiv";
searchDiv.style.margin = "0px 0px 0px 25px";
searchDiv.style.width = '300px';
@@ -1024,7 +1306,7 @@ function createRadio(content) {
searchAgainBtn.setAttribute("type", "button");
selectAll ? searchAgainBtn.disabled = true : searchAgainBtn.disabled = false;
if (searchPage) {
- /*var radio = document.createElement("INPUT");
+ var radio = document.createElement("INPUT");
radio.setAttribute("type", "radio");
radio.setAttribute("value", both);
radio.setAttribute("name", "site");
@@ -1032,7 +1314,7 @@ function createRadio(content) {
var label = document.createElement("label");
label.innerHTML = "Both";
searchDiv.appendChild(radio);
- searchDiv.appendChild(label);*/
+ searchDiv.appendChild(label);
searchAgainBtn.setAttribute("id", "searchAgain");
searchAgainBtn.setAttribute("value", "Search Again");
searchAgainBtn.onclick = searchAgain;
@@ -1041,7 +1323,7 @@ function createRadio(content) {
searchAgainTxt.setAttribute("type", "text");
searchAgainTxt.setAttribute("id", "searchTextBox");
selectAll ? searchAgainTxt.disabled = true : searchAgainTxt.disabled = false;
- searchAgainTxt.style.marginLeft = "25px";
+ //fsearchAgainTxt.style.marginLeft = "25px";
searchDiv.appendChild(searchAgainTxt);
searchAgainBtn.setAttribute("id", "searchbtn");
searchAgainBtn.setAttribute("value", "Search");
@@ -1082,7 +1364,7 @@ function getPreferences(url_hostname, name, dataObj) {
dataObj = jsonData;
}
console.log(url_hostname + " -- " + name );
- let pref = [];
+ let pref;// = [];
for (var item in dataObj) {
let domain;
domain = dataObj[item]['current'];
@@ -1126,12 +1408,14 @@ function createList(allurls) {
//list.setAttribute("")
if (!searchPage) {
list.style.width = "100%";
+ selectAll = true;
}
list.style.align = "right";
var i=1;
var value="";
var bgColor = "#EDEEED"; //"#F4F6F7";
+
allurls.forEach(function(page) {
console.log("in createList " + JSON.stringify(page));
//console.log(Object.keys(page));
@@ -1143,55 +1427,58 @@ function createList(allurls) {
var linkObj, key, url;
if (typeof page === 'object') {
console.log("has key value");
-
- if (typeof Object.values(page)[0] === 'object') {
- url = Object.values(page)[0];
- linkObj = url.url;
- if (linkObj.indexOf("http") === -1) {
- linkObj = baseUrl + linkObj;
- }
- input.setAttribute("value", linkObj);
- input.setAttribute("Alt", url.alt);
- if (currentUrl !== linkObj && url.selected !== false && selectAll) {
- input.setAttribute("checked", true);
- label.style.fontWeight = "bold";
- if (searchPage) {
- var itemValue = input.value;
- chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {highlight:true, selectedItems: itemValue}, function(response) {
- console.log(response.farewell);
- });
- });
+ if (Object.keys(page).length > 0){ //todo remove this condition 291217 ..any empty obj got into the jsonObj for washington post....due to which popup dint load...ths was added to handle that
+ if (typeof Object.values(page)[0] === 'object') {
+ url = Object.values(page)[0];
+ linkObj = url.url;
+ if (linkObj.indexOf("http") === -1) {
+ linkObj = baseUrl + linkObj;
}
+ input.setAttribute("value", linkObj);
+ input.setAttribute("Alt", url.alt);
+ if (currentUrl !== linkObj && url.selected !== false) { // && selectAll
+ input.setAttribute("checked", true);
+ label.style.fontWeight = "bold";
+ if (searchPage) {
+ var itemValue = input.value;
+ chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {highlight:true, selectedItems: itemValue}, function(response) {
+ console.log(response.farewell);
+ });
+ });
+ }
+ } else {
+ console.log("llll" + label.getText);
+ }
} else {
- console.log("llll" + label.getText);
- }
- } else {
- linkObj = Object.values(page)[0];
- if (linkObj.indexOf("http") === -1) {
- linkObj = baseUrl + linkObj;
- }
- input.setAttribute("value", linkObj);
- console.log("in else");
- input.setAttribute("Alt", linkObj);
- if (currentUrl !== linkObj && selectAll) {
- input.setAttribute("checked", true);
- label.style.fontWeight = "bold";
- if (searchPage) {
- var itemValue = input.value;
- chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
- chrome.tabs.sendMessage(tabs[0].id, {highlight:true, selectedItems: itemValue}, function(response) {
- console.log(response.farewell);
+ linkObj = Object.values(page)[0];
+ if (linkObj.indexOf("http") === -1) {
+ linkObj = baseUrl + linkObj;
+ }
+ input.setAttribute("value", linkObj);
+ console.log("in else");
+ input.setAttribute("Alt", linkObj);
+ if (currentUrl !== linkObj && selectAll) {
+ input.setAttribute("checked", true);
+ label.style.fontWeight = "bold";
+ if (searchPage) {
+ var itemValue = input.value;
+ chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
+ chrome.tabs.sendMessage(tabs[0].id, {highlight:true, selectedItems: itemValue}, function(response) {
+ console.log(response.farewell);
+ });
});
- });
+ }
+ } else {
+ console.log("llll" + label.getText);
}
- } else {
- console.log("llll" + label.getText);
}
+
+ key = Object.keys(page)[0];
+
}
- key = Object.keys(page)[0];
} else {
var pageParts = page.split('/');
console.log(pageParts.length);
@@ -1222,7 +1509,7 @@ function createList(allurls) {
if (currentUrl === linkObj) {
key = key + "(Current Tab)";
console.log("kkk"+key);
- document.getElementById('addbtn').hidden = "hidden";
+ document.getElementById('addbtn').disabled = true;
}
var id = key; //Object.keys(page)[0];
input.setAttribute("id", id);
@@ -1272,12 +1559,12 @@ function createList(allurls) {
bgColor = "#EDEEED"; //"#F4F6F7";
}
});
- var howmany = document.getElementById("howmany");
+ /*var howmany = document.getElementById("howmany");
if (selectAll) {
howmany.textContent = allurls.length + " selected.";
} else {
howmany.textContent = "0 selected.";
- }
+ }*/
return list;
@@ -1301,6 +1588,10 @@ function selectOption() {
if (Array.isArray(allTypes[selectedType])){
content.appendChild(createList(allTypes[selectedType]));
}
+ const allUrls = document.getElementsByName("link");
+ var parentNode = allUrls[0].parentNode.parentNode.childNodes;
+ changeSelection(parentNode);
+
}
@@ -1378,12 +1669,12 @@ function isParentGoogle(parentUrl) {
//return google.indexOf(url.hostname) > -1;
}
-function isFromSearch(currentURL) {
+function isFromSearch(currentURL, name) {
//console.log("Check1 " + JSON.stringify(googleSearch));
console.log("Check22 " + currentURL);
var urlFound = false;
- if (googleSearch) {
- googleSearch.forEach(function (obj) {
+ if (googleSearch && googleSearch[name]['sites']) {
+ googleSearch[name]['sites'].forEach(function (obj) {
var value = Object.values(obj);
console.log("Check3 " + value);
if (value == currentURL) {
@@ -1428,4 +1719,204 @@ function isUrlInList(currentURL, urlList) {
});
return urlFound;
-}
\ No newline at end of file
+}
+
+chrome.runtime.onMessage.addListener(function(req, sender, sendres){
+ if (req.cnnLoading === "complete") {
+ console.log("cnn loaded....")
+ }
+
+
+});
+
+function mainbuttonClick () {
+ console.log("on click text");
+}
+
+function loadList(prefForDom, content, name, treeStructure) {
+ if (Array.isArray(prefForDom)) {
+ console.log("pref dom is an array");
+ if (prefForDom.length > 0) {
+ content.appendChild(createList(prefForDom));
+ } else {
+ noConfigFound(content);
+ }
+ } else {
+ console.log("in else...");
+ if (treeStructure) {
+ console.log("tree");
+ /*var det = document.createElement("details");
+ var summ = document.createElement("summery");
+ summ.innerHTML = "click Me";
+ var textNode = document.createElement('kfkgkdfgkf');
+ summ.appendChild(textNode);
+ det.appendChild(summ);
+ content.appendChild(det);*/
+ var keys = Object.keys(prefForDom);
+
+ keys.forEach(function (key) {
+ var detail = document.createElement("details");
+ detail.setAttribute('name', 'detail');
+ var inp = document.createElement('input');
+ inp.setAttribute('type', 'checkbox');
+ inp.setAttribute('id', key);
+ //inp.onclick = selectChildren;
+ inp.disabled = true;
+ var summary = document.createElement('summary');
+ summary.innerHTML = key;
+ //var txt = document.createTextNode(key);
+ //inp.appendChild(txt);
+ detail.style.marginLeft = "25px";
+ detail.appendChild(summary);
+ summary.appendChild(inp);
+ detail.onclick = detailClick;
+ var objs = prefForDom[key]; //Object.values(prefForDom);
+ //console.log(objs);
+ var ol = document.createElement('ol');
+ var bgColor = "#EDEEED";
+ objs.forEach(function(obj){
+ //console.log(obj);
+
+ var subli = document.createElement('li');
+ var subinput = document.createElement('input');
+ subinput.setAttribute('type', 'checkbox');
+ subinput.setAttribute('id', Object.keys(obj));
+ subli.style.listStyleType = 'none';
+ subli.style.position = 'relative';
+ subli.style.backgroundColor = bgColor;
+ ol.appendChild(subli);
+ //var lbl = document.createElement('label');
+ //console.log("********************" + JSON.stringify(obj));
+ //var txt = document.createTextNode(Object.keys(obj));
+ //lbl.htmlFor = Object.keys(obj);
+ //lbl.appendChild(txt);
+ //lbl.style.display = 'block';
+ //subli.appendChild(lbl);
+ subli.appendChild(subinput);
+
+ var anchor = document.createElement('a');
+ anchor.href = Object.values(obj);
+ anchor.innerHTML = Object.keys(obj);
+ subli.appendChild(anchor);
+ detail.appendChild(ol);
+ if (bgColor === "#EDEEED") {//ECF0F1 //"#F4F6F7"
+ bgColor = "#FFFFFF";
+ } else {
+ bgColor = "#EDEEED"; //"#F4F6F7";
+ }
+ });
+
+ content.appendChild(detail);
+
+ });
+
+ /*keys.forEach(function (key) {
+ var orderedList = document.createElement('ol');
+ var li = document.createElement('li');
+ var input = document.createElement('input');
+ input.setAttribute('type', 'checkbox');
+ //var idy = key;
+ input.setAttribute('id', key);
+ input.style.position = 'absolute';
+ li.style.listStyleType = 'none';
+ li.style.position = 'relative';
+ orderedList.appendChild(li);
+ var label = document.createElement('label');
+ var txt = document.createTextNode(key);
+ label.htmlFor = key;
+ label.appendChild(txt);
+ label.style.display = 'block';
+ li.appendChild(label);
+ li.appendChild(input);
+ var objs = Object.values(prefForDom);
+ objs.forEach(function(obj){
+ var ol = document.createElement('ol');
+ var subli = document.createElement('li');
+ var subinput = document.createElement('input');
+ subinput.setAttribute('type', 'checkbox');
+ subinput.setAttribute('id', Object.keys(obj[0]));
+ subli.style.listStyleType = 'none';
+ subli.style.position = 'relative';
+ ol.appendChild(subli);
+ //var lbl = document.createElement('label');
+ //console.log("********************" + JSON.stringify(obj));
+ //var txt = document.createTextNode(Object.keys(obj[0]));
+ //lbl.htmlFor = Object.keys(obj[0]);
+ //lbl.appendChild(txt);
+ //lbl.style.display = 'block';
+ //subli.appendChild(lbl);
+ subli.appendChild(subinput);
+
+ var anchor = document.createElement('a');
+ anchor.href = Object.values(obj[0]);
+ anchor.innerHTML = Object.keys(obj[0]);
+ subli.appendChild(anchor);
+ li.appendChild(ol);
+ });
+ content.appendChild(orderedList);
+
+ });*/
+
+
+
+ } else {
+ content.appendChild(createDropDown(prefForDom, name));
+ var label = document.createElement('label');
+ var txt = document.createTextNode("Options ");
+ label.setAttribute("for", "typeSelect");
+ label.appendChild(txt);
+ label.style.marginLeft = "25px";
+ content.insertBefore(label,document.getElementById("typeSelect"));
+ var type = document.getElementById("typeSelect");
+ //type.style.marginLeft = "25px";
+ var selectedType = type.options[type.selectedIndex].value;
+ content.appendChild(createList(prefForDom[selectedType]));
+ }
+
+ }
+ console.log(selectAll + "---" + searchPage);
+ if (selectAll && searchPage) {
+ document.getElementById('selectall').checked = true;
+ }
+
+ const allUrls = document.getElementsByName("link");
+ console.log(allUrls[0]);
+ var parentNode = allUrls[0].parentNode.parentNode.childNodes;
+ changeSelection(parentNode);
+ console.log(name);
+ if (searchPage && (name === 'google' || name === 'yahoo' || name === 'bing' || name === 'youtube')) {
+ createRadio(content);
+ }
+}
+
+function selectChildren(obj) {
+ console.log(obj.checked);
+ var allLi = obj.parentNode.nextSibling.childNodes;
+ var set = obj.checked;
+
+ allLi.forEach(function(li){
+ //console.log(li);
+ if (set) {
+ console.log(li);
+ li.childNodes[0].checked = true;
+ li.childNodes[1].style.fontWeight = "bold";
+ } else {
+ console.log(li);
+ li.childNodes[0].checked = false;
+ li.childNodes[1].style.fontWeight = "normal";
+ }
+
+ });
+}
+
+function detailClick() {
+ //console.log(this);
+ this.childNodes[0].childNodes[1].checked = !(this.open);
+ console.log(this.attributes);
+ selectChildren(this.childNodes[0].childNodes[1]);
+ //if (this.open) {
+ //console.log(this.childNodes);
+ //this.childNodes[0].childNodes[1].checked = false;
+
+ //}
+}