From 00b0604b2176f956a3a3cea734c13c27f4cd79f5 Mon Sep 17 00:00:00 2001 From: Gautam Date: Thu, 30 Nov 2017 22:59:56 -0600 Subject: [PATCH 1/8] Modified popup.js, background.js etc for fixes. --- background.js | 64 +++++--- content_script.js | 36 ++++- manifest.json | 8 +- options.html | 7 +- options.js | 36 +++-- popup.js | 399 +++++++++++++++++++++++++++++----------------- 6 files changed, 362 insertions(+), 188 deletions(-) diff --git a/background.js b/background.js index 1102663..8669c74 100644 --- a/background.js +++ b/background.js @@ -9,7 +9,7 @@ var lastTab; var urls = []; var tabToHilite; var openAt; -var firstPage; +var firstPage = ""; var invokedWind; var startTime; var pagesToOpen = []; @@ -32,7 +32,11 @@ 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"; + //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 ) @@ -72,25 +76,40 @@ chrome.storage.onChanged.addListener(function(changes, area) { 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); + //var url = urls[0]; + for (var x = 0;x < parseInt(tabToLoad); 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 + urls[x]); + // 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){ @@ -159,20 +178,27 @@ chrome.tabs.onUpdated.addListener(function(tabId , changeInfo, info) { if (firstPage !== "") { chrome.tabs.update(firstPage, {active: true}); firstPage = ""; + console.log("before-------------" + pagesToOpen); + for (var i = 0 ; i < parseInt(tabToLoad) - 1; i ++) { + pagesToOpen.shift(); + } + console.log("after-------------" + pagesToOpen); } 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()); + console.log("k inside for--" + k + "---" + new Date().getTime() + "--------" + pagesToOpen[0]); 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 ++; + //openAt ++; }); + openAt ++; if (pagesToOpen.length == 1) { return; } diff --git a/content_script.js b/content_script.js index 1f9b822..1453728 100644 --- a/content_script.js +++ b/content_script.js @@ -78,6 +78,29 @@ $("div#contents").find("h3 > a").each(function (index) { //div#title-wrapper }); + +//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['sites'] = sites; if (location.origin.indexOf('yahoo') > -1) { queryString = document.getElementsByName("p")[0].value; @@ -97,6 +120,8 @@ console.log(location.origin);*/ //var urlquery = ''; //urlquery = location.origin + location.pathname + '?q=' + queryString; console.log("Final object...\n" + JSON.stringify(jsonObj)); +console.log("queryStr--" + queryString); +//chrome.storage.sync.set({'googleSearch': "", 'queryString' : "", 'searchEngine' : ""}, function() {}); chrome.storage.sync.set({'googleSearch': sites, 'queryString' : queryString, 'searchEngine' : location.origin}, function() { console.log('Settings saved'); }); @@ -109,15 +134,18 @@ $("div.srg").find("h3 > a").click(function () { }); $('a').click(function(){ + //alert('u r going to ' + $(this).attr('href') + '..jst li dt..'); }); -var urlArr = []; -$('a').each(function(){ - urlArr.push($(this).attr('href')); +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"}); diff --git a/manifest.json b/manifest.json index eb31b7c..16d2f64 100644 --- a/manifest.json +++ b/manifest.json @@ -33,7 +33,13 @@ } }, "content_scripts": [{ - "matches": ["https://www.google.com/*"], + "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://edition.cnn.com/"], "js": ["jquery-1.8.0.min.js", "content_script.js"] }], "browser_action": { diff --git a/options.html b/options.html index 9d1cf1c..0a43856 100644 --- a/options.html +++ b/options.html @@ -44,7 +44,7 @@ Highlight tabs with same base url.
- Select all pages. + Select all pages (Only for google/yahoo/bing/youtube search results).
Page loading time out @@ -52,6 +52,11 @@
Tabs to load at a time +
+ Load from: Configuration + + Page + diff --git a/options.js b/options.js index 2cfbb52..78c82e8 100644 --- a/options.js +++ b/options.js @@ -9,6 +9,7 @@ function save_options() { 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; if (jsonData.trim() === '') { @@ -46,7 +47,8 @@ function save_options() { highlightTabs: highlightTabs, selectAll: selectAll, timeOut : timeOut, - tabToLoad : tabToLoad}, + tabToLoad : tabToLoad, + loadFrom : loadFrom}, function() { // Update status to let user know options were saved. var status = document.getElementById('status'); @@ -89,10 +91,10 @@ function validJson(jsonObj) { if (typeof siteItem === 'object') { if (typeof Object.values(siteItem)[0] === 'object') { linkObj = Object.values(siteItem)[0].url; - alert("Link-A--1-" + JSON.stringify(linkObj)); + //alert("Link-A--1-" + JSON.stringify(linkObj)); } else { linkObj = Object.values(siteItem)[0]; - alert("Link-A--2-" + JSON.stringify(linkObj)); + //alert("Link-A--2-" + JSON.stringify(linkObj)); } } if (linkObj.indexOf("http") === -1) { @@ -105,10 +107,10 @@ function validJson(jsonObj) { } 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); + //alert("Link-B-" + linkObj); } else { linkObj = Object.values(sites[index])[0]; - alert("Link-C-" + linkObj); + //alert("Link-C-" + linkObj); } if (linkObj.indexOf("http") === -1) { linkObj = getBaseURL(current) + linkObj; @@ -118,7 +120,7 @@ function validJson(jsonObj) { } } else { linkObj = sites[index]; - alert("Link-D-" + linkObj); + //alert("Link-D-" + linkObj); if (linkObj.indexOf("http") === -1) { linkObj = getBaseURL(current) + linkObj; } @@ -192,9 +194,9 @@ function doesUrlRepeat(linkObj, jsonObj, current) { if (url.indexOf("http") === -1) { url = getBaseURL(curr) + url; } - alert("link--" + linkObj + "\n" + "site--" + url); + //alert("link--" + linkObj + "\n" + "site--" + url); if (linkObj === url) { - alert("me here AA"); + //alert("me here AA"); //alert("The url " + linkObj + "is defined under " + current + " and " + curr + "..Please correct and try again"); if (!firstOccurance) { let mesg; @@ -220,10 +222,10 @@ function doesUrlRepeat(linkObj, jsonObj, current) { if (url.indexOf("http") === -1) { url = getBaseURL(curr) + url; } - alert("link--" + linkObj + "\n" + "site--" + url); + //alert("link--" + linkObj + "\n" + "site--" + url); if (linkObj === url) { - alert("me here A"); + //alert("me here A"); //alert("The url " + linkObj + "is defined under " + current + " and " + curr + "..Please correct and try again"); if (!firstOccurance) { let mesg; @@ -243,10 +245,10 @@ function doesUrlRepeat(linkObj, jsonObj, current) { if (url.indexOf("http") === -1) { url = getBaseURL(curr) + url; } - alert("link--" + linkObj + "\n" + "site--" + url); + //alert("link--" + linkObj + "\n" + "site--" + url); if (linkObj === url) { - alert("me here B"); + //alert("me here B"); // alert("The url " + linkObj + "is defined under " + current + " and " + curr + "..Please correct and try again"); if (!firstOccurance) { let mesg; @@ -284,13 +286,21 @@ function restore_options() { highlightTabs: true, selectAll: true, timeOut: 30, - tabToLoad : 2 + tabToLoad : 2, + loadFrom : "config" }, 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; + 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; diff --git a/popup.js b/popup.js index 7b18918..3c6daa5 100644 --- a/popup.js +++ b/popup.js @@ -15,9 +15,11 @@ 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 options = ['tabsBackground', 'highlightTabs', 'jsonData', 'selectAll', 'loading', 'googleSearch', 'parentUrl', 'queryString', 'searchEngine', 'anonymus', 'loadFrom']; +var readPage = ['www.google.co.in', 'www.google.com', 'search.yahoo.com', 'www.bing.com', 'www.youtube.com', 'edition.cnn.com']; +var searchSite= ['google', 'yahoo', 'bing', 'youtube']; chrome.storage.sync.get( options, function(items) { @@ -28,11 +30,13 @@ chrome.storage.sync.get( options, function(items) { loading = items.loading; console.log("in sync get" + loading); googleSearch = items.googleSearch; + console.log("in sync get search--" + googleSearch); parentUrl = items.parentUrl; queryString = items.queryString; //searchSites = items.searchSites; searchEngine = items.searchEngine; anonymus = items.anonymus; + loadFrom = items.loadFrom; }); function closeWindow (e) { @@ -62,12 +66,12 @@ function clickHandler(e) { 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'); + anonymusValues = document.getElementById("anonymus").value; + const urls = anonymusValues.split('\n'); urls.forEach(function (url) { if (url.startsWith('http') || url.startsWith('https')) { urlsToOpen.push(url); @@ -113,7 +117,7 @@ function clickHandler(e) { }*/ 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."); } @@ -123,17 +127,17 @@ function clickHandler(e) { 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 +149,8 @@ function selectall () { } }); + + /* var howmany = document.getElementById("howmany"); var selNums = howManyChecked(parentNode); howmany.textContent = selNums + " selected."; @@ -160,14 +166,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 +185,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 +197,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 +236,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; } @@ -268,32 +274,39 @@ function chkBoxClick (ele) { } 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')) { @@ -322,13 +335,13 @@ function chkBoxClick (ele) { 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 +395,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 +421,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 +467,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 +493,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 +609,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; @@ -709,16 +770,20 @@ 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; } } document.addEventListener('DOMContentLoaded', function () { @@ -735,7 +800,7 @@ 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'); @@ -744,8 +809,11 @@ document.addEventListener('DOMContentLoaded', function () { getCurrentTabUrl(function(tab) { currentUrl = tab.url; if (currentUrl === "chrome://newtab/") { - window.close(); - return; + //window.close(); + //return; + newtab = true; + } else { + newtab = false; } var url = new URL(tab.url); @@ -766,111 +834,128 @@ document.addEventListener('DOMContentLoaded', function () { } 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("loadFrom-" + loadFrom); + var fromPage = true; + if (loadFrom === 'config' && searchSite.indexOf(url.hostname) === -1) { + fromPage = false; + } + if (!newtab) { + if (fromPage) { + if (readPage.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').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; + 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 = 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); + } } - 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; - } + if (prefForDom === undefined) { + prefForDom = getPreferences(url.hostname, name); //jsonData[url.hostname] || jsonData[name]; + //content.style.width = "200px"; + //ocument.getElementById('searchAgain').hidden = "hidden"; + searchPage = false; + } - 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)); + + 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); + } } else { - noConfigFound(content); + 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 && searchPage) { + document.getElementById('selectall').checked = true; + } + createRadio(content); + //document.getElementById('addbtn').hidden = "hidden"; + const allUrls = document.getElementsByName("link"); + var parentNode = allUrls[0].parentNode.parentNode.childNodes; + changeSelection(parentNode); } 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; + 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);*/ + } - 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);*/ - } + } else { + var mesg = "Bank Page."; + noConfigFound(content, mesg); + } @@ -927,24 +1012,32 @@ document.addEventListener('DOMContentLoaded', function () { document.getElementById('progress').hidden = true; }); -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; @@ -964,7 +1057,7 @@ function createRadio(content) { engine = 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'); @@ -1024,7 +1117,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 +1125,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; @@ -1082,7 +1175,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 +1219,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)); @@ -1152,7 +1247,7 @@ function createList(allurls) { } input.setAttribute("value", linkObj); input.setAttribute("Alt", url.alt); - if (currentUrl !== linkObj && url.selected !== false && selectAll) { + if (currentUrl !== linkObj && url.selected !== false) { // && selectAll input.setAttribute("checked", true); label.style.fontWeight = "bold"; if (searchPage) { @@ -1222,7 +1317,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 +1367,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 +1396,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); + } From cca16e21e79985d46aa4d0c93bf3bb979814e33c Mon Sep 17 00:00:00 2001 From: Gautam Date: Sun, 10 Dec 2017 23:14:14 -0600 Subject: [PATCH 2/8] Modified popup.js, background.js etc for fixes. --- background.js | 34 +- content_script.js | 5 +- manifest.json | 2 +- options.js | 2 +- popup.js | 2791 +++++++++++++++++++++++---------------------- 5 files changed, 1426 insertions(+), 1408 deletions(-) diff --git a/background.js b/background.js index 8669c74..eebffec 100644 --- a/background.js +++ b/background.js @@ -71,13 +71,15 @@ chrome.storage.onChanged.addListener(function(changes, area) { 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]; - for (var x = 0;x < parseInt(tabToLoad); x++) { + 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){ @@ -92,7 +94,7 @@ chrome.storage.onChanged.addListener(function(changes, area) { } lastTab = tab.id; - console.log("reset" + openAt + urls[x]); + console.log("reset" + openAt + url); // chrome.browserAction.setIcon({path:"icons/ajax-loader.gif"}); //keep_switching_icon = true; //console.log(keep_switching_icon); @@ -108,6 +110,7 @@ chrome.storage.onChanged.addListener(function(changes, area) { }); openAt ++; + } } else { @@ -178,11 +181,11 @@ chrome.tabs.onUpdated.addListener(function(tabId , changeInfo, info) { if (firstPage !== "") { chrome.tabs.update(firstPage, {active: true}); firstPage = ""; - console.log("before-------------" + pagesToOpen); + console.log("before-------------" + pagesToOpen.length); for (var i = 0 ; i < parseInt(tabToLoad) - 1; i ++) { pagesToOpen.shift(); } - console.log("after-------------" + pagesToOpen); + console.log("after-------------" + pagesToOpen.length); } console.log("k is-" + k); if (k === parseInt(tabToLoad)) { @@ -193,19 +196,24 @@ chrome.tabs.onUpdated.addListener(function(tabId , changeInfo, info) { for ( ;k < parseInt(tabToLoad); k++) { console.log("k inside for--" + k + "---" + new Date().getTime() + "--------" + pagesToOpen[0]); 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 ++; - }); + 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) { + if (pagesToOpen.length === 1) { return; } } } - if (info.status === "complete" && tabId === lastTab && pagesToOpen.length == 1) { + 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() {}); @@ -220,7 +228,9 @@ chrome.tabs.onUpdated.addListener(function(tabId , changeInfo, info) { /* chrome.browserAction.onClicked.addListener(function(tab) { console.log("call adi"); - //chrome.tabs.executeScript(null, {file: "content_script.js"}); + chrome.tabs.executeScript({file: "./popup.js"}); + + });*/ /* diff --git a/content_script.js b/content_script.js index 1453728..5730347 100644 --- a/content_script.js +++ b/content_script.js @@ -121,8 +121,9 @@ console.log(location.origin);*/ //urlquery = location.origin + location.pathname + '?q=' + queryString; console.log("Final object...\n" + JSON.stringify(jsonObj)); console.log("queryStr--" + queryString); -//chrome.storage.sync.set({'googleSearch': "", 'queryString' : "", 'searchEngine' : ""}, function() {}); -chrome.storage.sync.set({'googleSearch': sites, 'queryString' : queryString, 'searchEngine' : location.origin}, function() { +chrome.storage.local.set({'googleSearch': "", 'queryString' : "", 'searchEngine' : ""}, function() {}); +//chrome.storage.sync.StorageArea.remove(['googleSearch', 'queryString', 'searchEngine']); +chrome.storage.local.set({'googleSearch': sites, 'queryString' : queryString, 'searchEngine' : location.origin}, function() { console.log('Settings saved'); }); diff --git a/manifest.json b/manifest.json index 16d2f64..1ec98df 100644 --- a/manifest.json +++ b/manifest.json @@ -39,7 +39,7 @@ "https://www.bing.com/*", "https://www.youtube.com/*", "https://in.yahoo.com/*", - "http://edition.cnn.com/"], + "http://www.cnn.com/"], "js": ["jquery-1.8.0.min.js", "content_script.js"] }], "browser_action": { diff --git a/options.js b/options.js index 78c82e8..b059eb1 100644 --- a/options.js +++ b/options.js @@ -11,7 +11,7 @@ function save_options() { 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; } diff --git a/popup.js b/popup.js index 3c6daa5..798bc7c 100644 --- a/popup.js +++ b/popup.js @@ -23,1146 +23,1153 @@ var searchSite= ['google', 'yahoo', 'bing', 'youtube']; chrome.storage.sync.get( options, function(items) { - jsonData = items.jsonData; - highlightTabs = items.highlightTabs; - tabsBackground = items.tabsBackground; - selectAll = items.selectAll; - loading = items.loading; - console.log("in sync get" + loading); - googleSearch = items.googleSearch; - console.log("in sync get search--" + googleSearch); - parentUrl = items.parentUrl; - queryString = items.queryString; - //searchSites = items.searchSites; - searchEngine = items.searchEngine; - anonymus = items.anonymus; - loadFrom = items.loadFrom; + jsonData = items.jsonData; + highlightTabs = items.highlightTabs; + tabsBackground = items.tabsBackground; + selectAll = items.selectAll; + loading = items.loading; + console.log("in sync get" + loading); + //googleSearch = items.googleSearch; + //console.log("in sync get search--" + googleSearch); + parentUrl = items.parentUrl; + //queryString = items.queryString; + //searchSites = items.searchSites; + //searchEngine = items.searchEngine; + anonymus = items.anonymus; + loadFrom = items.loadFrom; }); -function closeWindow (e) { - const allUrls = document.getElementsByName("link"); - var parentNode; - allUrls.forEach (function (url) { - console.log(url.parentNode); - 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); - }); - }); - } - - }); - +chrome.storage.local.get( options, function(items) { + googleSearch = items.googleSearch; + console.log("in sync get search--" + googleSearch); + queryString = items.queryString; + searchEngine = items.searchEngine; +}); - window.close(); +function closeWindow (e) { + const allUrls = document.getElementsByName("link"); + var parentNode; + allUrls.forEach (function (url) { + console.log(url.parentNode); + 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); + }); + }); + } + + }); + + + window.close(); } function clickHandler(e) { - //loading = true; - const allUrls = document.getElementsByName("link"); - const urlsToOpen = []; - const tabToHilite = [currentTab.index]; - const openAt = currentTab.index + 1; - var anonymusValues; - try { - 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 { - 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; - } - - - console.log(urlsToOpen); - /*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 : anonymusValues}, function() { - if (chrome.runtime.error) { - console.log("Runtime error."); - } - }); - window.close(); + //loading = true; + const allUrls = document.getElementsByName("link"); + const urlsToOpen = []; + const tabToHilite = [currentTab.index]; + const openAt = currentTab.index + 1; + var anonymusValues; + try { + 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 { + 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; + } + + + console.log(urlsToOpen); + /*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 : anonymusValues}, function() { + if (chrome.runtime.error) { + console.log("Runtime error."); + } + }); + window.close(); } function selectall () { - const allUrls = document.getElementsByName("link"); - 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").disabled = true; - document.getElementById("sametabChkbx").checked = false; - } - - console.log("kkkkkk-" + url.value); - var itemValue = url.value; - if (searchPage) { - 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); - }); - }); - } - - }); - - /* - var howmany = document.getElementById("howmany"); - var selNums = howManyChecked(parentNode); - howmany.textContent = selNums + " selected."; - if (selNums > 0) { - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = true; - } - - if (document.getElementById('searchbtn')) { - 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; - }*/ - } 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").disabled = true; - document.getElementById("sametabChkbx").checked = false; - 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); - }); - }); - } - - }); - /*var howmany = document.getElementById("howmany"); - howmany.textContent = "0 selected."; - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = false; - } - - if (document.getElementById('searchbtn')) { - 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; */ - //document.getElementById('searchAgain').disabled = false; - } - - changeSelection(parentNode); + const allUrls = document.getElementsByName("link"); + 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").disabled = true; + document.getElementById("sametabChkbx").checked = false; + } + + console.log("kkkkkk-" + url.value); + var itemValue = url.value; + if (searchPage) { + 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); + }); + }); + } + + }); + + /* + var howmany = document.getElementById("howmany"); + var selNums = howManyChecked(parentNode); + howmany.textContent = selNums + " selected."; + if (selNums > 0) { + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = true; + } + + if (document.getElementById('searchbtn')) { + 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; + }*/ + } 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").disabled = true; + document.getElementById("sametabChkbx").checked = false; + 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); + }); + }); + } + + }); + /*var howmany = document.getElementById("howmany"); + howmany.textContent = "0 selected."; + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = false; + } + + if (document.getElementById('searchbtn')) { + 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; */ + //document.getElementById('searchAgain').disabled = false; + } + + changeSelection(parentNode); } function linkClick () { - console.log(this.href); - const opnSmeTab = document.getElementById("sametabChkbx").checked; - chrome.storage.sync.set({urlsToOpen: [], currTab : "", invokedWindow : "", opnSmeTb : "", loading: false}, function() {}); - chrome.storage.sync.set({urlsToOpen: this.href, currTab: currentTab, invokedWindow: invokedWindow, opnSmeTb: opnSmeTab, loading : true}, function() { - if (chrome.runtime.error) { - console.log("Runtime error."); - } - }); - window.close(); + console.log(this.href); + const opnSmeTab = document.getElementById("sametabChkbx").checked; + chrome.storage.sync.set({urlsToOpen: [], currTab : "", invokedWindow : "", opnSmeTb : "", loading: false}, function() {}); + chrome.storage.sync.set({urlsToOpen: this.href, currTab: currentTab, invokedWindow: invokedWindow, opnSmeTb: opnSmeTab, loading : true}, function() { + if (chrome.runtime.error) { + console.log("Runtime error."); + } + }); + window.close(); } function chkBoxClick (ele) { - console.log(this.labels[0].innerHTML); - var currNode = this; - var none = true; - var selectedArray = []; - if (this.checked) { - this.labels[0].style.fontWeight = "bold"; - document.getElementById("openbtn").disabled = false; - //var liList = this.parentNode.parentNode.childNodes; - //console.log(liList.length); - - this.parentNode.parentNode.childNodes.forEach(function (li){ - if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { - none = false; - return; - } - - }); - if (none) { - console.log("only one"); - document.getElementById("sametab").disabled = false; - document.getElementById("sametabChkbx").checked = true; - } else { - document.getElementById("sametab").disabled = true; - document.getElementById("sametabChkbx").checked = false; - } - - console.log("li value-" + this.value); - /*selectedArray.push(this.value); - this.parentNode.parentNode.childNodes.forEach(function (li){ - if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { - selectedArray.push(li.childNodes[0].value); - } - });*/ - var itemValue = this.value; - if (searchPage) { - 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 (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = true; - } - - if (document.getElementById('searchbtn')) { - 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; - //document.getElementById('searchAgain').disabled = true; - } else { - this.labels[0].style.fontWeight="normal"; - document.getElementById("openbtn").disabled = 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").disabled = true; - document.getElementById("sametabChkbx").checked = false; - } else { - document.getElementById("sametab").disabled = false; - document.getElementById("sametabChkbx").checked = true; - } - - var selItems = this.value; - if (searchPage) { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { - 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); + console.log(this.labels[0].innerHTML); + var currNode = this; + var none = true; + var selectedArray = []; + if (this.checked) { + this.labels[0].style.fontWeight = "bold"; + document.getElementById("openbtn").disabled = false; + //var liList = this.parentNode.parentNode.childNodes; + //console.log(liList.length); + + this.parentNode.parentNode.childNodes.forEach(function (li){ + if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { + none = false; + return; + } + + }); + if (none) { + console.log("only one"); + document.getElementById("sametab").disabled = false; + document.getElementById("sametabChkbx").checked = true; + } else { + document.getElementById("sametab").disabled = true; + document.getElementById("sametabChkbx").checked = false; + } + + console.log("li value-" + this.value); + /*selectedArray.push(this.value); + this.parentNode.parentNode.childNodes.forEach(function (li){ + if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { + selectedArray.push(li.childNodes[0].value); + } + });*/ + var itemValue = this.value; + if (searchPage) { + 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 (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = true; + } + + if (document.getElementById('searchbtn')) { + 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; + //document.getElementById('searchAgain').disabled = true; + } else { + this.labels[0].style.fontWeight="normal"; + document.getElementById("openbtn").disabled = 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").disabled = true; + document.getElementById("sametabChkbx").checked = false; + } else { + document.getElementById("sametab").disabled = false; + document.getElementById("sametabChkbx").checked = true; + } + + var selItems = this.value; + if (searchPage) { + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + 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(listNodes); - console.log(listNodes.length + "***" + selNums); - howmany.textContent = selNums + " selected."; - if (selNums === 0) { - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = false; - } - - if (document.getElementById('searchbtn')) { - 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; - //document.getElementById('searchAgain').disabled = false; - } else { - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = true; - } - - if (document.getElementById('searchbtn')) { - 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; - //document.getElementById('searchAgain').disabled = true; - } - console.log("selected--" + selNums + "--list len--" + listNodes.length); - if (selNums < listNodes.length) { - document.getElementById('selectall').checked = false; - } - if (selNums === listNodes.length) { - document.getElementById('selectall').checked = true; - } + + var howmany = document.getElementById("howmany"); + var selNums = howManyChecked(listNodes); + console.log(listNodes.length + "***" + selNums); + howmany.textContent = selNums + " selected."; + if (selNums === 0) { + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = false; + } + + if (document.getElementById('searchbtn')) { + 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; + //document.getElementById('searchAgain').disabled = false; + } else { + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = true; + } + + if (document.getElementById('searchbtn')) { + 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; + //document.getElementById('searchAgain').disabled = true; + } + console.log("selected--" + selNums + "--list len--" + listNodes.length); + if (selNums < listNodes.length) { + document.getElementById('selectall').checked = false; + } + if (selNums === listNodes.length) { + document.getElementById('selectall').checked = true; + } } function howManyChecked(liNodes) { - var chked = 0; - liNodes.forEach (function (liNode){ - if (liNode.childNodes[0].checked) { - chked ++; - } - }); - return chked; + var chked = 0; + liNodes.forEach (function (liNode){ + if (liNode.childNodes[0].checked) { + chked ++; + } + }); + return chked; } function atleastOneChecked(liNodes) { - var chked = false; - liNodes.forEach (function (liNode){ - if (liNode.childNodes[0].checked) { - chked = true; - } - }); - - return chked; - - /*console.log(Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked)); - return Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked);*/ + var chked = false; + liNodes.forEach (function (liNode){ + if (liNode.childNodes[0].checked) { + chked = true; + } + }); + + return chked; + + /*console.log(Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked)); + return Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked);*/ } function moreThanOneChecked(liNodes) { - var n = 0; - liNodes.forEach (function (liNode){ - if (liNode.childNodes[0].checked) { - n ++; - } - }); - if (n === 0 || n > 1 ) { - return true; - } else { - return false; - } + var n = 0; + liNodes.forEach (function (liNode){ + if (liNode.childNodes[0].checked) { + n ++; + } + }); + if (n === 0 || n > 1 ) { + return true; + } else { + return false; + } } function addUrl() { - getCurrentTabUrl(function(tab) { - currentUrl = tab.url; - 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 = 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; - //alert("before" + JSON.stringify(origObj)); - /*var prefForDom = origObj[fullDomain]; - if (prefForDom === undefined) { - prefForDom = origObj[name]; - }*/ - //var prefForDom = origObj[fullDomain] || origObj[name]; - var prefForDom = getPreferences(fullDomain, name, origObj); - console.log("==" + prefForDom + "--- llllllll"); - var newEntryObj = {}; - var path = url.pathname.split('/'); - 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; - key = path[path.length-1]; - } else { - //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 { - var options = prefForDom; - var type = document.getElementById("typeSelect"); - var selectedType = type.options[type.selectedIndex].value; - - var allTypes = options[selectedType]; - if (Array.isArray(options[selectedType])){ - options[selectedType].push(newEntryObj); - } - } - - - } else { - console.log('in else'); - //origObj[name] = [currentUrl]; - var newObj = {}; - newObj["current"] = name; - newObj["description"] = name; - newObj["sites"] = newObjArr; //[newEntryObj]; - origObj[name] = newObj; - } - //origObj[name] = [currentUrl]; - console.log(JSON.stringify(origObj)); - //jsonObj = items; - //console.log(JSON.stringify(jsonObj)); - chrome.storage.sync.set({ - jsonData: origObj}, - function() { - // Update status to let user know options were saved. - var status = document.getElementById('status'); - status.textContent = 'Options saved.'; - setTimeout(function() { - status.textContent = ''; - }, 750); - }); - }); - }); + getCurrentTabUrl(function(tab) { + currentUrl = tab.url; + 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 = 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; + //alert("before" + JSON.stringify(origObj)); + /*var prefForDom = origObj[fullDomain]; + if (prefForDom === undefined) { + prefForDom = origObj[name]; + }*/ + //var prefForDom = origObj[fullDomain] || origObj[name]; + var prefForDom = getPreferences(fullDomain, name, origObj); + console.log("==" + prefForDom + "--- llllllll"); + var newEntryObj = {}; + var path = url.pathname.split('/'); + 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; + key = path[path.length-1]; + } else { + //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 { + var options = prefForDom; + var type = document.getElementById("typeSelect"); + var selectedType = type.options[type.selectedIndex].value; + + var allTypes = options[selectedType]; + if (Array.isArray(options[selectedType])){ + options[selectedType].push(newEntryObj); + } + } + + + } else { + console.log('in else'); + //origObj[name] = [currentUrl]; + var newObj = {}; + newObj["current"] = name; + newObj["description"] = name; + newObj["sites"] = newObjArr; //[newEntryObj]; + origObj[name] = newObj; + } + //origObj[name] = [currentUrl]; + console.log(JSON.stringify(origObj)); + //jsonObj = items; + //console.log(JSON.stringify(jsonObj)); + chrome.storage.sync.set({ + jsonData: origObj}, + 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 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; + //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 = ''; - var selectedSite = getSearchSite(); - var selSiteArr; - var idx = currentTab.index + 1; - if (selectedSite.indexOf(',') > -1) { - selSiteArr = selectedSite.split(','); - selSiteArr.forEach(function(selSite){ - if (selSite.indexOf('yahoo') > -1) { - urlSite = selSite + 'search;?p=' + queryString; - } else { - urlSite = selSite + 'search?q=' + queryString; - } - - chrome.tabs.create({url: urlSite, active : false, index: parseInt(idx), windowId : invokedWindow}, function(tab) { - idx ++; - }); - }); - } else { - if (selectedSite.indexOf('yahoo') > -1) { - urlSite = selectedSite + 'search;?p=' + queryString; - } else { - urlSite = selectedSite + 'search?q=' + queryString; - } - chrome.tabs.create({url: urlSite, active : false, index: parseInt(currentTab.index + 1), windowId : invokedWindow}, function(tab) { - - }); - //chrome.tabs.update(currentTab.id, {url: urlSite}); - } - - window.close(); + var urlSite = ''; + var selectedSite = getSearchSite(); + var selSiteArr; + var idx = currentTab.index + 1; + if (selectedSite.indexOf(',') > -1) { + selSiteArr = selectedSite.split(','); + selSiteArr.forEach(function(selSite){ + if (selSite.indexOf('yahoo') > -1) { + urlSite = selSite + 'search;?p=' + queryString; + } else { + urlSite = selSite + 'search?q=' + queryString; + } + + chrome.tabs.create({url: urlSite, active : false, index: parseInt(idx), windowId : invokedWindow}, function(tab) { + idx ++; + }); + }); + } else { + if (selectedSite.indexOf('yahoo') > -1) { + urlSite = selectedSite + 'search;?p=' + queryString; + } else { + urlSite = selectedSite + 'search?q=' + queryString; + } + chrome.tabs.create({url: urlSite, active : false, index: parseInt(currentTab.index + 1), windowId : invokedWindow}, function(tab) { + + }); + //chrome.tabs.update(currentTab.id, {url: urlSite}); + } + + window.close(); } function getSearchSite() { - var selectedSite; - var site = document.getElementsByName("site"); - for(var i = 0; i < site.length; i++) { - if(site[i].checked) { - selectedSite = site[i].value; - - if (!selectedSite.endsWith('/')) { - selectedSite = selectedSite + '/'; - } - } - } - - return selectedSite; + var selectedSite; + var site = document.getElementsByName("site"); + for(var i = 0; i < site.length; i++) { + if(site[i].checked) { + selectedSite = site[i].value; + + if (!selectedSite.endsWith('/')) { + selectedSite = selectedSite + '/'; + } + } + } + + return selectedSite; } function sortListDir() { - var list, i, switching, b, shouldSwitch, dir, switchcount = 0; - list = document.getElementById("orderedList"); - switching = true; - //Set the sorting direction to ascending: - dir = "asc"; - //Make a loop that will continue until no switching has been done: - while (switching) { - //start by saying: no switching is done: - switching = false; - b = list.getElementsByTagName("LI"); - //Loop through all list-items: - for (i = 0; i < (b.length - 1); i++) { - //start by saying there should be no switching: - shouldSwitch = false; - /*check if the next item should switch place with the current item, - based on the sorting direction (asc or desc):*/ - if (dir == "asc") { - if (b[i].innerText.toLowerCase() > b[i + 1].innerText.toLowerCase()) { - console.log("THE TEXT--" + b[i].innerText); - /*if next item is alphabetically lower than current item, - mark as a switch and break the loop:*/ - shouldSwitch= true; - break; - } - } else if (dir == "desc") { - if (b[i].innerText.toLowerCase() < b[i + 1].innerText.toLowerCase()) { - console.log("THE TEXT--" + b[i].innerText); - /*if next item is alphabetically higher than current item, - mark as a switch and break the loop:*/ - shouldSwitch= true; - break; - } - } + var list, i, switching, b, shouldSwitch, dir, switchcount = 0; + list = document.getElementById("orderedList"); + switching = true; + //Set the sorting direction to ascending: + dir = "asc"; + //Make a loop that will continue until no switching has been done: + while (switching) { + //start by saying: no switching is done: + switching = false; + b = list.getElementsByTagName("LI"); + //Loop through all list-items: + for (i = 0; i < (b.length - 1); i++) { + //start by saying there should be no switching: + shouldSwitch = false; + /*check if the next item should switch place with the current item, + based on the sorting direction (asc or desc):*/ + if (dir == "asc") { + if (b[i].innerText.toLowerCase() > b[i + 1].innerText.toLowerCase()) { + console.log("THE TEXT--" + b[i].innerText); + /*if next item is alphabetically lower than current item, + mark as a switch and break the loop:*/ + shouldSwitch= true; + break; } - if (shouldSwitch) { - /*If a switch has been marked, make the switch - and mark that a switch has been done:*/ - b[i].parentNode.insertBefore(b[i + 1], b[i]); - switching = true; - //Each time a switch is done, increase switchcount by 1: - switchcount ++; - } 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") { - dir = "desc"; - switching = true; - - } + } else if (dir == "desc") { + if (b[i].innerText.toLowerCase() < b[i + 1].innerText.toLowerCase()) { + console.log("THE TEXT--" + b[i].innerText); + /*if next item is alphabetically higher than current item, + mark as a switch and break the loop:*/ + shouldSwitch= true; + break; } + } + } + if (shouldSwitch) { + /*If a switch has been marked, make the switch + and mark that a switch has been done:*/ + b[i].parentNode.insertBefore(b[i + 1], b[i]); + switching = true; + //Each time a switch is done, increase switchcount by 1: + switchcount ++; + } 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") { + dir = "desc"; + switching = true; + + } } - chngSortBtnValue(); + } + chngSortBtnValue(); } function chngSortBtnValue() { - var sortImg = document.getElementById('sortListDir'); - console.log(sortImg.getAttribute('src')); - if (sortImg.getAttribute('src') === "./icons/Small_A_Z.jpg") { - //sortImg.nextSibling.textContent = "Sort Z to A"; - sortImg.setAttribute('src', './icons/Small_Z_A.jpg'); - } else if (sortImg.getAttribute('src') === "./icons/Small_Z_A.jpg") { - //sortImg.nextSibling.textContent = "Sort A to Z"; - sortImg.setAttribute('src', './icons/Small_A_Z.jpg'); - } + var sortImg = document.getElementById('sortListDir'); + console.log(sortImg.getAttribute('src')); + if (sortImg.getAttribute('src') === "./icons/Small_A_Z.jpg") { + //sortImg.nextSibling.textContent = "Sort Z to A"; + sortImg.setAttribute('src', './icons/Small_Z_A.jpg'); + } else if (sortImg.getAttribute('src') === "./icons/Small_Z_A.jpg") { + //sortImg.nextSibling.textContent = "Sort A to Z"; + sortImg.setAttribute('src', './icons/Small_A_Z.jpg'); + } } function searchInSite (queryString) { - var urlSite = ''; - var searchText = document.getElementById('searchTextBox').value; - console.log(searchText); - if (searchText) { - var url = new URL(currentUrl); - - var selectedSite = getSearchSite(); - - if (selectedSite.indexOf('yahoo') > -1) { - urlSite = selectedSite + 'search;?p=' + searchText + '%20site:' + url.hostname; - } else { - urlSite = selectedSite + 'search?q=' + searchText + '%20site:' + url.hostname; - } - - chrome.tabs.update(currentTab.id, {url: urlSite}); - - } - window.close(); + var urlSite = ''; + var searchText = document.getElementById('searchTextBox').value; + console.log(searchText); + if (searchText) { + var url = new URL(currentUrl); + + var selectedSite = getSearchSite(); + + if (selectedSite.indexOf('yahoo') > -1) { + urlSite = selectedSite + 'search;?p=' + searchText + '%20site:' + url.hostname; + } else { + urlSite = selectedSite + 'search?q=' + searchText + '%20site:' + url.hostname; + } + + chrome.tabs.update(currentTab.id, {url: urlSite}); + + } + window.close(); } document.addEventListener('beforeunload', function (event) { - console.log("unload.."); - const allUrls = document.getElementsByName("link"); - var parentNode; - allUrls.forEach (function (url) { - console.log(url.parentNode); - 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); - }); - }); - } - - }); - - - window.close(); + console.log("unload.."); + const allUrls = document.getElementsByName("link"); + var parentNode; + allUrls.forEach (function (url) { + console.log(url.parentNode); + 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); + }); + }); + } + + }); + + + window.close(); }, true); function saveSelection() { - getCurrentTabUrl(function(tab) { - currentUrl = tab.url; - var url = new URL(tab.url); - var fullDomain = url.hostname; - console.log("dom-" + fullDomain); - var name = getDomainName(tab.url); - - chrome.storage.sync.get( "jsonData", function(items) { - console.log(JSON.stringify(items)); - var origObj = items.jsonData; - var prefForDom = getPreferences(fullDomain, name, origObj); - - if (prefForDom) { - if (Array.isArray(prefForDom)) { - const allUrls = document.getElementsByName("link"); - allUrls.forEach (function (url) { - console.log("chkd--" + url.checked); - console.log("val--" + url.value); - console.log(url.labels[0].innerText); - console.log(JSON.stringify(prefForDom)); - console.log(prefForDom.length + "---long"); - var label = url.labels[0].innerText; - //if (label) //need to remove (currentTab from label) - if (label.indexOf("Current Tab")) { - label = label.split('(')[0]; - } - for (var i=0; i < prefForDom.length; i++) { - if (typeof prefForDom[i] === 'object') { - console.log(prefForDom[i]) ; - if (Object.keys(prefForDom[i])[0] === label) { - if (typeof Object.values(prefForDom[i])[0] === 'object') { - prefForDom[i][label]['selected'] = url.checked; - } else { - prefForDom[i][label] = {'selected' : url.checked, url : Object.values(prefForDom[i])[0]}; - } - - } - } else { - if (prefForDom[i] === url.value) { - prefForDom[i] = {[label] : {'selected' : url.checked, url : url.value}}; - } - } - } - console.log(JSON.stringify(prefForDom)); - - }); - } else { - var options = prefForDom; - var type = document.getElementById("typeSelect"); - var selectedType = type.options[type.selectedIndex].value; - - var allTypes = options[selectedType]; - if (Array.isArray(options[selectedType])){ - const allUrls = document.getElementsByName("link"); - - allUrls.forEach (function (url) { - var label = url.labels[0].innerText; - if (label.indexOf("Current Tab")) { - label = label.split('(')[0]; - } - for (var i=0; i < allTypes.length; i++) { - //console.log("vaan" + JSON.stringify(allTypes[i])); - if (typeof allTypes[i] === 'object') { - if (Object.keys(allTypes[i])[0] === label) { - if (typeof Object.values(allTypes[i])[0] === 'object') { - prefForDom[selectedType][i][label]['selected'] = url.checked; - } else { - prefForDom[selectedType][i][label] = {'selected' : url.checked, url : Object.values(allTypes[i])[0]}; - } - - } - } else { - if (allTypes[i] === url.value) { - prefForDom[selectedType][i]= {[label] : {'selected' : url.checked, url : url.value}}; - } - } - } - console.log(JSON.stringify(prefForDom)); - - }); - } - } - } - console.log(JSON.stringify(origObj)); - chrome.storage.sync.set({ - jsonData: origObj}, - function() { - // Update status to let user know options were saved. - var status = document.getElementById('status'); - status.textContent = 'Options saved.'; - setTimeout(function() { - status.textContent = ''; - }, 750); - }); - }); - }); - - /*const allUrls = document.getElementsByName("link"); - var parentNode = allUrls[0].parentNode.parentNode.childNodes; - changeSelection(parentNode);*/ + getCurrentTabUrl(function(tab) { + currentUrl = tab.url; + var url = new URL(tab.url); + var fullDomain = url.hostname; + console.log("dom-" + fullDomain); + var name = getDomainName(tab.url); + + chrome.storage.sync.get( "jsonData", function(items) { + console.log(JSON.stringify(items)); + var origObj = items.jsonData; + var prefForDom = getPreferences(fullDomain, name, origObj); + + if (prefForDom) { + if (Array.isArray(prefForDom)) { + const allUrls = document.getElementsByName("link"); + allUrls.forEach (function (url) { + console.log("chkd--" + url.checked); + console.log("val--" + url.value); + console.log(url.labels[0].innerText); + console.log(JSON.stringify(prefForDom)); + console.log(prefForDom.length + "---long"); + var label = url.labels[0].innerText; + //if (label) //need to remove (currentTab from label) + if (label.indexOf("Current Tab")) { + label = label.split('(')[0]; + } + for (var i=0; i < prefForDom.length; i++) { + if (typeof prefForDom[i] === 'object') { + console.log(prefForDom[i]) ; + if (Object.keys(prefForDom[i])[0] === label) { + if (typeof Object.values(prefForDom[i])[0] === 'object') { + prefForDom[i][label]['selected'] = url.checked; + } else { + prefForDom[i][label] = {'selected' : url.checked, url : Object.values(prefForDom[i])[0]}; + } + + } + } else { + if (prefForDom[i] === url.value) { + prefForDom[i] = {[label] : {'selected' : url.checked, url : url.value}}; + } + } + } + console.log(JSON.stringify(prefForDom)); + + }); + } else { + var options = prefForDom; + var type = document.getElementById("typeSelect"); + var selectedType = type.options[type.selectedIndex].value; + + var allTypes = options[selectedType]; + if (Array.isArray(options[selectedType])){ + const allUrls = document.getElementsByName("link"); + + allUrls.forEach (function (url) { + var label = url.labels[0].innerText; + if (label.indexOf("Current Tab")) { + label = label.split('(')[0]; + } + for (var i=0; i < allTypes.length; i++) { + //console.log("vaan" + JSON.stringify(allTypes[i])); + if (typeof allTypes[i] === 'object') { + if (Object.keys(allTypes[i])[0] === label) { + if (typeof Object.values(allTypes[i])[0] === 'object') { + prefForDom[selectedType][i][label]['selected'] = url.checked; + } else { + prefForDom[selectedType][i][label] = {'selected' : url.checked, url : Object.values(allTypes[i])[0]}; + } + + } + } else { + if (allTypes[i] === url.value) { + prefForDom[selectedType][i]= {[label] : {'selected' : url.checked, url : url.value}}; + } + } + } + console.log(JSON.stringify(prefForDom)); + + }); + } + } + } + console.log(JSON.stringify(origObj)); + chrome.storage.sync.set({ + jsonData: origObj}, + function() { + // Update status to let user know options were saved. + var status = document.getElementById('status'); + status.textContent = 'Options saved.'; + setTimeout(function() { + status.textContent = ''; + }, 750); + }); + }); + }); + + /*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').disabled = true; - document.getElementById("error").innerHTML = ""; - } else { - document.getElementById('openbtn').disabled = false; - } + let txtAreaContent = this.value; + console.log("in txt are" + txtAreaContent); + if (txtAreaContent === '') { + document.getElementById('openbtn').disabled = true; + document.getElementById("error").innerHTML = ""; + } else { + document.getElementById('openbtn').disabled = false; + } } document.addEventListener('DOMContentLoaded', function () { - /* var bgPage = chrome.extension.getBackgroundPage(); - console.log("before"); + /* var bgPage = chrome.extension.getBackgroundPage(); + console.log("before"); var bk = bgPage.test("abc"); // Here paste() is a function that returns value. - console.log("beforeAAA--" + bk);*/ - document.getElementById('mainStuff').hidden = true; - document.getElementById('cancelbtn').addEventListener('click', closeWindow); - document.getElementById('openbtn').addEventListener('click', clickHandler); - document.getElementById('selectall').addEventListener('click', selectall); - document.getElementById('addbtn').addEventListener('click', addUrl); - document.getElementById('savebtn').addEventListener('click', saveSelection); - //document.getElementById('searchAgain').addEventListener('click', searchAgain); - document.getElementById('sortListDir').addEventListener('click', sortListDir); - //document.getElementById('searchbtn').addEventListener('click', searchInSite); - onclick="()"; - console.log("lod--" + loading); - console.log("jsondata--" + jsonData); - var content = document.getElementById('content'); + console.log("beforeAAA--" + bk);*/ + document.getElementById('mainStuff').hidden = true; + document.getElementById('cancelbtn').addEventListener('click', closeWindow); + document.getElementById('openbtn').addEventListener('click', clickHandler); + document.getElementById('selectall').addEventListener('click', selectall); + document.getElementById('addbtn').addEventListener('click', addUrl); + document.getElementById('savebtn').addEventListener('click', saveSelection); + //document.getElementById('searchAgain').addEventListener('click', searchAgain); + document.getElementById('sortListDir').addEventListener('click', sortListDir); + //document.getElementById('searchbtn').addEventListener('click', searchInSite); + 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; - 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); - var fromPage = true; - if (loadFrom === 'config' && searchSite.indexOf(url.hostname) === -1) { - fromPage = false; - } - if (!newtab) { - if (fromPage) { - if (readPage.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').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; - 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 = 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; - } - - - - - 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); - } - } 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 && searchPage) { - document.getElementById('selectall').checked = true; - } - createRadio(content); - //document.getElementById('addbtn').hidden = "hidden"; - const allUrls = document.getElementsByName("link"); - var parentNode = allUrls[0].parentNode.parentNode.childNodes; - changeSelection(parentNode); - } 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);*/ - - } - - - } else { - var mesg = "Bank Page."; - noConfigFound(content, mesg); - } - - - - }); - - 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; + //chrome.storage.sync.set({parentUrl: ""}, function() {}); + 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); + var fromPage = true; + if (loadFrom === 'config' && searchSite.indexOf(url.hostname) === -1) { + fromPage = false; + } + if (!newtab) { + if (fromPage) { + if (readPage.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').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; + 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 = 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; + } + + + + + 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); + } + } 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 && searchPage) { + document.getElementById('selectall').checked = true; + } + createRadio(content); + //document.getElementById('addbtn').hidden = "hidden"; + const allUrls = document.getElementsByName("link"); + var parentNode = allUrls[0].parentNode.parentNode.childNodes; + changeSelection(parentNode); + } 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);*/ + + } + + + } else { + var mesg = "Bank Page."; + noConfigFound(content, mesg); + } + + + + }); + + 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; }); 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(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').disabled = true; - //document.getElementById('cancelbtn').hidden = "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').disabled = false; - } - document.getElementById('anonymus').onkeyup = editTextArea; - - - divTxt.appendChild(pre); - content.appendChild(divTxt); - + 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(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').disabled = true; + //document.getElementById('cancelbtn').hidden = "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').disabled = false; + } + document.getElementById('anonymus').onkeyup = editTextArea; + + + divTxt.appendChild(pre); + content.appendChild(divTxt); + } function createRadio(content) { - //var engDom = getDomain(searchEngine); - //var engine = engDom.split('.')[0]; - //var engineUrl = new URL(searchEngine); - //console.log("url hostname eng-" + engineUrl.hostname); - var engine; - if (searchPage) { - engine = getDomainName(searchEngine); //engineUrl.hostname.split('.')[1]; - } - - 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'); - searchDiv.id = "searchDiv"; - searchDiv.style.margin = "0px 0px 0px 25px"; - searchDiv.style.width = '300px'; - - var searchLbl = document.createElement('label'); - searchLbl.innerHTML = "search in"; - searchLbl.style.marginLeft = "25px"; - searchContent.appendChild(searchLbl); - var br = document.createElement('br'); - searchContent.appendChild(br); - /*var margin = true;*/ - - var both; - - sitesArr.forEach(function (site) { - var url = new URL(site); - console.log("url hostname-" + url.hostname); - var name = getDomainName(site);//url.hostname.split('.')[1]; - //var domain = getDomain(site); - //var name = domain.split('.')[0]; - console.log("name " + name); - console.log("engg " + engine); - if (searchPage && name === engine) { - return; - } - - both = both ? both + "," + site : site; - console.log("both " + both); - var radio = document.createElement("INPUT"); - radio.setAttribute("type", "radio"); - radio.setAttribute("value", site); - radio.setAttribute("name", "site"); - selectAll ? radio.disabled = true : radio.disabled = false; - //radio.setAttribute("id", "site"); - //radio.style.marginLeft = "10px"; - console.log("site " + site); - console.log("eng " + searchEngine); - /*var url = new URL(site); - var fullDomain = url.hostname;*/ - var label = document.createElement("label"); - label.innerHTML = name; - //content.appendChild(radio); - //content.appendChild(label); - searchDiv.appendChild(radio); - searchDiv.appendChild(label); - searchContent.appendChild(searchDiv); - - - }); - - - var searchAgainBtn = document.createElement('input'); - searchAgainBtn.setAttribute("type", "button"); - selectAll ? searchAgainBtn.disabled = true : searchAgainBtn.disabled = false; - if (searchPage) { - var radio = document.createElement("INPUT"); - radio.setAttribute("type", "radio"); - radio.setAttribute("value", both); - radio.setAttribute("name", "site"); - selectAll ? radio.disabled = true : radio.disabled = false; - var label = document.createElement("label"); - label.innerHTML = "Both"; - searchDiv.appendChild(radio); - searchDiv.appendChild(label); - searchAgainBtn.setAttribute("id", "searchAgain"); - searchAgainBtn.setAttribute("value", "Search Again"); - searchAgainBtn.onclick = searchAgain; - } else { - var searchAgainTxt = document.createElement('input'); - searchAgainTxt.setAttribute("type", "text"); - searchAgainTxt.setAttribute("id", "searchTextBox"); - selectAll ? searchAgainTxt.disabled = true : searchAgainTxt.disabled = false; - searchAgainTxt.style.marginLeft = "25px"; - searchDiv.appendChild(searchAgainTxt); - searchAgainBtn.setAttribute("id", "searchbtn"); - searchAgainBtn.setAttribute("value", "Search"); - searchAgainBtn.onclick = searchInSite; - } - searchAgainBtn.style.marginLeft = '2px'; - searchDiv.appendChild(searchAgainBtn); - - searchContent.appendChild(searchDiv); - - /*if (selectAll) { - const allUrls = document.getElementsByName("link"); - if (allUrls.length > -1) { - if (howManyChecked(allUrls[0].parentNode.parentNode.childNodes)) { - //radio.disabled = true; - searchAgainBtn.disabled = true; - document.getElementsByName('site')[0].style.disabled = true; - document.getElementsByName('site')[1].style.disabled = true; - document.getElementsByName('site')[2].style.disabled = true; - if (!searchPage) { - document.getElementById('searchTextBox').style.disabled = true; - } - } - - } - }*/ - - + //var engDom = getDomain(searchEngine); + //var engine = engDom.split('.')[0]; + //var engineUrl = new URL(searchEngine); + //console.log("url hostname eng-" + engineUrl.hostname); + var engine; + if (searchPage) { + engine = getDomainName(searchEngine); //engineUrl.hostname.split('.')[1]; + } + + 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'); + searchDiv.id = "searchDiv"; + searchDiv.style.margin = "0px 0px 0px 25px"; + searchDiv.style.width = '300px'; + + var searchLbl = document.createElement('label'); + searchLbl.innerHTML = "search in"; + searchLbl.style.marginLeft = "25px"; + searchContent.appendChild(searchLbl); + var br = document.createElement('br'); + searchContent.appendChild(br); + /*var margin = true;*/ + + var both; + + sitesArr.forEach(function (site) { + var url = new URL(site); + console.log("url hostname-" + url.hostname); + var name = getDomainName(site);//url.hostname.split('.')[1]; + //var domain = getDomain(site); + //var name = domain.split('.')[0]; + console.log("name " + name); + console.log("engg " + engine); + if (searchPage && name === engine) { + return; + } + + both = both ? both + "," + site : site; + console.log("both " + both); + var radio = document.createElement("INPUT"); + radio.setAttribute("type", "radio"); + radio.setAttribute("value", site); + radio.setAttribute("name", "site"); + selectAll ? radio.disabled = true : radio.disabled = false; + //radio.setAttribute("id", "site"); + //radio.style.marginLeft = "10px"; + console.log("site " + site); + console.log("eng " + searchEngine); + /*var url = new URL(site); + var fullDomain = url.hostname;*/ + var label = document.createElement("label"); + label.innerHTML = name; + //content.appendChild(radio); + //content.appendChild(label); + searchDiv.appendChild(radio); + searchDiv.appendChild(label); + searchContent.appendChild(searchDiv); + + + }); + + + var searchAgainBtn = document.createElement('input'); + searchAgainBtn.setAttribute("type", "button"); + selectAll ? searchAgainBtn.disabled = true : searchAgainBtn.disabled = false; + if (searchPage) { + var radio = document.createElement("INPUT"); + radio.setAttribute("type", "radio"); + radio.setAttribute("value", both); + radio.setAttribute("name", "site"); + selectAll ? radio.disabled = true : radio.disabled = false; + var label = document.createElement("label"); + label.innerHTML = "Both"; + searchDiv.appendChild(radio); + searchDiv.appendChild(label); + searchAgainBtn.setAttribute("id", "searchAgain"); + searchAgainBtn.setAttribute("value", "Search Again"); + searchAgainBtn.onclick = searchAgain; + } else { + var searchAgainTxt = document.createElement('input'); + searchAgainTxt.setAttribute("type", "text"); + searchAgainTxt.setAttribute("id", "searchTextBox"); + selectAll ? searchAgainTxt.disabled = true : searchAgainTxt.disabled = false; + searchAgainTxt.style.marginLeft = "25px"; + searchDiv.appendChild(searchAgainTxt); + searchAgainBtn.setAttribute("id", "searchbtn"); + searchAgainBtn.setAttribute("value", "Search"); + searchAgainBtn.onclick = searchInSite; + } + searchAgainBtn.style.marginLeft = '2px'; + searchDiv.appendChild(searchAgainBtn); + + searchContent.appendChild(searchDiv); + + /*if (selectAll) { + const allUrls = document.getElementsByName("link"); + if (allUrls.length > -1) { + if (howManyChecked(allUrls[0].parentNode.parentNode.childNodes)) { + //radio.disabled = true; + searchAgainBtn.disabled = true; + document.getElementsByName('site')[0].style.disabled = true; + document.getElementsByName('site')[1].style.disabled = true; + document.getElementsByName('site')[2].style.disabled = true; + if (!searchPage) { + document.getElementById('searchTextBox').style.disabled = true; + } + } + + } + }*/ + + } function randomIntFromInterval(min,max) @@ -1171,263 +1178,263 @@ function randomIntFromInterval(min,max) } function getPreferences(url_hostname, name, dataObj) { - if (dataObj === undefined) { - dataObj = jsonData; - } - console.log(url_hostname + " -- " + name ); - let pref;// = []; - for (var item in dataObj) { - let domain; - domain = dataObj[item]['current']; - console.log("DOMAIN--" + domain); - if (domain.indexOf(',') === -1) { - console.log("in no comma"); - //pref = []; - //if (domain === url_hostname || domain === name) { - if (domain.indexOf(url_hostname) > -1 || domain.indexOf(name) > -1) { - console.log("name matched....") - if (domain.indexOf('http://') !== -1) { - baseUrl = domain; - } else { - baseUrl = 'http://' + domain; - } - var sites = dataObj[item]['sites']; - pref = sites; - console.log("sites--" + sites); - } - console.log("in get pref " + JSON.stringify(pref)); - } else { - var domArr = domain.split(','); - domArr.forEach(function(hostname){ - if (url_hostname === hostname || name === hostname) { - pref = dataObj[item]['sites']; - } - }); - console.log("in get pref " + pref); - } - } - console.log(pref); - return pref; - -} + if (dataObj === undefined) { + dataObj = jsonData; + } + console.log(url_hostname + " -- " + name ); + let pref;// = []; + for (var item in dataObj) { + let domain; + domain = dataObj[item]['current']; + console.log("DOMAIN--" + domain); + if (domain.indexOf(',') === -1) { + console.log("in no comma"); + //pref = []; + //if (domain === url_hostname || domain === name) { + if (domain.indexOf(url_hostname) > -1 || domain.indexOf(name) > -1) { + console.log("name matched....") + if (domain.indexOf('http://') !== -1) { + baseUrl = domain; + } else { + baseUrl = 'http://' + domain; + } + var sites = dataObj[item]['sites']; + pref = sites; + console.log("sites--" + sites); + } + console.log("in get pref " + JSON.stringify(pref)); + } else { + var domArr = domain.split(','); + domArr.forEach(function(hostname){ + if (url_hostname === hostname || name === hostname) { + pref = dataObj[item]['sites']; + } + }); + console.log("in get pref " + pref); + } + } + console.log(pref); + return pref; + +} function createList(allurls) { - - var list = document.createElement("OL"); - list.setAttribute("type", "1"); - list.setAttribute("id", "orderedList"); - //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)); - //console.log(Object.values(page)); - var input = document.createElement("INPUT"); - input.setAttribute("type", "checkbox"); - var label = document.createElement('label'); - - 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); - }); - }); - } - - } 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); - }); - }); - } - } else { - console.log("llll" + label.getText); - } - } - - key = Object.keys(page)[0]; - } else { - var pageParts = page.split('/'); - console.log(pageParts.length); - console.log(pageParts[pageParts.length - 1] ); - linkObj = page; - if (linkObj.indexOf("http") === -1) { - linkObj = baseUrl + linkObj; - } - key = page.endsWith('/') ? pageParts[pageParts.length - 2] : pageParts[pageParts.length - 1]; - input.setAttribute("value", 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); - } - - } - input.setAttribute("name", "link"); - if (currentUrl === linkObj) { - key = key + "(Current Tab)"; - console.log("kkk"+key); - document.getElementById('addbtn').disabled = true; - } - var id = key; //Object.keys(page)[0]; - input.setAttribute("id", id); - input.onclick = chkBoxClick; - label.htmlFor = id; - - console.log("linkObj--" + linkObj); - console.log("currentUrl--" + currentUrl); - - - //var linkObj = Object.values(page)[0]; - - - - var li = document.createElement("LI"); - li.style.backgroundColor = bgColor; - if (searchPage) - li.style.margin = "10px 0"; - - //li.setAttribute("background-color" , "#FFFEEC"); - var logo = document.createElement("IMG"); - console.log("link " + Object.values(page)[0]); - logo.setAttribute("src", 'chrome://favicon/'+ linkObj); //Object.values(page)[0]); - logo.setAttribute("width", "20"); - logo.setAttribute("height", "12"); - - var link = document.createElement('a'); - link.textContent = id; - link.href = linkObj; //Object.values(page)[0]; - link.title = linkObj; - link.onclick = linkClick; - label.appendChild(link); - - - list.appendChild(li); - li.appendChild(input); - li.appendChild(logo); - li.appendChild(label); - //list.appendChild(input); - //list.appendChild(logo); - //list.appendChild(label); - //var line = document.createElement('br'); - //list.appendChild(line); - if (bgColor === "#EDEEED") {//ECF0F1 //"#F4F6F7" - bgColor = "#FFFFFF"; - } else { - bgColor = "#EDEEED"; //"#F4F6F7"; - } - }); - /*var howmany = document.getElementById("howmany"); - if (selectAll) { - howmany.textContent = allurls.length + " selected."; - } else { - howmany.textContent = "0 selected."; - }*/ - return list; - - + + var list = document.createElement("OL"); + list.setAttribute("type", "1"); + list.setAttribute("id", "orderedList"); + //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)); + //console.log(Object.values(page)); + var input = document.createElement("INPUT"); + input.setAttribute("type", "checkbox"); + var label = document.createElement('label'); + + 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); + }); + }); + } + + } 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); + }); + }); + } + } else { + console.log("llll" + label.getText); + } + } + + key = Object.keys(page)[0]; + } else { + var pageParts = page.split('/'); + console.log(pageParts.length); + console.log(pageParts[pageParts.length - 1] ); + linkObj = page; + if (linkObj.indexOf("http") === -1) { + linkObj = baseUrl + linkObj; + } + key = page.endsWith('/') ? pageParts[pageParts.length - 2] : pageParts[pageParts.length - 1]; + input.setAttribute("value", 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); + } + + } + input.setAttribute("name", "link"); + if (currentUrl === linkObj) { + key = key + "(Current Tab)"; + console.log("kkk"+key); + document.getElementById('addbtn').disabled = true; + } + var id = key; //Object.keys(page)[0]; + input.setAttribute("id", id); + input.onclick = chkBoxClick; + label.htmlFor = id; + + console.log("linkObj--" + linkObj); + console.log("currentUrl--" + currentUrl); + + + //var linkObj = Object.values(page)[0]; + + + + var li = document.createElement("LI"); + li.style.backgroundColor = bgColor; + if (searchPage) + li.style.margin = "10px 0"; + + //li.setAttribute("background-color" , "#FFFEEC"); + var logo = document.createElement("IMG"); + console.log("link " + Object.values(page)[0]); + logo.setAttribute("src", 'chrome://favicon/'+ linkObj); //Object.values(page)[0]); + logo.setAttribute("width", "20"); + logo.setAttribute("height", "12"); + + var link = document.createElement('a'); + link.textContent = id; + link.href = linkObj; //Object.values(page)[0]; + link.title = linkObj; + link.onclick = linkClick; + label.appendChild(link); + + + list.appendChild(li); + li.appendChild(input); + li.appendChild(logo); + li.appendChild(label); + //list.appendChild(input); + //list.appendChild(logo); + //list.appendChild(label); + //var line = document.createElement('br'); + //list.appendChild(line); + if (bgColor === "#EDEEED") {//ECF0F1 //"#F4F6F7" + bgColor = "#FFFFFF"; + } else { + bgColor = "#EDEEED"; //"#F4F6F7"; + } + }); + /*var howmany = document.getElementById("howmany"); + if (selectAll) { + howmany.textContent = allurls.length + " selected."; + } else { + howmany.textContent = "0 selected."; + }*/ + return list; + + } function selectOption() { - var content = document.getElementById('content'); - var orderedList = document.getElementById('orderedList'); - if (orderedList) { - content.removeChild(orderedList); - } - - var type = document.getElementById("typeSelect"); - var selectedType = type.options[type.selectedIndex].value; - - //var allTypes = jsonData[type.name]; - var url = new URL(currentUrl); + var content = document.getElementById('content'); + var orderedList = document.getElementById('orderedList'); + if (orderedList) { + content.removeChild(orderedList); + } + + var type = document.getElementById("typeSelect"); + var selectedType = type.options[type.selectedIndex].value; + + //var allTypes = jsonData[type.name]; + var url = new URL(currentUrl); //var allTypes = jsonData[url.hostname] || jsonData[type.name]; - var allTypes = getPreferences(url.hostname, type.name); //jsonData[url.hostname] || jsonData[name]; - if (Array.isArray(allTypes[selectedType])){ - content.appendChild(createList(allTypes[selectedType])); - } - const allUrls = document.getElementsByName("link"); - var parentNode = allUrls[0].parentNode.parentNode.childNodes; - changeSelection(parentNode); - + var allTypes = getPreferences(url.hostname, type.name); //jsonData[url.hostname] || jsonData[name]; + if (Array.isArray(allTypes[selectedType])){ + content.appendChild(createList(allTypes[selectedType])); + } + const allUrls = document.getElementsByName("link"); + var parentNode = allUrls[0].parentNode.parentNode.childNodes; + changeSelection(parentNode); + } function createDropDown (data, hierarchy) { - var dropDown = document.createElement("SELECT"); - dropDown.setAttribute("id", "typeSelect"); - dropDown.setAttribute("name", hierarchy); - var keys = Object.keys(data); - keys.forEach(function (optn) { - var options = document.createElement("option"); - options.setAttribute("value", optn); - options.setAttribute("id", optn); - var txt = document.createTextNode(optn); - options.appendChild(txt); - if (optn.indexOf("default") > -1) { - options.selected = true; - } - dropDown.appendChild(options); - }); - dropDown.onchange = selectOption; - return dropDown; - + var dropDown = document.createElement("SELECT"); + dropDown.setAttribute("id", "typeSelect"); + dropDown.setAttribute("name", hierarchy); + var keys = Object.keys(data); + keys.forEach(function (optn) { + var options = document.createElement("option"); + options.setAttribute("value", optn); + options.setAttribute("id", optn); + var txt = document.createTextNode(optn); + options.appendChild(txt); + if (optn.indexOf("default") > -1) { + options.selected = true; + } + dropDown.appendChild(options); + }); + dropDown.onchange = selectOption; + return dropDown; + } - + function getDomain(url, subdomain) { - //var isSubdom = isSubdomain(url); - subdomain = subdomain || false; + //var isSubdom = isSubdomain(url); + subdomain = subdomain || false; url = url.replace(/(https?:\/\/)?(www.)?/i, ''); @@ -1446,85 +1453,85 @@ function getDomain(url, subdomain) { } function getCurrentTabUrl(callback) { - var queryInfo = { - active: true, - currentWindow: true - }; - - chrome.tabs.query(queryInfo, function(tabs) { - - var tab = tabs[0]; - //var url = tab.url; - currentTab = tab; - callback(tab); - }); - - chrome.windows.getCurrent(function(currentWindow) { - invokedWindow = currentWindow.id; - }); - -} - -function utubeClick() { - var idx = currentTab.index + 1; - chrome.tabs.create({url: this.href, active : false, index: idx, windowId : invokedWindow}, function(tab) { + var queryInfo = { + active: true, + currentWindow: true + }; + + chrome.tabs.query(queryInfo, function(tabs) { + + var tab = tabs[0]; + //var url = tab.url; +currentTab = tab; + callback(tab); + }); + + chrome.windows.getCurrent(function(currentWindow) { + invokedWindow = currentWindow.id; + }); - }); } -function isParentGoogle(parentUrl) { - // var url = new URL(parentUrl); - // console.log("azhagiye...." + url.hostname); - //return google.indexOf(url.hostname) > -1; -} - -function isFromSearch(currentURL) { - //console.log("Check1 " + JSON.stringify(googleSearch)); - console.log("Check22 " + currentURL); - var urlFound = false; - if (googleSearch) { - googleSearch.forEach(function (obj) { - var value = Object.values(obj); - console.log("Check3 " + value); - if (value == currentURL) { - console.log("ret true"); - urlFound = true; - } - }); - } - return urlFound; -} - -function getDomainName(url) { - var hostname = new URL(url).hostname; - var hostArr = hostname.split('.'); - console.log(hostArr.length + "---yyy"); - console.log(hostArr); - if (hostArr.length === 2) { - return hostArr[0]; - } else if (hostArr.length === 4) { - if (hostArr[0] === 'www') { - return hostArr[1]; - } else { - return hostArr[2]; - } - } else { - return hostArr[1]; - } -} - -function isUrlInList(currentURL, urlList) { - //console.log("Check1 " + JSON.stringify(googleSearch)); - console.log("Check22 " + currentURL); - var urlFound = false; - - urlList.forEach(function (obj) { - var value = Object.values(obj); - console.log("Check3 " + value); - if (value == currentURL) { - console.log("ret true"); - urlFound = true; - } - }); - - return urlFound; -} \ No newline at end of file + + function utubeClick() { + var idx = currentTab.index + 1; + chrome.tabs.create({url: this.href, active : false, index: idx, windowId : invokedWindow}, function(tab) { + + }); + } + function isParentGoogle(parentUrl) { + // var url = new URL(parentUrl); + // console.log("azhagiye...." + url.hostname); + //return google.indexOf(url.hostname) > -1; + } + + function isFromSearch(currentURL) { + //console.log("Check1 " + JSON.stringify(googleSearch)); + console.log("Check22 " + currentURL); + var urlFound = false; + if (googleSearch) { + googleSearch.forEach(function (obj) { + var value = Object.values(obj); + console.log("Check3 " + value); + if (value == currentURL) { + console.log("ret true"); + urlFound = true; + } + }); + } + return urlFound; + } + + function getDomainName(url) { + var hostname = new URL(url).hostname; + var hostArr = hostname.split('.'); + console.log(hostArr.length + "---yyy"); + console.log(hostArr); + if (hostArr.length === 2) { + return hostArr[0]; + } else if (hostArr.length === 4) { + if (hostArr[0] === 'www') { + return hostArr[1]; + } else { + return hostArr[2]; + } + } else { + return hostArr[1]; + } + } + + function isUrlInList(currentURL, urlList) { + //console.log("Check1 " + JSON.stringify(googleSearch)); + console.log("Check22 " + currentURL); + var urlFound = false; + + urlList.forEach(function (obj) { + var value = Object.values(obj); + console.log("Check3 " + value); + if (value == currentURL) { + console.log("ret true"); + urlFound = true; + } + }); + + return urlFound; + } \ No newline at end of file From 79404304ffbf393969ad0f8bf2790771dcfa1e64 Mon Sep 17 00:00:00 2001 From: Gautam Date: Mon, 1 Jan 2018 18:32:37 -0600 Subject: [PATCH 3/8] Modified popup.js, background.js etc for fixes. --- content_script.js | 519 ++++++-- manifest.json | 34 +- options.html | 4 +- options.js | 12 +- popup.js | 2962 ++++++++++++++++++++++++--------------------- 5 files changed, 2011 insertions(+), 1520 deletions(-) diff --git a/content_script.js b/content_script.js index 5730347..326a56c 100644 --- a/content_script.js +++ b/content_script.js @@ -2,113 +2,426 @@ var jsonObj = {}; //jsonObj["current"] = "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; + /*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; + 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; + /*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; + /*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; + 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) { + 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'); + 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; + /*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)); + jsonObj['washingtonpost'] = sites; + console.log("Final object...\n" + 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); - } + } + 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.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 -}); -//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); - } +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..'); + });*/ +} + + + + +/* -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); @@ -119,13 +432,14 @@ 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)); -console.log("queryStr--" + queryString); -chrome.storage.local.set({'googleSearch': "", 'queryString' : "", 'searchEngine' : ""}, function() {}); -//chrome.storage.sync.StorageArea.remove(['googleSearch', 'queryString', 'searchEngine']); -chrome.storage.local.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 () { @@ -148,15 +462,21 @@ $('a').each(function(index){ }); //console.log("showing..\n" + urlArr); -//chrome.runtime.sendMessage({todo: "show_text"}); + chrome.runtime.onMessage.addListener(function(req, sender, sendres){ + 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') { @@ -279,5 +599,4 @@ function highlightTextYT(selectedItems, highlight) { } }); - } \ No newline at end of file diff --git a/manifest.json b/manifest.json index 1ec98df..7907c7a 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,16 +34,26 @@ } } }, - "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/"], - "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://wwww.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 0a43856..fb3c2da 100644 --- a/options.html +++ b/options.html @@ -53,11 +53,11 @@ Tabs to load at a time
- Load from: Configuration + diff --git a/options.js b/options.js index b059eb1..fb220b0 100644 --- a/options.js +++ b/options.js @@ -9,7 +9,7 @@ function save_options() { 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 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() === '') { @@ -47,8 +47,7 @@ function save_options() { highlightTabs: highlightTabs, selectAll: selectAll, timeOut : timeOut, - tabToLoad : tabToLoad, - loadFrom : loadFrom}, + tabToLoad : tabToLoad}, function() { // Update status to let user know options were saved. var status = document.getElementById('status'); @@ -286,20 +285,19 @@ function restore_options() { highlightTabs: true, selectAll: true, timeOut: 30, - tabToLoad : 2, - loadFrom : "config" + 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; - alert(items.loadFrom); + /*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; diff --git a/popup.js b/popup.js index 798bc7c..5256219 100644 --- a/popup.js +++ b/popup.js @@ -17,1159 +17,1277 @@ var baseUrl; var anonymus; var newtab; var loadFrom; -var options = ['tabsBackground', 'highlightTabs', 'jsonData', 'selectAll', 'loading', 'googleSearch', 'parentUrl', 'queryString', 'searchEngine', 'anonymus', 'loadFrom']; -var readPage = ['www.google.co.in', 'www.google.com', 'search.yahoo.com', 'www.bing.com', 'www.youtube.com', 'edition.cnn.com']; -var searchSite= ['google', 'yahoo', 'bing', 'youtube']; - +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']; +var dualSetting = ['cnn', 'stackoverflow']; +var cnnLoading = "loading"; chrome.storage.sync.get( options, function(items) { - jsonData = items.jsonData; - highlightTabs = items.highlightTabs; - tabsBackground = items.tabsBackground; - selectAll = items.selectAll; - loading = items.loading; - console.log("in sync get" + loading); - //googleSearch = items.googleSearch; - //console.log("in sync get search--" + googleSearch); - parentUrl = items.parentUrl; - //queryString = items.queryString; - //searchSites = items.searchSites; - //searchEngine = items.searchEngine; - anonymus = items.anonymus; - loadFrom = items.loadFrom; + jsonData = items.jsonData; + highlightTabs = items.highlightTabs; + tabsBackground = items.tabsBackground; + selectAll = items.selectAll; + loading = items.loading; + console.log("in sync get" + loading); + //googleSearch = items.googleSearch; + //console.log("in sync get search--" + googleSearch); + parentUrl = items.parentUrl; + //queryString = items.queryString; + //searchSites = items.searchSites; + //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; + googleSearch = items.googleSearch; + console.log("in sync get search--" + googleSearch); + queryString = items.queryString; + // searchEngine = items.searchEngine; }); function closeWindow (e) { - const allUrls = document.getElementsByName("link"); - var parentNode; - allUrls.forEach (function (url) { - console.log(url.parentNode); - 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); - }); - }); - } - - }); - - - window.close(); + const allUrls = document.getElementsByName("link"); + var parentNode; + allUrls.forEach (function (url) { + console.log(url.parentNode); + 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); + }); + }); + } + + }); + + + window.close(); } function clickHandler(e) { - //loading = true; - const allUrls = document.getElementsByName("link"); - const urlsToOpen = []; - const tabToHilite = [currentTab.index]; - const openAt = currentTab.index + 1; - var anonymusValues; - try { - 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 { - 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; - } - - - console.log(urlsToOpen); - /*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 : anonymusValues}, function() { - if (chrome.runtime.error) { - console.log("Runtime error."); - } - }); - window.close(); + //loading = true; + document.getElementById("openbtn").disabled = true; + const allUrls = document.getElementsByName("link"); + const urlsToOpen = []; + const tabToHilite = [currentTab.index]; + const openAt = currentTab.index + 1; + var anonymusValues; + try { + 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 { + 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; + } + + + console.log(urlsToOpen); + /*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 : anonymusValues}, function() { + if (chrome.runtime.error) { + console.log("Runtime error."); + } + }); + window.close(); } function selectall () { - const allUrls = document.getElementsByName("link"); - 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").disabled = true; - document.getElementById("sametabChkbx").checked = false; - } - - console.log("kkkkkk-" + url.value); - var itemValue = url.value; - if (searchPage) { - 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); - }); - }); - } - - }); - - /* - var howmany = document.getElementById("howmany"); - var selNums = howManyChecked(parentNode); - howmany.textContent = selNums + " selected."; - if (selNums > 0) { - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = true; - } - - if (document.getElementById('searchbtn')) { - 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; - }*/ - } 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").disabled = true; - document.getElementById("sametabChkbx").checked = false; - 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); - }); - }); - } - - }); - /*var howmany = document.getElementById("howmany"); - howmany.textContent = "0 selected."; - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = false; - } - - if (document.getElementById('searchbtn')) { - 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; */ - //document.getElementById('searchAgain').disabled = false; - } - - changeSelection(parentNode); + const allUrls = document.getElementsByName("link"); + 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").disabled = true; + document.getElementById("sametabChkbx").checked = false; + } + + console.log("kkkkkk-" + url.value); + var itemValue = url.value; + if (searchPage) { + 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); + }); + }); + } + + }); + + /* + var howmany = document.getElementById("howmany"); + var selNums = howManyChecked(parentNode); + howmany.textContent = selNums + " selected."; + if (selNums > 0) { + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = true; + } + + if (document.getElementById('searchbtn')) { + 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; + }*/ + } 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").disabled = true; + document.getElementById("sametabChkbx").checked = false; + 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); + }); + }); + } + + }); + /*var howmany = document.getElementById("howmany"); + howmany.textContent = "0 selected."; + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = false; + } + + if (document.getElementById('searchbtn')) { + 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; */ + //document.getElementById('searchAgain').disabled = false; + } + + changeSelection(parentNode); } function linkClick () { - console.log(this.href); - const opnSmeTab = document.getElementById("sametabChkbx").checked; - chrome.storage.sync.set({urlsToOpen: [], currTab : "", invokedWindow : "", opnSmeTb : "", loading: false}, function() {}); - chrome.storage.sync.set({urlsToOpen: this.href, currTab: currentTab, invokedWindow: invokedWindow, opnSmeTb: opnSmeTab, loading : true}, function() { - if (chrome.runtime.error) { - console.log("Runtime error."); - } - }); - window.close(); + console.log(this.href); + const opnSmeTab = document.getElementById("sametabChkbx").checked; + chrome.storage.sync.set({urlsToOpen: [], currTab : "", invokedWindow : "", opnSmeTb : "", loading: false}, function() {}); + chrome.storage.sync.set({urlsToOpen: this.href, currTab: currentTab, invokedWindow: invokedWindow, opnSmeTb: opnSmeTab, loading : true}, function() { + if (chrome.runtime.error) { + console.log("Runtime error."); + } + }); + window.close(); } function chkBoxClick (ele) { - console.log(this.labels[0].innerHTML); - var currNode = this; - var none = true; - var selectedArray = []; - if (this.checked) { - this.labels[0].style.fontWeight = "bold"; - document.getElementById("openbtn").disabled = false; - //var liList = this.parentNode.parentNode.childNodes; - //console.log(liList.length); - - this.parentNode.parentNode.childNodes.forEach(function (li){ - if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { - none = false; - return; - } - - }); - if (none) { - console.log("only one"); - document.getElementById("sametab").disabled = false; - document.getElementById("sametabChkbx").checked = true; - } else { - document.getElementById("sametab").disabled = true; - document.getElementById("sametabChkbx").checked = false; - } - - console.log("li value-" + this.value); - /*selectedArray.push(this.value); - this.parentNode.parentNode.childNodes.forEach(function (li){ - if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { - selectedArray.push(li.childNodes[0].value); - } - });*/ - var itemValue = this.value; - if (searchPage) { - 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 (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = true; - } - - if (document.getElementById('searchbtn')) { - 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; - //document.getElementById('searchAgain').disabled = true; - } else { - this.labels[0].style.fontWeight="normal"; - document.getElementById("openbtn").disabled = 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").disabled = true; - document.getElementById("sametabChkbx").checked = false; - } else { - document.getElementById("sametab").disabled = false; - document.getElementById("sametabChkbx").checked = true; - } - - var selItems = this.value; - if (searchPage) { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { - 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); + console.log(this.labels[0].innerHTML); + var currNode = this; + var none = true; + var selectedArray = []; + if (this.checked) { + this.labels[0].style.fontWeight = "bold"; + document.getElementById("openbtn").disabled = false; + //var liList = this.parentNode.parentNode.childNodes; + //console.log(liList.length); + + this.parentNode.parentNode.childNodes.forEach(function (li){ + if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { + none = false; + return; + } + + }); + if (none) { + console.log("only one"); + document.getElementById("sametab").disabled = false; + document.getElementById("sametabChkbx").checked = true; + } else { + document.getElementById("sametab").disabled = true; + document.getElementById("sametabChkbx").checked = false; + } + + console.log("li value-" + this.value); + /*selectedArray.push(this.value); + this.parentNode.parentNode.childNodes.forEach(function (li){ + if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { + selectedArray.push(li.childNodes[0].value); + } + });*/ + var itemValue = this.value; + if (searchPage) { + 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 (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = true; + } + + if (document.getElementById('searchbtn')) { + 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; + //document.getElementById('searchAgain').disabled = true; + } else { + this.labels[0].style.fontWeight="normal"; + document.getElementById("openbtn").disabled = 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").disabled = true; + document.getElementById("sametabChkbx").checked = false; + } else { + document.getElementById("sametab").disabled = false; + document.getElementById("sametabChkbx").checked = true; + } + + var selItems = this.value; + if (searchPage) { + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + 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(listNodes); - console.log(listNodes.length + "***" + selNums); - howmany.textContent = selNums + " selected."; - if (selNums === 0) { - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = false; - } - - if (document.getElementById('searchbtn')) { - 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; - //document.getElementById('searchAgain').disabled = false; - } else { - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = true; - } - - if (document.getElementById('searchbtn')) { - 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; - //document.getElementById('searchAgain').disabled = true; - } - console.log("selected--" + selNums + "--list len--" + listNodes.length); - if (selNums < listNodes.length) { - document.getElementById('selectall').checked = false; - } - if (selNums === listNodes.length) { - document.getElementById('selectall').checked = true; - } + + var howmany = document.getElementById("howmany"); + var selNums = howManyChecked(listNodes); + console.log(listNodes.length + "***" + selNums); + howmany.textContent = selNums + " selected."; + if (selNums === 0) { + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = false; + } + + if (document.getElementById('searchbtn')) { + 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; + //document.getElementById('searchAgain').disabled = false; + } else { + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = true; + } + + if (document.getElementById('searchbtn')) { + 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; + //document.getElementById('searchAgain').disabled = true; + } + console.log("selected--" + selNums + "--list len--" + listNodes.length); + if (selNums < listNodes.length) { + document.getElementById('selectall').checked = false; + } + if (selNums === listNodes.length) { + document.getElementById('selectall').checked = true; + } } function howManyChecked(liNodes) { - var chked = 0; - liNodes.forEach (function (liNode){ - if (liNode.childNodes[0].checked) { - chked ++; - } - }); - return chked; + var chked = 0; + liNodes.forEach (function (liNode){ + if (liNode.childNodes[0].checked) { + chked ++; + } + }); + return chked; } function atleastOneChecked(liNodes) { - var chked = false; - liNodes.forEach (function (liNode){ - if (liNode.childNodes[0].checked) { - chked = true; - } - }); - - return chked; - - /*console.log(Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked)); - return Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked);*/ + var chked = false; + liNodes.forEach (function (liNode){ + if (liNode.childNodes[0].checked) { + chked = true; + } + }); + + return chked; + + /*console.log(Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked)); + return Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked);*/ } function moreThanOneChecked(liNodes) { - var n = 0; - liNodes.forEach (function (liNode){ - if (liNode.childNodes[0].checked) { - n ++; - } - }); - if (n === 0 || n > 1 ) { - return true; - } else { - return false; - } + var n = 0; + liNodes.forEach (function (liNode){ + if (liNode.childNodes[0].checked) { + n ++; + } + }); + if (n === 0 || n > 1 ) { + return true; + } else { + return false; + } } function addUrl() { - getCurrentTabUrl(function(tab) { - currentUrl = tab.url; - 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 = 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; - //alert("before" + JSON.stringify(origObj)); - /*var prefForDom = origObj[fullDomain]; - if (prefForDom === undefined) { - prefForDom = origObj[name]; - }*/ - //var prefForDom = origObj[fullDomain] || origObj[name]; - var prefForDom = getPreferences(fullDomain, name, origObj); - console.log("==" + prefForDom + "--- llllllll"); - var newEntryObj = {}; - var path = url.pathname.split('/'); - 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; - key = path[path.length-1]; - } else { - //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 { - var options = prefForDom; - var type = document.getElementById("typeSelect"); - var selectedType = type.options[type.selectedIndex].value; - - var allTypes = options[selectedType]; - if (Array.isArray(options[selectedType])){ - options[selectedType].push(newEntryObj); - } - } - - - } else { - console.log('in else'); - //origObj[name] = [currentUrl]; - var newObj = {}; - newObj["current"] = name; - newObj["description"] = name; - newObj["sites"] = newObjArr; //[newEntryObj]; - origObj[name] = newObj; - } - //origObj[name] = [currentUrl]; - console.log(JSON.stringify(origObj)); - //jsonObj = items; - //console.log(JSON.stringify(jsonObj)); - chrome.storage.sync.set({ - jsonData: origObj}, - function() { - // Update status to let user know options were saved. - var status = document.getElementById('status'); - status.textContent = 'Options saved.'; - setTimeout(function() { - status.textContent = ''; - }, 750); - }); - }); - }); + getCurrentTabUrl(function(tab) { + currentUrl = tab.url; + 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 = 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; + //alert("before" + JSON.stringify(origObj)); + /*var prefForDom = origObj[fullDomain]; + if (prefForDom === undefined) { + prefForDom = origObj[name]; + }*/ + //var prefForDom = origObj[fullDomain] || origObj[name]; + var prefForDom = getPreferences(fullDomain, name, origObj); + console.log("==" + prefForDom + "--- llllllll"); + var newEntryObj = {}; + var path = url.pathname.split('/'); + 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; + key = path[path.length-1]; + } else { + //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 { + var options = prefForDom; + var type = document.getElementById("typeSelect"); + var selectedType = type.options[type.selectedIndex].value; + + var allTypes = options[selectedType]; + if (Array.isArray(options[selectedType])){ + options[selectedType].push(newEntryObj); + } + } + + + } else { + console.log('in else'); + //origObj[name] = [currentUrl]; + var newObj = {}; + newObj["current"] = name; + newObj["description"] = name; + newObj["sites"] = newObjArr; //[newEntryObj]; + origObj[name] = newObj; + } + //origObj[name] = [currentUrl]; + console.log(JSON.stringify(origObj)); + //jsonObj = items; + //console.log(JSON.stringify(jsonObj)); + chrome.storage.sync.set({ + jsonData: origObj}, + 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 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; + //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 = ''; - var selectedSite = getSearchSite(); - var selSiteArr; - var idx = currentTab.index + 1; - if (selectedSite.indexOf(',') > -1) { - selSiteArr = selectedSite.split(','); - selSiteArr.forEach(function(selSite){ - if (selSite.indexOf('yahoo') > -1) { - urlSite = selSite + 'search;?p=' + queryString; - } else { - urlSite = selSite + 'search?q=' + queryString; - } - - chrome.tabs.create({url: urlSite, active : false, index: parseInt(idx), windowId : invokedWindow}, function(tab) { - idx ++; - }); - }); - } else { - if (selectedSite.indexOf('yahoo') > -1) { - urlSite = selectedSite + 'search;?p=' + queryString; - } else { - urlSite = selectedSite + 'search?q=' + queryString; - } - chrome.tabs.create({url: urlSite, active : false, index: parseInt(currentTab.index + 1), windowId : invokedWindow}, function(tab) { - - }); - //chrome.tabs.update(currentTab.id, {url: urlSite}); - } - - window.close(); + var urlSite = ''; + var selectedSite = getSearchSite(); + var selSiteArr; + var idx = currentTab.index + 1; + if (selectedSite.indexOf(',') > -1) { + selSiteArr = selectedSite.split(','); + selSiteArr.forEach(function(selSite){ + if (selSite.indexOf('yahoo') > -1) { + urlSite = selSite + 'search;?p=' + queryString; + } else { + urlSite = selSite + 'search?q=' + queryString; + } + + chrome.tabs.create({url: urlSite, active : false, index: parseInt(idx), windowId : invokedWindow}, function(tab) { + idx ++; + }); + }); + } else { + if (selectedSite.indexOf('yahoo') > -1) { + urlSite = selectedSite + 'search;?p=' + queryString; + } else { + urlSite = selectedSite + 'search?q=' + queryString; + } + chrome.tabs.create({url: urlSite, active : false, index: parseInt(currentTab.index + 1), windowId : invokedWindow}, function(tab) { + + }); + //chrome.tabs.update(currentTab.id, {url: urlSite}); + } + + window.close(); } function getSearchSite() { - var selectedSite; - var site = document.getElementsByName("site"); - for(var i = 0; i < site.length; i++) { - if(site[i].checked) { - selectedSite = site[i].value; - - if (!selectedSite.endsWith('/')) { - selectedSite = selectedSite + '/'; - } - } - } - - return selectedSite; + var selectedSite; + var site = document.getElementsByName("site"); + for(var i = 0; i < site.length; i++) { + if(site[i].checked) { + selectedSite = site[i].value; + + if (!selectedSite.endsWith('/')) { + selectedSite = selectedSite + '/'; + } + } + } + + return selectedSite; } function sortListDir() { - var list, i, switching, b, shouldSwitch, dir, switchcount = 0; - list = document.getElementById("orderedList"); - switching = true; - //Set the sorting direction to ascending: - dir = "asc"; - //Make a loop that will continue until no switching has been done: - while (switching) { - //start by saying: no switching is done: - switching = false; - b = list.getElementsByTagName("LI"); - //Loop through all list-items: - for (i = 0; i < (b.length - 1); i++) { - //start by saying there should be no switching: - shouldSwitch = false; - /*check if the next item should switch place with the current item, - based on the sorting direction (asc or desc):*/ - if (dir == "asc") { - if (b[i].innerText.toLowerCase() > b[i + 1].innerText.toLowerCase()) { - console.log("THE TEXT--" + b[i].innerText); - /*if next item is alphabetically lower than current item, - mark as a switch and break the loop:*/ - shouldSwitch= true; - break; + var list, i, switching, b, shouldSwitch, dir, switchcount = 0; + list = document.getElementById("orderedList"); + switching = true; + //Set the sorting direction to ascending: + dir = "asc"; + //Make a loop that will continue until no switching has been done: + while (switching) { + //start by saying: no switching is done: + switching = false; + b = list.getElementsByTagName("LI"); + //Loop through all list-items: + for (i = 0; i < (b.length - 1); i++) { + //start by saying there should be no switching: + shouldSwitch = false; + /*check if the next item should switch place with the current item, + based on the sorting direction (asc or desc):*/ + if (dir == "asc") { + if (b[i].innerText.toLowerCase() > b[i + 1].innerText.toLowerCase()) { + console.log("THE TEXT--" + b[i].innerText); + /*if next item is alphabetically lower than current item, + mark as a switch and break the loop:*/ + shouldSwitch= true; + break; + } + } else if (dir == "desc") { + if (b[i].innerText.toLowerCase() < b[i + 1].innerText.toLowerCase()) { + console.log("THE TEXT--" + b[i].innerText); + /*if next item is alphabetically higher than current item, + mark as a switch and break the loop:*/ + shouldSwitch= true; + break; + } + } } - } else if (dir == "desc") { - if (b[i].innerText.toLowerCase() < b[i + 1].innerText.toLowerCase()) { - console.log("THE TEXT--" + b[i].innerText); - /*if next item is alphabetically higher than current item, - mark as a switch and break the loop:*/ - shouldSwitch= true; - break; + if (shouldSwitch) { + /*If a switch has been marked, make the switch + and mark that a switch has been done:*/ + b[i].parentNode.insertBefore(b[i + 1], b[i]); + switching = true; + //Each time a switch is done, increase switchcount by 1: + switchcount ++; + } 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") { + dir = "desc"; + switching = true; + + } } - } } - if (shouldSwitch) { - /*If a switch has been marked, make the switch - and mark that a switch has been done:*/ - b[i].parentNode.insertBefore(b[i + 1], b[i]); - switching = true; - //Each time a switch is done, increase switchcount by 1: - switchcount ++; - } 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") { - dir = "desc"; - switching = true; - - } - } - } - chngSortBtnValue(); + chngSortBtnValue(); } function chngSortBtnValue() { - var sortImg = document.getElementById('sortListDir'); - console.log(sortImg.getAttribute('src')); - if (sortImg.getAttribute('src') === "./icons/Small_A_Z.jpg") { - //sortImg.nextSibling.textContent = "Sort Z to A"; - sortImg.setAttribute('src', './icons/Small_Z_A.jpg'); - } else if (sortImg.getAttribute('src') === "./icons/Small_Z_A.jpg") { - //sortImg.nextSibling.textContent = "Sort A to Z"; - sortImg.setAttribute('src', './icons/Small_A_Z.jpg'); - } + var sortImg = document.getElementById('sortListDir'); + console.log(sortImg.getAttribute('src')); + if (sortImg.getAttribute('src') === "./icons/Small_A_Z.jpg") { + //sortImg.nextSibling.textContent = "Sort Z to A"; + sortImg.setAttribute('src', './icons/Small_Z_A.jpg'); + } else if (sortImg.getAttribute('src') === "./icons/Small_Z_A.jpg") { + //sortImg.nextSibling.textContent = "Sort A to Z"; + sortImg.setAttribute('src', './icons/Small_A_Z.jpg'); + } } function searchInSite (queryString) { - var urlSite = ''; - var searchText = document.getElementById('searchTextBox').value; - console.log(searchText); - if (searchText) { - var url = new URL(currentUrl); - - var selectedSite = getSearchSite(); - - if (selectedSite.indexOf('yahoo') > -1) { - urlSite = selectedSite + 'search;?p=' + searchText + '%20site:' + url.hostname; - } else { - urlSite = selectedSite + 'search?q=' + searchText + '%20site:' + url.hostname; - } - - chrome.tabs.update(currentTab.id, {url: urlSite}); - - } - window.close(); + var urlSite = ''; + var searchText = document.getElementById('searchTextBox').value; + console.log(searchText); + if (searchText) { + var url = new URL(currentUrl); + + var selectedSite = getSearchSite(); + + if (selectedSite.indexOf('yahoo') > -1) { + urlSite = selectedSite + 'search;?p=' + searchText + '%20site:' + url.hostname; + } else { + urlSite = selectedSite + 'search?q=' + searchText + '%20site:' + url.hostname; + } + + chrome.tabs.update(currentTab.id, {url: urlSite}); + + } + window.close(); } document.addEventListener('beforeunload', function (event) { - console.log("unload.."); - const allUrls = document.getElementsByName("link"); - var parentNode; - allUrls.forEach (function (url) { - console.log(url.parentNode); - 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); - }); - }); - } - - }); - - - window.close(); + console.log("unload.."); + const allUrls = document.getElementsByName("link"); + var parentNode; + allUrls.forEach (function (url) { + console.log(url.parentNode); + 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); + }); + }); + } + + }); + + + window.close(); }, true); function saveSelection() { - getCurrentTabUrl(function(tab) { - currentUrl = tab.url; - var url = new URL(tab.url); - var fullDomain = url.hostname; - console.log("dom-" + fullDomain); - var name = getDomainName(tab.url); - - chrome.storage.sync.get( "jsonData", function(items) { - console.log(JSON.stringify(items)); - var origObj = items.jsonData; - var prefForDom = getPreferences(fullDomain, name, origObj); - - if (prefForDom) { - if (Array.isArray(prefForDom)) { - const allUrls = document.getElementsByName("link"); - allUrls.forEach (function (url) { - console.log("chkd--" + url.checked); - console.log("val--" + url.value); - console.log(url.labels[0].innerText); - console.log(JSON.stringify(prefForDom)); - console.log(prefForDom.length + "---long"); - var label = url.labels[0].innerText; - //if (label) //need to remove (currentTab from label) - if (label.indexOf("Current Tab")) { - label = label.split('(')[0]; - } - for (var i=0; i < prefForDom.length; i++) { - if (typeof prefForDom[i] === 'object') { - console.log(prefForDom[i]) ; - if (Object.keys(prefForDom[i])[0] === label) { - if (typeof Object.values(prefForDom[i])[0] === 'object') { - prefForDom[i][label]['selected'] = url.checked; - } else { - prefForDom[i][label] = {'selected' : url.checked, url : Object.values(prefForDom[i])[0]}; - } - - } - } else { - if (prefForDom[i] === url.value) { - prefForDom[i] = {[label] : {'selected' : url.checked, url : url.value}}; - } - } - } - console.log(JSON.stringify(prefForDom)); - - }); - } else { - var options = prefForDom; - var type = document.getElementById("typeSelect"); - var selectedType = type.options[type.selectedIndex].value; - - var allTypes = options[selectedType]; - if (Array.isArray(options[selectedType])){ - const allUrls = document.getElementsByName("link"); - - allUrls.forEach (function (url) { - var label = url.labels[0].innerText; - if (label.indexOf("Current Tab")) { - label = label.split('(')[0]; - } - for (var i=0; i < allTypes.length; i++) { - //console.log("vaan" + JSON.stringify(allTypes[i])); - if (typeof allTypes[i] === 'object') { - if (Object.keys(allTypes[i])[0] === label) { - if (typeof Object.values(allTypes[i])[0] === 'object') { - prefForDom[selectedType][i][label]['selected'] = url.checked; - } else { - prefForDom[selectedType][i][label] = {'selected' : url.checked, url : Object.values(allTypes[i])[0]}; - } - - } - } else { - if (allTypes[i] === url.value) { - prefForDom[selectedType][i]= {[label] : {'selected' : url.checked, url : url.value}}; - } - } - } - console.log(JSON.stringify(prefForDom)); - - }); - } - } - } - console.log(JSON.stringify(origObj)); - chrome.storage.sync.set({ - jsonData: origObj}, - function() { - // Update status to let user know options were saved. - var status = document.getElementById('status'); - status.textContent = 'Options saved.'; - setTimeout(function() { - status.textContent = ''; - }, 750); - }); - }); - }); - - /*const allUrls = document.getElementsByName("link"); - var parentNode = allUrls[0].parentNode.parentNode.childNodes; - changeSelection(parentNode);*/ + getCurrentTabUrl(function(tab) { + currentUrl = tab.url; + var url = new URL(tab.url); + var fullDomain = url.hostname; + console.log("dom-" + fullDomain); + var name = getDomainName(tab.url); + + chrome.storage.sync.get( "jsonData", function(items) { + console.log(JSON.stringify(items)); + var origObj = items.jsonData; + var prefForDom = getPreferences(fullDomain, name, origObj); + + if (prefForDom) { + if (Array.isArray(prefForDom)) { + const allUrls = document.getElementsByName("link"); + allUrls.forEach (function (url) { + console.log("chkd--" + url.checked); + console.log("val--" + url.value); + console.log(url.labels[0].innerText); + console.log(JSON.stringify(prefForDom)); + console.log(prefForDom.length + "---long"); + var label = url.labels[0].innerText; + //if (label) //need to remove (currentTab from label) + if (label.indexOf("Current Tab")) { + label = label.split('(')[0]; + } + for (var i=0; i < prefForDom.length; i++) { + if (typeof prefForDom[i] === 'object') { + console.log(prefForDom[i]) ; + if (Object.keys(prefForDom[i])[0] === label) { + if (typeof Object.values(prefForDom[i])[0] === 'object') { + prefForDom[i][label]['selected'] = url.checked; + } else { + prefForDom[i][label] = {'selected' : url.checked, url : Object.values(prefForDom[i])[0]}; + } + + } + } else { + if (prefForDom[i] === url.value) { + prefForDom[i] = {[label] : {'selected' : url.checked, url : url.value}}; + } + } + } + console.log(JSON.stringify(prefForDom)); + + }); + } else { + var options = prefForDom; + var type = document.getElementById("typeSelect"); + var selectedType = type.options[type.selectedIndex].value; + + var allTypes = options[selectedType]; + if (Array.isArray(options[selectedType])){ + const allUrls = document.getElementsByName("link"); + + allUrls.forEach (function (url) { + var label = url.labels[0].innerText; + if (label.indexOf("Current Tab")) { + label = label.split('(')[0]; + } + for (var i=0; i < allTypes.length; i++) { + //console.log("vaan" + JSON.stringify(allTypes[i])); + if (typeof allTypes[i] === 'object') { + if (Object.keys(allTypes[i])[0] === label) { + if (typeof Object.values(allTypes[i])[0] === 'object') { + prefForDom[selectedType][i][label]['selected'] = url.checked; + } else { + prefForDom[selectedType][i][label] = {'selected' : url.checked, url : Object.values(allTypes[i])[0]}; + } + + } + } else { + if (allTypes[i] === url.value) { + prefForDom[selectedType][i]= {[label] : {'selected' : url.checked, url : url.value}}; + } + } + } + console.log(JSON.stringify(prefForDom)); + + }); + } + } + } + console.log(JSON.stringify(origObj)); + chrome.storage.sync.set({ + jsonData: origObj}, + function() { + // Update status to let user know options were saved. + var status = document.getElementById('status'); + status.textContent = 'Options saved.'; + setTimeout(function() { + status.textContent = ''; + }, 750); + }); + }); + }); + + /*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').disabled = true; - document.getElementById("error").innerHTML = ""; - } else { - document.getElementById('openbtn').disabled = false; - } + let txtAreaContent = this.value; + console.log("in txt are" + txtAreaContent); + if (txtAreaContent === '') { + document.getElementById('openbtn').disabled = true; + document.getElementById("error").innerHTML = ""; + } else { + 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(array[x].indexOf(item)); + + 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"); + /* var bgPage = chrome.extension.getBackgroundPage(); + console.log("before"); var bk = bgPage.test("abc"); // Here paste() is a function that returns value. - console.log("beforeAAA--" + bk);*/ - document.getElementById('mainStuff').hidden = true; - document.getElementById('cancelbtn').addEventListener('click', closeWindow); - document.getElementById('openbtn').addEventListener('click', clickHandler); - document.getElementById('selectall').addEventListener('click', selectall); - document.getElementById('addbtn').addEventListener('click', addUrl); - document.getElementById('savebtn').addEventListener('click', saveSelection); - //document.getElementById('searchAgain').addEventListener('click', searchAgain); - document.getElementById('sortListDir').addEventListener('click', sortListDir); - //document.getElementById('searchbtn').addEventListener('click', searchInSite); - onclick="()"; - console.log("lod--" + loading); - console.log("jsondata--" + jsonData); - var content = document.getElementById('content'); + console.log("beforeAAA--" + bk);*/ + document.getElementById('mainStuff').hidden = true; + document.getElementById('cancelbtn').addEventListener('click', closeWindow); + document.getElementById('openbtn').addEventListener('click', clickHandler); + document.getElementById('selectall').addEventListener('click', selectall); + document.getElementById('addbtn').addEventListener('click', addUrl); + document.getElementById('savebtn').addEventListener('click', saveSelection); + //document.getElementById('searchAgain').addEventListener('click', searchAgain); + document.getElementById('sortListDir').addEventListener('click', sortListDir); + //document.getElementById('searchbtn').addEventListener('click', searchInSite); + //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; - 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); - var fromPage = true; - if (loadFrom === 'config' && searchSite.indexOf(url.hostname) === -1) { - fromPage = false; - } - if (!newtab) { - if (fromPage) { - if (readPage.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').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; - 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 = 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; - } - - - - - 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); - } - } 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 && searchPage) { - document.getElementById('selectall').checked = true; - } - createRadio(content); - //document.getElementById('addbtn').hidden = "hidden"; - const allUrls = document.getElementsByName("link"); - var parentNode = allUrls[0].parentNode.parentNode.childNodes; - changeSelection(parentNode); - } 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);*/ - - } - - - } else { - var mesg = "Bank Page."; - noConfigFound(content, mesg); - } - - - - }); - - 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; + //chrome.storage.sync.set({parentUrl: ""}, function() {}); + /*if (cnnLoading === 'loading') { + window.close(); + return; + }*/ + 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; + if (findInArray(dualSetting, url.hostname)) { + //if (loadFrom === 'config') { + fromPage = false; + //} + createLoadOptions(content, "config"); + + } + + if (!newtab) { + if (fromPage) { + console.log("from page" + name); + console.log(findInArray(readPage, url.hostname) + "---" + readPage.indexOf(url.hostname)); + if (findInArray(readPage, url.hostname) > -1 || isFromSearch(currentUrl)) { + 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]; + 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"; + //ocument.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);*/ + + } + + } else { + var mesg = "Bank Page."; + noConfigFound(content, mesg); + } + }); + + 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); + }); + }); + }); +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); + +} + +function updateList(ele) { + + 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); + loadList(googleSearch[name], content, name); + } 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; + loadList(getPreferences(url.hostname, name), content, name); + } + + //content.removeAll(); + +} + 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(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').disabled = true; - //document.getElementById('cancelbtn').hidden = "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').disabled = false; - } - document.getElementById('anonymus').onkeyup = editTextArea; - - - divTxt.appendChild(pre); - content.appendChild(divTxt); - + 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(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').disabled = true; + //document.getElementById('cancelbtn').hidden = "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').disabled = false; + } + document.getElementById('anonymus').onkeyup = editTextArea; + + + divTxt.appendChild(pre); + content.appendChild(divTxt); + } function createRadio(content) { - //var engDom = getDomain(searchEngine); - //var engine = engDom.split('.')[0]; - //var engineUrl = new URL(searchEngine); - //console.log("url hostname eng-" + engineUrl.hostname); - var engine; - if (searchPage) { - engine = getDomainName(searchEngine); //engineUrl.hostname.split('.')[1]; - } - - 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'); - searchDiv.id = "searchDiv"; - searchDiv.style.margin = "0px 0px 0px 25px"; - searchDiv.style.width = '300px'; - - var searchLbl = document.createElement('label'); - searchLbl.innerHTML = "search in"; - searchLbl.style.marginLeft = "25px"; - searchContent.appendChild(searchLbl); - var br = document.createElement('br'); - searchContent.appendChild(br); - /*var margin = true;*/ - - var both; - - sitesArr.forEach(function (site) { - var url = new URL(site); - console.log("url hostname-" + url.hostname); - var name = getDomainName(site);//url.hostname.split('.')[1]; - //var domain = getDomain(site); - //var name = domain.split('.')[0]; - console.log("name " + name); - console.log("engg " + engine); - if (searchPage && name === engine) { - return; - } - - both = both ? both + "," + site : site; - console.log("both " + both); - var radio = document.createElement("INPUT"); - radio.setAttribute("type", "radio"); - radio.setAttribute("value", site); - radio.setAttribute("name", "site"); - selectAll ? radio.disabled = true : radio.disabled = false; - //radio.setAttribute("id", "site"); - //radio.style.marginLeft = "10px"; - console.log("site " + site); - console.log("eng " + searchEngine); - /*var url = new URL(site); - var fullDomain = url.hostname;*/ - var label = document.createElement("label"); - label.innerHTML = name; - //content.appendChild(radio); - //content.appendChild(label); - searchDiv.appendChild(radio); - searchDiv.appendChild(label); - searchContent.appendChild(searchDiv); - - - }); - - - var searchAgainBtn = document.createElement('input'); - searchAgainBtn.setAttribute("type", "button"); - selectAll ? searchAgainBtn.disabled = true : searchAgainBtn.disabled = false; - if (searchPage) { - var radio = document.createElement("INPUT"); - radio.setAttribute("type", "radio"); - radio.setAttribute("value", both); - radio.setAttribute("name", "site"); - selectAll ? radio.disabled = true : radio.disabled = false; - var label = document.createElement("label"); - label.innerHTML = "Both"; - searchDiv.appendChild(radio); - searchDiv.appendChild(label); - searchAgainBtn.setAttribute("id", "searchAgain"); - searchAgainBtn.setAttribute("value", "Search Again"); - searchAgainBtn.onclick = searchAgain; - } else { - var searchAgainTxt = document.createElement('input'); - searchAgainTxt.setAttribute("type", "text"); - searchAgainTxt.setAttribute("id", "searchTextBox"); - selectAll ? searchAgainTxt.disabled = true : searchAgainTxt.disabled = false; - searchAgainTxt.style.marginLeft = "25px"; - searchDiv.appendChild(searchAgainTxt); - searchAgainBtn.setAttribute("id", "searchbtn"); - searchAgainBtn.setAttribute("value", "Search"); - searchAgainBtn.onclick = searchInSite; - } - searchAgainBtn.style.marginLeft = '2px'; - searchDiv.appendChild(searchAgainBtn); - - searchContent.appendChild(searchDiv); - - /*if (selectAll) { - const allUrls = document.getElementsByName("link"); - if (allUrls.length > -1) { - if (howManyChecked(allUrls[0].parentNode.parentNode.childNodes)) { - //radio.disabled = true; - searchAgainBtn.disabled = true; - document.getElementsByName('site')[0].style.disabled = true; - document.getElementsByName('site')[1].style.disabled = true; - document.getElementsByName('site')[2].style.disabled = true; - if (!searchPage) { - document.getElementById('searchTextBox').style.disabled = true; - } - } - - } - }*/ - - + //var engDom = getDomain(searchEngine); + //var engine = engDom.split('.')[0]; + //var engineUrl = new URL(searchEngine); + //console.log("url hostname eng-" + engineUrl.hostname); + var engine; + if (searchPage) { + //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/']; //searchSites.split(',');//, 'https://www.youtube.com/' + + var searchContent = document.getElementById('searchContent'); + + var searchDiv = document.createElement('div'); + searchDiv.id = "searchDiv"; + searchDiv.style.margin = "0px 0px 0px 25px"; + searchDiv.style.width = '300px'; + + var searchLbl = document.createElement('label'); + searchLbl.innerHTML = "search in"; + searchLbl.style.marginLeft = "25px"; + searchContent.appendChild(searchLbl); + var br = document.createElement('br'); + searchContent.appendChild(br); + /*var margin = true;*/ + + var both; + + sitesArr.forEach(function (site) { + var url = new URL(site); + console.log("url hostname-" + url.hostname); + var name = getDomainName(site);//url.hostname.split('.')[1]; + //var domain = getDomain(site); + //var name = domain.split('.')[0]; + console.log("name " + name); + console.log("engg " + engine); + if (searchPage && name === engine) { + return; + } + + both = both ? both + "," + site : site; + console.log("both " + both); + var radio = document.createElement("INPUT"); + radio.setAttribute("type", "radio"); + radio.setAttribute("value", site); + radio.setAttribute("name", "site"); + selectAll ? radio.disabled = true : radio.disabled = false; + //radio.setAttribute("id", "site"); + //radio.style.marginLeft = "10px"; + console.log("site " + site); + console.log("eng " + searchEngine); + /*var url = new URL(site); + var fullDomain = url.hostname;*/ + var label = document.createElement("label"); + label.innerHTML = name; + //content.appendChild(radio); + //content.appendChild(label); + searchDiv.appendChild(radio); + searchDiv.appendChild(label); + searchContent.appendChild(searchDiv); + + + }); + + + var searchAgainBtn = document.createElement('input'); + searchAgainBtn.setAttribute("type", "button"); + selectAll ? searchAgainBtn.disabled = true : searchAgainBtn.disabled = false; + if (searchPage) { + var radio = document.createElement("INPUT"); + radio.setAttribute("type", "radio"); + radio.setAttribute("value", both); + radio.setAttribute("name", "site"); + selectAll ? radio.disabled = true : radio.disabled = false; + var label = document.createElement("label"); + label.innerHTML = "Both"; + searchDiv.appendChild(radio); + searchDiv.appendChild(label); + searchAgainBtn.setAttribute("id", "searchAgain"); + searchAgainBtn.setAttribute("value", "Search Again"); + searchAgainBtn.onclick = searchAgain; + } else { + var searchAgainTxt = document.createElement('input'); + searchAgainTxt.setAttribute("type", "text"); + searchAgainTxt.setAttribute("id", "searchTextBox"); + selectAll ? searchAgainTxt.disabled = true : searchAgainTxt.disabled = false; + //fsearchAgainTxt.style.marginLeft = "25px"; + searchDiv.appendChild(searchAgainTxt); + searchAgainBtn.setAttribute("id", "searchbtn"); + searchAgainBtn.setAttribute("value", "Search"); + searchAgainBtn.onclick = searchInSite; + } + searchAgainBtn.style.marginLeft = '2px'; + searchDiv.appendChild(searchAgainBtn); + + searchContent.appendChild(searchDiv); + + /*if (selectAll) { + const allUrls = document.getElementsByName("link"); + if (allUrls.length > -1) { + if (howManyChecked(allUrls[0].parentNode.parentNode.childNodes)) { + //radio.disabled = true; + searchAgainBtn.disabled = true; + document.getElementsByName('site')[0].style.disabled = true; + document.getElementsByName('site')[1].style.disabled = true; + document.getElementsByName('site')[2].style.disabled = true; + if (!searchPage) { + document.getElementById('searchTextBox').style.disabled = true; + } + } + + } + }*/ + + } function randomIntFromInterval(min,max) @@ -1178,263 +1296,266 @@ function randomIntFromInterval(min,max) } function getPreferences(url_hostname, name, dataObj) { - if (dataObj === undefined) { - dataObj = jsonData; - } - console.log(url_hostname + " -- " + name ); - let pref;// = []; - for (var item in dataObj) { - let domain; - domain = dataObj[item]['current']; - console.log("DOMAIN--" + domain); - if (domain.indexOf(',') === -1) { - console.log("in no comma"); - //pref = []; - //if (domain === url_hostname || domain === name) { - if (domain.indexOf(url_hostname) > -1 || domain.indexOf(name) > -1) { - console.log("name matched....") - if (domain.indexOf('http://') !== -1) { - baseUrl = domain; - } else { - baseUrl = 'http://' + domain; - } - var sites = dataObj[item]['sites']; - pref = sites; - console.log("sites--" + sites); - } - console.log("in get pref " + JSON.stringify(pref)); - } else { - var domArr = domain.split(','); - domArr.forEach(function(hostname){ - if (url_hostname === hostname || name === hostname) { - pref = dataObj[item]['sites']; - } - }); - console.log("in get pref " + pref); - } - } - console.log(pref); - return pref; - -} + if (dataObj === undefined) { + dataObj = jsonData; + } + console.log(url_hostname + " -- " + name ); + let pref;// = []; + for (var item in dataObj) { + let domain; + domain = dataObj[item]['current']; + console.log("DOMAIN--" + domain); + if (domain.indexOf(',') === -1) { + console.log("in no comma"); + //pref = []; + //if (domain === url_hostname || domain === name) { + if (domain.indexOf(url_hostname) > -1 || domain.indexOf(name) > -1) { + console.log("name matched....") + if (domain.indexOf('http://') !== -1) { + baseUrl = domain; + } else { + baseUrl = 'http://' + domain; + } + var sites = dataObj[item]['sites']; + pref = sites; + console.log("sites--" + sites); + } + console.log("in get pref " + JSON.stringify(pref)); + } else { + var domArr = domain.split(','); + domArr.forEach(function(hostname){ + if (url_hostname === hostname || name === hostname) { + pref = dataObj[item]['sites']; + } + }); + console.log("in get pref " + pref); + } + } + console.log(pref); + return pref; + +} function createList(allurls) { - - var list = document.createElement("OL"); - list.setAttribute("type", "1"); - list.setAttribute("id", "orderedList"); - //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)); - //console.log(Object.values(page)); - var input = document.createElement("INPUT"); - input.setAttribute("type", "checkbox"); - var label = document.createElement('label'); - - 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); - }); - }); - } - - } 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); - }); - }); - } - } else { - console.log("llll" + label.getText); - } - } - - key = Object.keys(page)[0]; - } else { - var pageParts = page.split('/'); - console.log(pageParts.length); - console.log(pageParts[pageParts.length - 1] ); - linkObj = page; - if (linkObj.indexOf("http") === -1) { - linkObj = baseUrl + linkObj; - } - key = page.endsWith('/') ? pageParts[pageParts.length - 2] : pageParts[pageParts.length - 1]; - input.setAttribute("value", 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); - } - - } - input.setAttribute("name", "link"); - if (currentUrl === linkObj) { - key = key + "(Current Tab)"; - console.log("kkk"+key); - document.getElementById('addbtn').disabled = true; - } - var id = key; //Object.keys(page)[0]; - input.setAttribute("id", id); - input.onclick = chkBoxClick; - label.htmlFor = id; - - console.log("linkObj--" + linkObj); - console.log("currentUrl--" + currentUrl); - - - //var linkObj = Object.values(page)[0]; - - - - var li = document.createElement("LI"); - li.style.backgroundColor = bgColor; - if (searchPage) - li.style.margin = "10px 0"; - - //li.setAttribute("background-color" , "#FFFEEC"); - var logo = document.createElement("IMG"); - console.log("link " + Object.values(page)[0]); - logo.setAttribute("src", 'chrome://favicon/'+ linkObj); //Object.values(page)[0]); - logo.setAttribute("width", "20"); - logo.setAttribute("height", "12"); - - var link = document.createElement('a'); - link.textContent = id; - link.href = linkObj; //Object.values(page)[0]; - link.title = linkObj; - link.onclick = linkClick; - label.appendChild(link); - - - list.appendChild(li); - li.appendChild(input); - li.appendChild(logo); - li.appendChild(label); - //list.appendChild(input); - //list.appendChild(logo); - //list.appendChild(label); - //var line = document.createElement('br'); - //list.appendChild(line); - if (bgColor === "#EDEEED") {//ECF0F1 //"#F4F6F7" - bgColor = "#FFFFFF"; - } else { - bgColor = "#EDEEED"; //"#F4F6F7"; - } - }); - /*var howmany = document.getElementById("howmany"); - if (selectAll) { - howmany.textContent = allurls.length + " selected."; - } else { - howmany.textContent = "0 selected."; - }*/ - return list; - - + + var list = document.createElement("OL"); + list.setAttribute("type", "1"); + list.setAttribute("id", "orderedList"); + //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)); + //console.log(Object.values(page)); + var input = document.createElement("INPUT"); + input.setAttribute("type", "checkbox"); + var label = document.createElement('label'); + + var linkObj, key, url; + if (typeof page === 'object') { + console.log("has key value"); + 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 { + 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); + } + } + + key = Object.keys(page)[0]; + + } + + } else { + var pageParts = page.split('/'); + console.log(pageParts.length); + console.log(pageParts[pageParts.length - 1] ); + linkObj = page; + if (linkObj.indexOf("http") === -1) { + linkObj = baseUrl + linkObj; + } + key = page.endsWith('/') ? pageParts[pageParts.length - 2] : pageParts[pageParts.length - 1]; + input.setAttribute("value", 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); + } + + } + input.setAttribute("name", "link"); + if (currentUrl === linkObj) { + key = key + "(Current Tab)"; + console.log("kkk"+key); + document.getElementById('addbtn').disabled = true; + } + var id = key; //Object.keys(page)[0]; + input.setAttribute("id", id); + input.onclick = chkBoxClick; + label.htmlFor = id; + + console.log("linkObj--" + linkObj); + console.log("currentUrl--" + currentUrl); + + + //var linkObj = Object.values(page)[0]; + + + + var li = document.createElement("LI"); + li.style.backgroundColor = bgColor; + if (searchPage) + li.style.margin = "10px 0"; + + //li.setAttribute("background-color" , "#FFFEEC"); + var logo = document.createElement("IMG"); + console.log("link " + Object.values(page)[0]); + logo.setAttribute("src", 'chrome://favicon/'+ linkObj); //Object.values(page)[0]); + logo.setAttribute("width", "20"); + logo.setAttribute("height", "12"); + + var link = document.createElement('a'); + link.textContent = id; + link.href = linkObj; //Object.values(page)[0]; + link.title = linkObj; + link.onclick = linkClick; + label.appendChild(link); + + + list.appendChild(li); + li.appendChild(input); + li.appendChild(logo); + li.appendChild(label); + //list.appendChild(input); + //list.appendChild(logo); + //list.appendChild(label); + //var line = document.createElement('br'); + //list.appendChild(line); + if (bgColor === "#EDEEED") {//ECF0F1 //"#F4F6F7" + bgColor = "#FFFFFF"; + } else { + bgColor = "#EDEEED"; //"#F4F6F7"; + } + }); + /*var howmany = document.getElementById("howmany"); + if (selectAll) { + howmany.textContent = allurls.length + " selected."; + } else { + howmany.textContent = "0 selected."; + }*/ + return list; + + } function selectOption() { - var content = document.getElementById('content'); - var orderedList = document.getElementById('orderedList'); - if (orderedList) { - content.removeChild(orderedList); - } - - var type = document.getElementById("typeSelect"); - var selectedType = type.options[type.selectedIndex].value; - - //var allTypes = jsonData[type.name]; - var url = new URL(currentUrl); + var content = document.getElementById('content'); + var orderedList = document.getElementById('orderedList'); + if (orderedList) { + content.removeChild(orderedList); + } + + var type = document.getElementById("typeSelect"); + var selectedType = type.options[type.selectedIndex].value; + + //var allTypes = jsonData[type.name]; + var url = new URL(currentUrl); //var allTypes = jsonData[url.hostname] || jsonData[type.name]; - var allTypes = getPreferences(url.hostname, type.name); //jsonData[url.hostname] || jsonData[name]; - if (Array.isArray(allTypes[selectedType])){ - content.appendChild(createList(allTypes[selectedType])); - } - const allUrls = document.getElementsByName("link"); - var parentNode = allUrls[0].parentNode.parentNode.childNodes; - changeSelection(parentNode); - + var allTypes = getPreferences(url.hostname, type.name); //jsonData[url.hostname] || jsonData[name]; + if (Array.isArray(allTypes[selectedType])){ + content.appendChild(createList(allTypes[selectedType])); + } + const allUrls = document.getElementsByName("link"); + var parentNode = allUrls[0].parentNode.parentNode.childNodes; + changeSelection(parentNode); + } function createDropDown (data, hierarchy) { - var dropDown = document.createElement("SELECT"); - dropDown.setAttribute("id", "typeSelect"); - dropDown.setAttribute("name", hierarchy); - var keys = Object.keys(data); - keys.forEach(function (optn) { - var options = document.createElement("option"); - options.setAttribute("value", optn); - options.setAttribute("id", optn); - var txt = document.createTextNode(optn); - options.appendChild(txt); - if (optn.indexOf("default") > -1) { - options.selected = true; - } - dropDown.appendChild(options); - }); - dropDown.onchange = selectOption; - return dropDown; - + var dropDown = document.createElement("SELECT"); + dropDown.setAttribute("id", "typeSelect"); + dropDown.setAttribute("name", hierarchy); + var keys = Object.keys(data); + keys.forEach(function (optn) { + var options = document.createElement("option"); + options.setAttribute("value", optn); + options.setAttribute("id", optn); + var txt = document.createTextNode(optn); + options.appendChild(txt); + if (optn.indexOf("default") > -1) { + options.selected = true; + } + dropDown.appendChild(options); + }); + dropDown.onchange = selectOption; + return dropDown; + } - + function getDomain(url, subdomain) { - //var isSubdom = isSubdomain(url); - subdomain = subdomain || false; + //var isSubdom = isSubdomain(url); + subdomain = subdomain || false; url = url.replace(/(https?:\/\/)?(www.)?/i, ''); @@ -1453,85 +1574,126 @@ function getDomain(url, subdomain) { } function getCurrentTabUrl(callback) { - var queryInfo = { - active: true, - currentWindow: true - }; - - chrome.tabs.query(queryInfo, function(tabs) { - - var tab = tabs[0]; - //var url = tab.url; -currentTab = tab; - callback(tab); - }); - - chrome.windows.getCurrent(function(currentWindow) { - invokedWindow = currentWindow.id; - }); + var queryInfo = { + active: true, + currentWindow: true + }; + + chrome.tabs.query(queryInfo, function(tabs) { + + var tab = tabs[0]; + //var url = tab.url; + currentTab = tab; + callback(tab); + }); + + chrome.windows.getCurrent(function(currentWindow) { + invokedWindow = currentWindow.id; + }); + +} + +function utubeClick() { + var idx = currentTab.index + 1; + chrome.tabs.create({url: this.href, active : false, index: idx, windowId : invokedWindow}, function(tab) { + + }); +} +function isParentGoogle(parentUrl) { + // var url = new URL(parentUrl); + // console.log("azhagiye...." + url.hostname); + //return google.indexOf(url.hostname) > -1; +} + +function isFromSearch(currentURL) { + //console.log("Check1 " + JSON.stringify(googleSearch)); + console.log("Check22 " + currentURL); + var urlFound = false; + if (googleSearch) { + googleSearch.forEach(function (obj) { + var value = Object.values(obj); + console.log("Check3 " + value); + if (value == currentURL) { + console.log("ret true"); + urlFound = true; + } + }); + } + return urlFound; +} + +function getDomainName(url) { + var hostname = new URL(url).hostname; + var hostArr = hostname.split('.'); + console.log(hostArr.length + "---yyy"); + console.log(hostArr); + if (hostArr.length === 2) { + return hostArr[0]; + } else if (hostArr.length === 4) { + if (hostArr[0] === 'www') { + return hostArr[1]; + } else { + return hostArr[2]; + } + } else { + return hostArr[1]; + } +} + +function isUrlInList(currentURL, urlList) { + //console.log("Check1 " + JSON.stringify(googleSearch)); + console.log("Check22 " + currentURL); + var urlFound = false; + + urlList.forEach(function (obj) { + var value = Object.values(obj); + console.log("Check3 " + value); + if (value == currentURL) { + console.log("ret true"); + urlFound = true; + } + }); + + return urlFound; +} + +chrome.runtime.onMessage.addListener(function(req, sender, sendres){ + if (req.cnnLoading === "complete") { + console.log("cnn loaded....") + } + + +}); + +function loadList(prefForDom, content, name) { + if (Array.isArray(prefForDom)) { + console.log("pref dom is an array"); + if (prefForDom.length > 0) { + content.appendChild(createList(prefForDom)); + } else { + noConfigFound(content); + } + } 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 && searchPage) { + document.getElementById('selectall').checked = true; + } + createRadio(content); + //document.getElementById('addbtn').hidden = "hidden"; + const allUrls = document.getElementsByName("link"); + var parentNode = allUrls[0].parentNode.parentNode.childNodes; + changeSelection(parentNode); } - - function utubeClick() { - var idx = currentTab.index + 1; - chrome.tabs.create({url: this.href, active : false, index: idx, windowId : invokedWindow}, function(tab) { - - }); - } - function isParentGoogle(parentUrl) { - // var url = new URL(parentUrl); - // console.log("azhagiye...." + url.hostname); - //return google.indexOf(url.hostname) > -1; - } - - function isFromSearch(currentURL) { - //console.log("Check1 " + JSON.stringify(googleSearch)); - console.log("Check22 " + currentURL); - var urlFound = false; - if (googleSearch) { - googleSearch.forEach(function (obj) { - var value = Object.values(obj); - console.log("Check3 " + value); - if (value == currentURL) { - console.log("ret true"); - urlFound = true; - } - }); - } - return urlFound; - } - - function getDomainName(url) { - var hostname = new URL(url).hostname; - var hostArr = hostname.split('.'); - console.log(hostArr.length + "---yyy"); - console.log(hostArr); - if (hostArr.length === 2) { - return hostArr[0]; - } else if (hostArr.length === 4) { - if (hostArr[0] === 'www') { - return hostArr[1]; - } else { - return hostArr[2]; - } - } else { - return hostArr[1]; - } - } - - function isUrlInList(currentURL, urlList) { - //console.log("Check1 " + JSON.stringify(googleSearch)); - console.log("Check22 " + currentURL); - var urlFound = false; - - urlList.forEach(function (obj) { - var value = Object.values(obj); - console.log("Check3 " + value); - if (value == currentURL) { - console.log("ret true"); - urlFound = true; - } - }); - - return urlFound; - } \ No newline at end of file From cd83699c208831fb1ec63f5ba98c88d7ce0cfb92 Mon Sep 17 00:00:00 2001 From: Gautam Date: Tue, 2 Jan 2018 22:47:04 -0600 Subject: [PATCH 4/8] Modified popup.js, background.js etc for fixes. --- popup.js | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/popup.js b/popup.js index 5256219..0d7d82d 100644 --- a/popup.js +++ b/popup.js @@ -20,7 +20,7 @@ var loadFrom; 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']; -var dualSetting = ['cnn', 'stackoverflow']; + var cnnLoading = "loading"; chrome.storage.sync.get( options, function(items) { @@ -662,8 +662,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) { @@ -801,7 +810,7 @@ function findInArray(array, item) { //var found = false; for (var x = 0; x < array.length; x ++) { console.log(array[x] + " ---" + item); - console.log(array[x].indexOf(item)); + console.log(item.indexOf(array[x])); if (item.indexOf(array[x]) > -1) { //found = true; @@ -870,7 +879,12 @@ document.addEventListener('DOMContentLoaded', function () { console.log("loadFrom-" + loadFrom); console.log("going to else part -- " + JSON.stringify(tab)); var fromPage = true; - if (findInArray(dualSetting, url.hostname)) { + + 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; //} @@ -881,8 +895,8 @@ document.addEventListener('DOMContentLoaded', function () { if (!newtab) { if (fromPage) { console.log("from page" + name); - console.log(findInArray(readPage, url.hostname) + "---" + readPage.indexOf(url.hostname)); - if (findInArray(readPage, url.hostname) > -1 || isFromSearch(currentUrl)) { + 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 @@ -943,7 +957,7 @@ document.addEventListener('DOMContentLoaded', function () { if (prefForDom === undefined) { prefForDom = getPreferences(url.hostname, name); //jsonData[url.hostname] || jsonData[name]; //content.style.width = "200px"; - //ocument.getElementById('searchAgain').hidden = "hidden"; + //document.getElementById('searchAgain').hidden = "hidden"; searchPage = false; } @@ -1605,12 +1619,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]) { + googleSearch[name].forEach(function (obj) { var value = Object.values(obj); console.log("Check3 " + value); if (value == currentURL) { @@ -1693,6 +1707,7 @@ function loadList(prefForDom, content, name) { createRadio(content); //document.getElementById('addbtn').hidden = "hidden"; const allUrls = document.getElementsByName("link"); + console.log(allUrls[0]); var parentNode = allUrls[0].parentNode.parentNode.childNodes; changeSelection(parentNode); From b7b6f23089c8600987f8b146aefc143845e2657a Mon Sep 17 00:00:00 2001 From: Gautam Dev Date: Thu, 4 Jan 2018 23:13:23 -0600 Subject: [PATCH 5/8] Update popup.js --- popup.js | 3112 +++++++++++++++++++++++++++--------------------------- 1 file changed, 1556 insertions(+), 1556 deletions(-) diff --git a/popup.js b/popup.js index 0d7d82d..9e41174 100644 --- a/popup.js +++ b/popup.js @@ -24,1284 +24,1284 @@ var readPage = ['google', 'search.yahoo', 'bing', 'youtube', 'cnn', 'stackoverfl var cnnLoading = "loading"; chrome.storage.sync.get( options, function(items) { - jsonData = items.jsonData; - highlightTabs = items.highlightTabs; - tabsBackground = items.tabsBackground; - selectAll = items.selectAll; - loading = items.loading; - console.log("in sync get" + loading); - //googleSearch = items.googleSearch; - //console.log("in sync get search--" + googleSearch); - parentUrl = items.parentUrl; - //queryString = items.queryString; - //searchSites = items.searchSites; - //searchEngine = items.searchEngine; - anonymus = items.anonymus; - //loadFrom = items.loadFrom; + jsonData = items.jsonData; + highlightTabs = items.highlightTabs; + tabsBackground = items.tabsBackground; + selectAll = items.selectAll; + loading = items.loading; + console.log("in sync get" + loading); + //googleSearch = items.googleSearch; + //console.log("in sync get search--" + googleSearch); + parentUrl = items.parentUrl; + //queryString = items.queryString; + //searchSites = items.searchSites; + //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; + googleSearch = items.googleSearch; + console.log("in sync get search--" + googleSearch); + queryString = items.queryString; + // searchEngine = items.searchEngine; }); function closeWindow (e) { - const allUrls = document.getElementsByName("link"); - var parentNode; - allUrls.forEach (function (url) { - console.log(url.parentNode); - 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); - }); - }); - } - - }); - - - window.close(); + const allUrls = document.getElementsByName("link"); + var parentNode; + allUrls.forEach (function (url) { + console.log(url.parentNode); + 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); + }); + }); + } + + }); + + + window.close(); } function clickHandler(e) { - //loading = true; - document.getElementById("openbtn").disabled = true; - const allUrls = document.getElementsByName("link"); - const urlsToOpen = []; - const tabToHilite = [currentTab.index]; - const openAt = currentTab.index + 1; - var anonymusValues; - try { - 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 { - 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; - } - - - console.log(urlsToOpen); - /*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 : anonymusValues}, function() { - if (chrome.runtime.error) { - console.log("Runtime error."); - } - }); - window.close(); + //loading = true; + document.getElementById("openbtn").disabled = true; + const allUrls = document.getElementsByName("link"); + const urlsToOpen = []; + const tabToHilite = [currentTab.index]; + const openAt = currentTab.index + 1; + var anonymusValues; + try { + 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 { + 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; + } + + + console.log(urlsToOpen); + /*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 : anonymusValues}, function() { + if (chrome.runtime.error) { + console.log("Runtime error."); + } + }); + window.close(); } function selectall () { - const allUrls = document.getElementsByName("link"); - 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").disabled = true; - document.getElementById("sametabChkbx").checked = false; - } - - console.log("kkkkkk-" + url.value); - var itemValue = url.value; - if (searchPage) { - 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); - }); - }); - } - - }); - - /* - var howmany = document.getElementById("howmany"); - var selNums = howManyChecked(parentNode); - howmany.textContent = selNums + " selected."; - if (selNums > 0) { - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = true; - } - - if (document.getElementById('searchbtn')) { - 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; - }*/ - } 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").disabled = true; - document.getElementById("sametabChkbx").checked = false; - 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); - }); - }); - } - - }); - /*var howmany = document.getElementById("howmany"); - howmany.textContent = "0 selected."; - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = false; - } - - if (document.getElementById('searchbtn')) { - 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; */ - //document.getElementById('searchAgain').disabled = false; - } - - changeSelection(parentNode); + const allUrls = document.getElementsByName("link"); + 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").disabled = true; + document.getElementById("sametabChkbx").checked = false; + } + + console.log("kkkkkk-" + url.value); + var itemValue = url.value; + if (searchPage) { + 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); + }); + }); + } + + }); + + /* + var howmany = document.getElementById("howmany"); + var selNums = howManyChecked(parentNode); + howmany.textContent = selNums + " selected."; + if (selNums > 0) { + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = true; + } + + if (document.getElementById('searchbtn')) { + 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; + }*/ + } 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").disabled = true; + document.getElementById("sametabChkbx").checked = false; + 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); + }); + }); + } + + }); + /*var howmany = document.getElementById("howmany"); + howmany.textContent = "0 selected."; + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = false; + } + + if (document.getElementById('searchbtn')) { + 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; */ + //document.getElementById('searchAgain').disabled = false; + } + + changeSelection(parentNode); } function linkClick () { - console.log(this.href); - const opnSmeTab = document.getElementById("sametabChkbx").checked; - chrome.storage.sync.set({urlsToOpen: [], currTab : "", invokedWindow : "", opnSmeTb : "", loading: false}, function() {}); - chrome.storage.sync.set({urlsToOpen: this.href, currTab: currentTab, invokedWindow: invokedWindow, opnSmeTb: opnSmeTab, loading : true}, function() { - if (chrome.runtime.error) { - console.log("Runtime error."); - } - }); - window.close(); + console.log(this.href); + const opnSmeTab = document.getElementById("sametabChkbx").checked; + chrome.storage.sync.set({urlsToOpen: [], currTab : "", invokedWindow : "", opnSmeTb : "", loading: false}, function() {}); + chrome.storage.sync.set({urlsToOpen: this.href, currTab: currentTab, invokedWindow: invokedWindow, opnSmeTb: opnSmeTab, loading : true}, function() { + if (chrome.runtime.error) { + console.log("Runtime error."); + } + }); + window.close(); } function chkBoxClick (ele) { - console.log(this.labels[0].innerHTML); - var currNode = this; - var none = true; - var selectedArray = []; - if (this.checked) { - this.labels[0].style.fontWeight = "bold"; - document.getElementById("openbtn").disabled = false; - //var liList = this.parentNode.parentNode.childNodes; - //console.log(liList.length); - - this.parentNode.parentNode.childNodes.forEach(function (li){ - if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { - none = false; - return; - } - - }); - if (none) { - console.log("only one"); - document.getElementById("sametab").disabled = false; - document.getElementById("sametabChkbx").checked = true; - } else { - document.getElementById("sametab").disabled = true; - document.getElementById("sametabChkbx").checked = false; - } - - console.log("li value-" + this.value); - /*selectedArray.push(this.value); - this.parentNode.parentNode.childNodes.forEach(function (li){ - if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { - selectedArray.push(li.childNodes[0].value); - } - });*/ - var itemValue = this.value; - if (searchPage) { - 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 (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = true; - } - - if (document.getElementById('searchbtn')) { - 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; - //document.getElementById('searchAgain').disabled = true; - } else { - this.labels[0].style.fontWeight="normal"; - document.getElementById("openbtn").disabled = 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").disabled = true; - document.getElementById("sametabChkbx").checked = false; - } else { - document.getElementById("sametab").disabled = false; - document.getElementById("sametabChkbx").checked = true; - } - - var selItems = this.value; - if (searchPage) { - chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { - 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); + console.log(this.labels[0].innerHTML); + var currNode = this; + var none = true; + var selectedArray = []; + if (this.checked) { + this.labels[0].style.fontWeight = "bold"; + document.getElementById("openbtn").disabled = false; + //var liList = this.parentNode.parentNode.childNodes; + //console.log(liList.length); + + this.parentNode.parentNode.childNodes.forEach(function (li){ + if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { + none = false; + return; + } + + }); + if (none) { + console.log("only one"); + document.getElementById("sametab").disabled = false; + document.getElementById("sametabChkbx").checked = true; + } else { + document.getElementById("sametab").disabled = true; + document.getElementById("sametabChkbx").checked = false; + } + + console.log("li value-" + this.value); + /*selectedArray.push(this.value); + this.parentNode.parentNode.childNodes.forEach(function (li){ + if (currNode !== li.childNodes[0] && li.childNodes[0].checked) { + selectedArray.push(li.childNodes[0].value); + } + });*/ + var itemValue = this.value; + if (searchPage) { + 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 (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = true; + } + + if (document.getElementById('searchbtn')) { + 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; + //document.getElementById('searchAgain').disabled = true; + } else { + this.labels[0].style.fontWeight="normal"; + document.getElementById("openbtn").disabled = 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").disabled = true; + document.getElementById("sametabChkbx").checked = false; + } else { + document.getElementById("sametab").disabled = false; + document.getElementById("sametabChkbx").checked = true; + } + + var selItems = this.value; + if (searchPage) { + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + 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(listNodes); - console.log(listNodes.length + "***" + selNums); - howmany.textContent = selNums + " selected."; - if (selNums === 0) { - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = false; - } - - if (document.getElementById('searchbtn')) { - 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; - //document.getElementById('searchAgain').disabled = false; - } else { - if (document.getElementById('searchAgain')) { - document.getElementById('searchAgain').disabled = true; - } - - if (document.getElementById('searchbtn')) { - 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; - //document.getElementById('searchAgain').disabled = true; - } - console.log("selected--" + selNums + "--list len--" + listNodes.length); - if (selNums < listNodes.length) { - document.getElementById('selectall').checked = false; - } - if (selNums === listNodes.length) { - document.getElementById('selectall').checked = true; - } + + var howmany = document.getElementById("howmany"); + var selNums = howManyChecked(listNodes); + console.log(listNodes.length + "***" + selNums); + howmany.textContent = selNums + " selected."; + if (selNums === 0) { + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = false; + } + + if (document.getElementById('searchbtn')) { + 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; + //document.getElementById('searchAgain').disabled = false; + } else { + if (document.getElementById('searchAgain')) { + document.getElementById('searchAgain').disabled = true; + } + + if (document.getElementById('searchbtn')) { + 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; + //document.getElementById('searchAgain').disabled = true; + } + console.log("selected--" + selNums + "--list len--" + listNodes.length); + if (selNums < listNodes.length) { + document.getElementById('selectall').checked = false; + } + if (selNums === listNodes.length) { + document.getElementById('selectall').checked = true; + } } function howManyChecked(liNodes) { - var chked = 0; - liNodes.forEach (function (liNode){ - if (liNode.childNodes[0].checked) { - chked ++; - } - }); - return chked; + var chked = 0; + liNodes.forEach (function (liNode){ + if (liNode.childNodes[0].checked) { + chked ++; + } + }); + return chked; } function atleastOneChecked(liNodes) { - var chked = false; - liNodes.forEach (function (liNode){ - if (liNode.childNodes[0].checked) { - chked = true; - } - }); - - return chked; - - /*console.log(Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked)); - return Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked);*/ + var chked = false; + liNodes.forEach (function (liNode){ + if (liNode.childNodes[0].checked) { + chked = true; + } + }); + + return chked; + + /*console.log(Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked)); + return Array.prototype.slice.call(chkBoxNodes).some(x => x.childNodes[0].checked);*/ } function moreThanOneChecked(liNodes) { - var n = 0; - liNodes.forEach (function (liNode){ - if (liNode.childNodes[0].checked) { - n ++; - } - }); - if (n === 0 || n > 1 ) { - return true; - } else { - return false; - } + var n = 0; + liNodes.forEach (function (liNode){ + if (liNode.childNodes[0].checked) { + n ++; + } + }); + if (n === 0 || n > 1 ) { + return true; + } else { + return false; + } } function addUrl() { - getCurrentTabUrl(function(tab) { - currentUrl = tab.url; - 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 = 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; - //alert("before" + JSON.stringify(origObj)); - /*var prefForDom = origObj[fullDomain]; - if (prefForDom === undefined) { - prefForDom = origObj[name]; - }*/ - //var prefForDom = origObj[fullDomain] || origObj[name]; - var prefForDom = getPreferences(fullDomain, name, origObj); - console.log("==" + prefForDom + "--- llllllll"); - var newEntryObj = {}; - var path = url.pathname.split('/'); - 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; - key = path[path.length-1]; - } else { - //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 { - var options = prefForDom; - var type = document.getElementById("typeSelect"); - var selectedType = type.options[type.selectedIndex].value; - - var allTypes = options[selectedType]; - if (Array.isArray(options[selectedType])){ - options[selectedType].push(newEntryObj); - } - } - - - } else { - console.log('in else'); - //origObj[name] = [currentUrl]; - var newObj = {}; - newObj["current"] = name; - newObj["description"] = name; - newObj["sites"] = newObjArr; //[newEntryObj]; - origObj[name] = newObj; - } - //origObj[name] = [currentUrl]; - console.log(JSON.stringify(origObj)); - //jsonObj = items; - //console.log(JSON.stringify(jsonObj)); - chrome.storage.sync.set({ - jsonData: origObj}, - function() { - // Update status to let user know options were saved. - var status = document.getElementById('status'); - status.textContent = 'Options saved.'; - setTimeout(function() { - status.textContent = ''; - }, 750); - }); - }); - }); + getCurrentTabUrl(function(tab) { + currentUrl = tab.url; + 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 = 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; + //alert("before" + JSON.stringify(origObj)); + /*var prefForDom = origObj[fullDomain]; + if (prefForDom === undefined) { + prefForDom = origObj[name]; + }*/ + //var prefForDom = origObj[fullDomain] || origObj[name]; + var prefForDom = getPreferences(fullDomain, name, origObj); + console.log("==" + prefForDom + "--- llllllll"); + var newEntryObj = {}; + var path = url.pathname.split('/'); + 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; + key = path[path.length-1]; + } else { + //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 { + var options = prefForDom; + var type = document.getElementById("typeSelect"); + var selectedType = type.options[type.selectedIndex].value; + + var allTypes = options[selectedType]; + if (Array.isArray(options[selectedType])){ + options[selectedType].push(newEntryObj); + } + } + + + } else { + console.log('in else'); + //origObj[name] = [currentUrl]; + var newObj = {}; + newObj["current"] = name; + newObj["description"] = name; + newObj["sites"] = newObjArr; //[newEntryObj]; + origObj[name] = newObj; + } + //origObj[name] = [currentUrl]; + console.log(JSON.stringify(origObj)); + //jsonObj = items; + //console.log(JSON.stringify(jsonObj)); + chrome.storage.sync.set({ + jsonData: origObj}, + 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 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; + //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 = ''; - var selectedSite = getSearchSite(); - var selSiteArr; - var idx = currentTab.index + 1; - if (selectedSite.indexOf(',') > -1) { - selSiteArr = selectedSite.split(','); - selSiteArr.forEach(function(selSite){ - if (selSite.indexOf('yahoo') > -1) { - urlSite = selSite + 'search;?p=' + queryString; - } else { - urlSite = selSite + 'search?q=' + queryString; - } - - chrome.tabs.create({url: urlSite, active : false, index: parseInt(idx), windowId : invokedWindow}, function(tab) { - idx ++; - }); - }); - } else { - if (selectedSite.indexOf('yahoo') > -1) { - urlSite = selectedSite + 'search;?p=' + queryString; - } else { - urlSite = selectedSite + 'search?q=' + queryString; - } - chrome.tabs.create({url: urlSite, active : false, index: parseInt(currentTab.index + 1), windowId : invokedWindow}, function(tab) { - - }); - //chrome.tabs.update(currentTab.id, {url: urlSite}); - } - - window.close(); + var urlSite = ''; + var selectedSite = getSearchSite(); + var selSiteArr; + var idx = currentTab.index + 1; + if (selectedSite.indexOf(',') > -1) { + selSiteArr = selectedSite.split(','); + selSiteArr.forEach(function(selSite){ + if (selSite.indexOf('yahoo') > -1) { + urlSite = selSite + 'search;?p=' + queryString; + } else { + urlSite = selSite + 'search?q=' + queryString; + } + + chrome.tabs.create({url: urlSite, active : false, index: parseInt(idx), windowId : invokedWindow}, function(tab) { + idx ++; + }); + }); + } else { + if (selectedSite.indexOf('yahoo') > -1) { + urlSite = selectedSite + 'search;?p=' + queryString; + } else { + urlSite = selectedSite + 'search?q=' + queryString; + } + chrome.tabs.create({url: urlSite, active : false, index: parseInt(currentTab.index + 1), windowId : invokedWindow}, function(tab) { + + }); + //chrome.tabs.update(currentTab.id, {url: urlSite}); + } + + window.close(); } function getSearchSite() { - var selectedSite; - var site = document.getElementsByName("site"); - for(var i = 0; i < site.length; i++) { - if(site[i].checked) { - selectedSite = site[i].value; - - if (!selectedSite.endsWith('/')) { - selectedSite = selectedSite + '/'; - } - } - } - - return selectedSite; + var selectedSite; + var site = document.getElementsByName("site"); + for(var i = 0; i < site.length; i++) { + if(site[i].checked) { + selectedSite = site[i].value; + + if (!selectedSite.endsWith('/')) { + selectedSite = selectedSite + '/'; + } + } + } + + return selectedSite; } function sortListDir() { - var list, i, switching, b, shouldSwitch, dir, switchcount = 0; - list = document.getElementById("orderedList"); - switching = true; - //Set the sorting direction to ascending: - dir = "asc"; - //Make a loop that will continue until no switching has been done: - while (switching) { - //start by saying: no switching is done: - switching = false; - b = list.getElementsByTagName("LI"); - //Loop through all list-items: - for (i = 0; i < (b.length - 1); i++) { - //start by saying there should be no switching: - shouldSwitch = false; - /*check if the next item should switch place with the current item, - based on the sorting direction (asc or desc):*/ - if (dir == "asc") { - if (b[i].innerText.toLowerCase() > b[i + 1].innerText.toLowerCase()) { - console.log("THE TEXT--" + b[i].innerText); - /*if next item is alphabetically lower than current item, - mark as a switch and break the loop:*/ - shouldSwitch= true; - break; - } - } else if (dir == "desc") { - if (b[i].innerText.toLowerCase() < b[i + 1].innerText.toLowerCase()) { - console.log("THE TEXT--" + b[i].innerText); - /*if next item is alphabetically higher than current item, - mark as a switch and break the loop:*/ - shouldSwitch= true; - break; - } - } + var list, i, switching, b, shouldSwitch, dir, switchcount = 0; + list = document.getElementById("orderedList"); + switching = true; + //Set the sorting direction to ascending: + dir = "asc"; + //Make a loop that will continue until no switching has been done: + while (switching) { + //start by saying: no switching is done: + switching = false; + b = list.getElementsByTagName("LI"); + //Loop through all list-items: + for (i = 0; i < (b.length - 1); i++) { + //start by saying there should be no switching: + shouldSwitch = false; + /*check if the next item should switch place with the current item, + based on the sorting direction (asc or desc):*/ + if (dir == "asc") { + if (b[i].innerText.toLowerCase() > b[i + 1].innerText.toLowerCase()) { + console.log("THE TEXT--" + b[i].innerText); + /*if next item is alphabetically lower than current item, + mark as a switch and break the loop:*/ + shouldSwitch= true; + break; } - if (shouldSwitch) { - /*If a switch has been marked, make the switch - and mark that a switch has been done:*/ - b[i].parentNode.insertBefore(b[i + 1], b[i]); - switching = true; - //Each time a switch is done, increase switchcount by 1: - switchcount ++; - } 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") { - dir = "desc"; - switching = true; - - } + } else if (dir == "desc") { + if (b[i].innerText.toLowerCase() < b[i + 1].innerText.toLowerCase()) { + console.log("THE TEXT--" + b[i].innerText); + /*if next item is alphabetically higher than current item, + mark as a switch and break the loop:*/ + shouldSwitch= true; + break; } + } + } + if (shouldSwitch) { + /*If a switch has been marked, make the switch + and mark that a switch has been done:*/ + b[i].parentNode.insertBefore(b[i + 1], b[i]); + switching = true; + //Each time a switch is done, increase switchcount by 1: + switchcount ++; + } 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") { + dir = "desc"; + switching = true; + + } } - chngSortBtnValue(); + } + chngSortBtnValue(); } function chngSortBtnValue() { - var sortImg = document.getElementById('sortListDir'); - console.log(sortImg.getAttribute('src')); - if (sortImg.getAttribute('src') === "./icons/Small_A_Z.jpg") { - //sortImg.nextSibling.textContent = "Sort Z to A"; - sortImg.setAttribute('src', './icons/Small_Z_A.jpg'); - } else if (sortImg.getAttribute('src') === "./icons/Small_Z_A.jpg") { - //sortImg.nextSibling.textContent = "Sort A to Z"; - sortImg.setAttribute('src', './icons/Small_A_Z.jpg'); - } + var sortImg = document.getElementById('sortListDir'); + console.log(sortImg.getAttribute('src')); + if (sortImg.getAttribute('src') === "./icons/Small_A_Z.jpg") { + //sortImg.nextSibling.textContent = "Sort Z to A"; + sortImg.setAttribute('src', './icons/Small_Z_A.jpg'); + } else if (sortImg.getAttribute('src') === "./icons/Small_Z_A.jpg") { + //sortImg.nextSibling.textContent = "Sort A to Z"; + sortImg.setAttribute('src', './icons/Small_A_Z.jpg'); + } } function searchInSite (queryString) { - var urlSite = ''; - var searchText = document.getElementById('searchTextBox').value; - console.log(searchText); - if (searchText) { - var url = new URL(currentUrl); - - var selectedSite = getSearchSite(); - - if (selectedSite.indexOf('yahoo') > -1) { - urlSite = selectedSite + 'search;?p=' + searchText + '%20site:' + url.hostname; - } else { - urlSite = selectedSite + 'search?q=' + searchText + '%20site:' + url.hostname; - } - - chrome.tabs.update(currentTab.id, {url: urlSite}); - - } - window.close(); + var urlSite = ''; + var searchText = document.getElementById('searchTextBox').value; + console.log(searchText); + if (searchText) { + var url = new URL(currentUrl); + + var selectedSite = getSearchSite(); + + if (selectedSite.indexOf('yahoo') > -1) { + urlSite = selectedSite + 'search;?p=' + searchText + '%20site:' + url.hostname; + } else { + urlSite = selectedSite + 'search?q=' + searchText + '%20site:' + url.hostname; + } + + chrome.tabs.update(currentTab.id, {url: urlSite}); + + } + window.close(); } - + 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) { - console.log(url.parentNode); - 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); - }); - }); - } - - }); - - - window.close(); + 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) { + console.log(url.parentNode); + 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); + }); + }); + } + + }); + + + window.close(); }, true); function saveSelection() { - getCurrentTabUrl(function(tab) { - currentUrl = tab.url; - var url = new URL(tab.url); - var fullDomain = url.hostname; - console.log("dom-" + fullDomain); - var name = getDomainName(tab.url); - - chrome.storage.sync.get( "jsonData", function(items) { - console.log(JSON.stringify(items)); - var origObj = items.jsonData; - var prefForDom = getPreferences(fullDomain, name, origObj); - - if (prefForDom) { - if (Array.isArray(prefForDom)) { - const allUrls = document.getElementsByName("link"); - allUrls.forEach (function (url) { - console.log("chkd--" + url.checked); - console.log("val--" + url.value); - console.log(url.labels[0].innerText); - console.log(JSON.stringify(prefForDom)); - console.log(prefForDom.length + "---long"); - var label = url.labels[0].innerText; - //if (label) //need to remove (currentTab from label) - if (label.indexOf("Current Tab")) { - label = label.split('(')[0]; - } - for (var i=0; i < prefForDom.length; i++) { - if (typeof prefForDom[i] === 'object') { - console.log(prefForDom[i]) ; - if (Object.keys(prefForDom[i])[0] === label) { - if (typeof Object.values(prefForDom[i])[0] === 'object') { - prefForDom[i][label]['selected'] = url.checked; - } else { - prefForDom[i][label] = {'selected' : url.checked, url : Object.values(prefForDom[i])[0]}; - } - - } - } else { - if (prefForDom[i] === url.value) { - prefForDom[i] = {[label] : {'selected' : url.checked, url : url.value}}; - } - } - } - console.log(JSON.stringify(prefForDom)); - - }); - } else { - var options = prefForDom; - var type = document.getElementById("typeSelect"); - var selectedType = type.options[type.selectedIndex].value; - - var allTypes = options[selectedType]; - if (Array.isArray(options[selectedType])){ - const allUrls = document.getElementsByName("link"); - - allUrls.forEach (function (url) { - var label = url.labels[0].innerText; - if (label.indexOf("Current Tab")) { - label = label.split('(')[0]; - } - for (var i=0; i < allTypes.length; i++) { - //console.log("vaan" + JSON.stringify(allTypes[i])); - if (typeof allTypes[i] === 'object') { - if (Object.keys(allTypes[i])[0] === label) { - if (typeof Object.values(allTypes[i])[0] === 'object') { - prefForDom[selectedType][i][label]['selected'] = url.checked; - } else { - prefForDom[selectedType][i][label] = {'selected' : url.checked, url : Object.values(allTypes[i])[0]}; - } - - } - } else { - if (allTypes[i] === url.value) { - prefForDom[selectedType][i]= {[label] : {'selected' : url.checked, url : url.value}}; - } - } - } - console.log(JSON.stringify(prefForDom)); - - }); - } - } - } - console.log(JSON.stringify(origObj)); - chrome.storage.sync.set({ - jsonData: origObj}, - function() { - // Update status to let user know options were saved. - var status = document.getElementById('status'); - status.textContent = 'Options saved.'; - setTimeout(function() { - status.textContent = ''; - }, 750); - }); - }); - }); - - /*const allUrls = document.getElementsByName("link"); - var parentNode = allUrls[0].parentNode.parentNode.childNodes; - changeSelection(parentNode);*/ + getCurrentTabUrl(function(tab) { + currentUrl = tab.url; + var url = new URL(tab.url); + var fullDomain = url.hostname; + console.log("dom-" + fullDomain); + var name = getDomainName(tab.url); + + chrome.storage.sync.get( "jsonData", function(items) { + console.log(JSON.stringify(items)); + var origObj = items.jsonData; + var prefForDom = getPreferences(fullDomain, name, origObj); + + if (prefForDom) { + if (Array.isArray(prefForDom)) { + const allUrls = document.getElementsByName("link"); + allUrls.forEach (function (url) { + console.log("chkd--" + url.checked); + console.log("val--" + url.value); + console.log(url.labels[0].innerText); + console.log(JSON.stringify(prefForDom)); + console.log(prefForDom.length + "---long"); + var label = url.labels[0].innerText; + //if (label) //need to remove (currentTab from label) + if (label.indexOf("Current Tab")) { + label = label.split('(')[0]; + } + for (var i=0; i < prefForDom.length; i++) { + if (typeof prefForDom[i] === 'object') { + console.log(prefForDom[i]) ; + if (Object.keys(prefForDom[i])[0] === label) { + if (typeof Object.values(prefForDom[i])[0] === 'object') { + prefForDom[i][label]['selected'] = url.checked; + } else { + prefForDom[i][label] = {'selected' : url.checked, url : Object.values(prefForDom[i])[0]}; + } + + } + } else { + if (prefForDom[i] === url.value) { + prefForDom[i] = {[label] : {'selected' : url.checked, url : url.value}}; + } + } + } + console.log(JSON.stringify(prefForDom)); + + }); + } else { + var options = prefForDom; + var type = document.getElementById("typeSelect"); + var selectedType = type.options[type.selectedIndex].value; + + var allTypes = options[selectedType]; + if (Array.isArray(options[selectedType])){ + const allUrls = document.getElementsByName("link"); + + allUrls.forEach (function (url) { + var label = url.labels[0].innerText; + if (label.indexOf("Current Tab")) { + label = label.split('(')[0]; + } + for (var i=0; i < allTypes.length; i++) { + //console.log("vaan" + JSON.stringify(allTypes[i])); + if (typeof allTypes[i] === 'object') { + if (Object.keys(allTypes[i])[0] === label) { + if (typeof Object.values(allTypes[i])[0] === 'object') { + prefForDom[selectedType][i][label]['selected'] = url.checked; + } else { + prefForDom[selectedType][i][label] = {'selected' : url.checked, url : Object.values(allTypes[i])[0]}; + } + + } + } else { + if (allTypes[i] === url.value) { + prefForDom[selectedType][i]= {[label] : {'selected' : url.checked, url : url.value}}; + } + } + } + console.log(JSON.stringify(prefForDom)); + + }); + } + } + } + console.log(JSON.stringify(origObj)); + chrome.storage.sync.set({ + jsonData: origObj}, + function() { + // Update status to let user know options were saved. + var status = document.getElementById('status'); + status.textContent = 'Options saved.'; + setTimeout(function() { + status.textContent = ''; + }, 750); + }); + }); + }); + + /*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').disabled = true; - document.getElementById("error").innerHTML = ""; - } else { - document.getElementById('openbtn').disabled = false; - } + let txtAreaContent = this.value; + console.log("in txt are" + txtAreaContent); + if (txtAreaContent === '') { + document.getElementById('openbtn').disabled = true; + document.getElementById("error").innerHTML = ""; + } else { + 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; + //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"); + /* var bgPage = chrome.extension.getBackgroundPage(); + console.log("before"); var bk = bgPage.test("abc"); // Here paste() is a function that returns value. - console.log("beforeAAA--" + bk);*/ - document.getElementById('mainStuff').hidden = true; - document.getElementById('cancelbtn').addEventListener('click', closeWindow); - document.getElementById('openbtn').addEventListener('click', clickHandler); - document.getElementById('selectall').addEventListener('click', selectall); - document.getElementById('addbtn').addEventListener('click', addUrl); - document.getElementById('savebtn').addEventListener('click', saveSelection); - //document.getElementById('searchAgain').addEventListener('click', searchAgain); - document.getElementById('sortListDir').addEventListener('click', sortListDir); - //document.getElementById('searchbtn').addEventListener('click', searchInSite); - //onclick="()"; - console.log("lod--" + loading); - console.log("jsondata--" + jsonData); - var content = document.getElementById('content'); + console.log("beforeAAA--" + bk);*/ + document.getElementById('mainStuff').hidden = true; + document.getElementById('cancelbtn').addEventListener('click', closeWindow); + document.getElementById('openbtn').addEventListener('click', clickHandler); + document.getElementById('selectall').addEventListener('click', selectall); + document.getElementById('addbtn').addEventListener('click', addUrl); + document.getElementById('savebtn').addEventListener('click', saveSelection); + //document.getElementById('searchAgain').addEventListener('click', searchAgain); + document.getElementById('sortListDir').addEventListener('click', sortListDir); + //document.getElementById('searchbtn').addEventListener('click', searchInSite); + //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() {}); - /*if (cnnLoading === 'loading') { - window.close(); - return; - }*/ - 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]; - 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);*/ - - } - - } else { - var mesg = "Bank Page."; - noConfigFound(content, mesg); - } - }); - - 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); - }); - }); - + //chrome.storage.sync.set({parentUrl: ""}, function() {}); + /*if (cnnLoading === 'loading') { + window.close(); + return; + }*/ + 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]; + 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);*/ + + } + + } else { + var mesg = "Bank Page."; + noConfigFound(content, mesg); + } + }); + + 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); + }); + }); + }); 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); - + 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); + } -function updateList(ele) { - +function updateList(ele) { + 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); - loadList(googleSearch[name], content, name); - } 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; - loadList(getPreferences(url.hostname, name), content, name); - } - - //content.removeAll(); - + 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); + loadList(googleSearch[name], content, name); + } 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; + loadList(getPreferences(url.hostname, name), content, name); + } + + //content.removeAll(); + } 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(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').disabled = true; - //document.getElementById('cancelbtn').hidden = "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').disabled = false; - } - document.getElementById('anonymus').onkeyup = editTextArea; - - - divTxt.appendChild(pre); - content.appendChild(divTxt); - + 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(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').disabled = true; + //document.getElementById('cancelbtn').hidden = "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').disabled = false; + } + document.getElementById('anonymus').onkeyup = editTextArea; + + + divTxt.appendChild(pre); + content.appendChild(divTxt); + } function createRadio(content) { - //var engDom = getDomain(searchEngine); - //var engine = engDom.split('.')[0]; - //var engineUrl = new URL(searchEngine); - //console.log("url hostname eng-" + engineUrl.hostname); - var engine; - if (searchPage) { - //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/']; //searchSites.split(',');//, 'https://www.youtube.com/' - - var searchContent = document.getElementById('searchContent'); - - var searchDiv = document.createElement('div'); - searchDiv.id = "searchDiv"; - searchDiv.style.margin = "0px 0px 0px 25px"; - searchDiv.style.width = '300px'; - - var searchLbl = document.createElement('label'); - searchLbl.innerHTML = "search in"; - searchLbl.style.marginLeft = "25px"; - searchContent.appendChild(searchLbl); - var br = document.createElement('br'); - searchContent.appendChild(br); - /*var margin = true;*/ - - var both; - - sitesArr.forEach(function (site) { - var url = new URL(site); - console.log("url hostname-" + url.hostname); - var name = getDomainName(site);//url.hostname.split('.')[1]; - //var domain = getDomain(site); - //var name = domain.split('.')[0]; - console.log("name " + name); - console.log("engg " + engine); - if (searchPage && name === engine) { - return; - } - - both = both ? both + "," + site : site; - console.log("both " + both); - var radio = document.createElement("INPUT"); - radio.setAttribute("type", "radio"); - radio.setAttribute("value", site); - radio.setAttribute("name", "site"); - selectAll ? radio.disabled = true : radio.disabled = false; - //radio.setAttribute("id", "site"); - //radio.style.marginLeft = "10px"; - console.log("site " + site); - console.log("eng " + searchEngine); - /*var url = new URL(site); - var fullDomain = url.hostname;*/ - var label = document.createElement("label"); - label.innerHTML = name; - //content.appendChild(radio); - //content.appendChild(label); - searchDiv.appendChild(radio); - searchDiv.appendChild(label); - searchContent.appendChild(searchDiv); - - - }); - - - var searchAgainBtn = document.createElement('input'); - searchAgainBtn.setAttribute("type", "button"); - selectAll ? searchAgainBtn.disabled = true : searchAgainBtn.disabled = false; - if (searchPage) { - var radio = document.createElement("INPUT"); - radio.setAttribute("type", "radio"); - radio.setAttribute("value", both); - radio.setAttribute("name", "site"); - selectAll ? radio.disabled = true : radio.disabled = false; - var label = document.createElement("label"); - label.innerHTML = "Both"; - searchDiv.appendChild(radio); - searchDiv.appendChild(label); - searchAgainBtn.setAttribute("id", "searchAgain"); - searchAgainBtn.setAttribute("value", "Search Again"); - searchAgainBtn.onclick = searchAgain; - } else { - var searchAgainTxt = document.createElement('input'); - searchAgainTxt.setAttribute("type", "text"); - searchAgainTxt.setAttribute("id", "searchTextBox"); - selectAll ? searchAgainTxt.disabled = true : searchAgainTxt.disabled = false; - //fsearchAgainTxt.style.marginLeft = "25px"; - searchDiv.appendChild(searchAgainTxt); - searchAgainBtn.setAttribute("id", "searchbtn"); - searchAgainBtn.setAttribute("value", "Search"); - searchAgainBtn.onclick = searchInSite; - } - searchAgainBtn.style.marginLeft = '2px'; - searchDiv.appendChild(searchAgainBtn); - - searchContent.appendChild(searchDiv); - - /*if (selectAll) { - const allUrls = document.getElementsByName("link"); - if (allUrls.length > -1) { - if (howManyChecked(allUrls[0].parentNode.parentNode.childNodes)) { - //radio.disabled = true; - searchAgainBtn.disabled = true; - document.getElementsByName('site')[0].style.disabled = true; - document.getElementsByName('site')[1].style.disabled = true; - document.getElementsByName('site')[2].style.disabled = true; - if (!searchPage) { - document.getElementById('searchTextBox').style.disabled = true; - } - } - - } - }*/ - - + //var engDom = getDomain(searchEngine); + //var engine = engDom.split('.')[0]; + //var engineUrl = new URL(searchEngine); + //console.log("url hostname eng-" + engineUrl.hostname); + var engine; + if (searchPage) { + //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/']; //searchSites.split(',');//, 'https://www.youtube.com/' + + var searchContent = document.getElementById('searchContent'); + + var searchDiv = document.createElement('div'); + searchDiv.id = "searchDiv"; + searchDiv.style.margin = "0px 0px 0px 25px"; + searchDiv.style.width = '300px'; + + var searchLbl = document.createElement('label'); + searchLbl.innerHTML = "search in"; + searchLbl.style.marginLeft = "25px"; + searchContent.appendChild(searchLbl); + var br = document.createElement('br'); + searchContent.appendChild(br); + /*var margin = true;*/ + + var both; + + sitesArr.forEach(function (site) { + var url = new URL(site); + console.log("url hostname-" + url.hostname); + var name = getDomainName(site);//url.hostname.split('.')[1]; + //var domain = getDomain(site); + //var name = domain.split('.')[0]; + console.log("name " + name); + console.log("engg " + engine); + if (searchPage && name === engine) { + return; + } + + both = both ? both + "," + site : site; + console.log("both " + both); + var radio = document.createElement("INPUT"); + radio.setAttribute("type", "radio"); + radio.setAttribute("value", site); + radio.setAttribute("name", "site"); + selectAll ? radio.disabled = true : radio.disabled = false; + //radio.setAttribute("id", "site"); + //radio.style.marginLeft = "10px"; + console.log("site " + site); + console.log("eng " + searchEngine); + /*var url = new URL(site); + var fullDomain = url.hostname;*/ + var label = document.createElement("label"); + label.innerHTML = name; + //content.appendChild(radio); + //content.appendChild(label); + searchDiv.appendChild(radio); + searchDiv.appendChild(label); + searchContent.appendChild(searchDiv); + + + }); + + + var searchAgainBtn = document.createElement('input'); + searchAgainBtn.setAttribute("type", "button"); + selectAll ? searchAgainBtn.disabled = true : searchAgainBtn.disabled = false; + if (searchPage) { + var radio = document.createElement("INPUT"); + radio.setAttribute("type", "radio"); + radio.setAttribute("value", both); + radio.setAttribute("name", "site"); + selectAll ? radio.disabled = true : radio.disabled = false; + var label = document.createElement("label"); + label.innerHTML = "Both"; + searchDiv.appendChild(radio); + searchDiv.appendChild(label); + searchAgainBtn.setAttribute("id", "searchAgain"); + searchAgainBtn.setAttribute("value", "Search Again"); + searchAgainBtn.onclick = searchAgain; + } else { + var searchAgainTxt = document.createElement('input'); + searchAgainTxt.setAttribute("type", "text"); + searchAgainTxt.setAttribute("id", "searchTextBox"); + selectAll ? searchAgainTxt.disabled = true : searchAgainTxt.disabled = false; + //fsearchAgainTxt.style.marginLeft = "25px"; + searchDiv.appendChild(searchAgainTxt); + searchAgainBtn.setAttribute("id", "searchbtn"); + searchAgainBtn.setAttribute("value", "Search"); + searchAgainBtn.onclick = searchInSite; + } + searchAgainBtn.style.marginLeft = '2px'; + searchDiv.appendChild(searchAgainBtn); + + searchContent.appendChild(searchDiv); + + /*if (selectAll) { + const allUrls = document.getElementsByName("link"); + if (allUrls.length > -1) { + if (howManyChecked(allUrls[0].parentNode.parentNode.childNodes)) { + //radio.disabled = true; + searchAgainBtn.disabled = true; + document.getElementsByName('site')[0].style.disabled = true; + document.getElementsByName('site')[1].style.disabled = true; + document.getElementsByName('site')[2].style.disabled = true; + if (!searchPage) { + document.getElementById('searchTextBox').style.disabled = true; + } + } + + } + }*/ + + } function randomIntFromInterval(min,max) @@ -1310,266 +1310,266 @@ function randomIntFromInterval(min,max) } function getPreferences(url_hostname, name, dataObj) { - if (dataObj === undefined) { - dataObj = jsonData; - } - console.log(url_hostname + " -- " + name ); - let pref;// = []; - for (var item in dataObj) { - let domain; - domain = dataObj[item]['current']; - console.log("DOMAIN--" + domain); - if (domain.indexOf(',') === -1) { - console.log("in no comma"); - //pref = []; - //if (domain === url_hostname || domain === name) { - if (domain.indexOf(url_hostname) > -1 || domain.indexOf(name) > -1) { - console.log("name matched....") - if (domain.indexOf('http://') !== -1) { - baseUrl = domain; - } else { - baseUrl = 'http://' + domain; - } - var sites = dataObj[item]['sites']; - pref = sites; - console.log("sites--" + sites); - } - console.log("in get pref " + JSON.stringify(pref)); - } else { - var domArr = domain.split(','); - domArr.forEach(function(hostname){ - if (url_hostname === hostname || name === hostname) { - pref = dataObj[item]['sites']; - } - }); - console.log("in get pref " + pref); - } - } - console.log(pref); - return pref; - -} + if (dataObj === undefined) { + dataObj = jsonData; + } + console.log(url_hostname + " -- " + name ); + let pref;// = []; + for (var item in dataObj) { + let domain; + domain = dataObj[item]['current']; + console.log("DOMAIN--" + domain); + if (domain.indexOf(',') === -1) { + console.log("in no comma"); + //pref = []; + //if (domain === url_hostname || domain === name) { + if (domain.indexOf(url_hostname) > -1 || domain.indexOf(name) > -1) { + console.log("name matched....") + if (domain.indexOf('http://') !== -1) { + baseUrl = domain; + } else { + baseUrl = 'http://' + domain; + } + var sites = dataObj[item]['sites']; + pref = sites; + console.log("sites--" + sites); + } + console.log("in get pref " + JSON.stringify(pref)); + } else { + var domArr = domain.split(','); + domArr.forEach(function(hostname){ + if (url_hostname === hostname || name === hostname) { + pref = dataObj[item]['sites']; + } + }); + console.log("in get pref " + pref); + } + } + console.log(pref); + return pref; + +} function createList(allurls) { - - var list = document.createElement("OL"); - list.setAttribute("type", "1"); - list.setAttribute("id", "orderedList"); - //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)); - //console.log(Object.values(page)); - var input = document.createElement("INPUT"); - input.setAttribute("type", "checkbox"); - var label = document.createElement('label'); - - var linkObj, key, url; - if (typeof page === 'object') { - console.log("has key value"); - 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 { - 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); - } - } - - key = Object.keys(page)[0]; - - } - - } else { - var pageParts = page.split('/'); - console.log(pageParts.length); - console.log(pageParts[pageParts.length - 1] ); - linkObj = page; - if (linkObj.indexOf("http") === -1) { - linkObj = baseUrl + linkObj; - } - key = page.endsWith('/') ? pageParts[pageParts.length - 2] : pageParts[pageParts.length - 1]; - input.setAttribute("value", 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); - } - - } - input.setAttribute("name", "link"); - if (currentUrl === linkObj) { - key = key + "(Current Tab)"; - console.log("kkk"+key); - document.getElementById('addbtn').disabled = true; - } - var id = key; //Object.keys(page)[0]; - input.setAttribute("id", id); - input.onclick = chkBoxClick; - label.htmlFor = id; - - console.log("linkObj--" + linkObj); - console.log("currentUrl--" + currentUrl); - - - //var linkObj = Object.values(page)[0]; - - - - var li = document.createElement("LI"); - li.style.backgroundColor = bgColor; - if (searchPage) - li.style.margin = "10px 0"; - - //li.setAttribute("background-color" , "#FFFEEC"); - var logo = document.createElement("IMG"); - console.log("link " + Object.values(page)[0]); - logo.setAttribute("src", 'chrome://favicon/'+ linkObj); //Object.values(page)[0]); - logo.setAttribute("width", "20"); - logo.setAttribute("height", "12"); - - var link = document.createElement('a'); - link.textContent = id; - link.href = linkObj; //Object.values(page)[0]; - link.title = linkObj; - link.onclick = linkClick; - label.appendChild(link); - - - list.appendChild(li); - li.appendChild(input); - li.appendChild(logo); - li.appendChild(label); - //list.appendChild(input); - //list.appendChild(logo); - //list.appendChild(label); - //var line = document.createElement('br'); - //list.appendChild(line); - if (bgColor === "#EDEEED") {//ECF0F1 //"#F4F6F7" - bgColor = "#FFFFFF"; - } else { - bgColor = "#EDEEED"; //"#F4F6F7"; - } - }); - /*var howmany = document.getElementById("howmany"); - if (selectAll) { - howmany.textContent = allurls.length + " selected."; - } else { - howmany.textContent = "0 selected."; - }*/ - return list; - - + + var list = document.createElement("OL"); + list.setAttribute("type", "1"); + list.setAttribute("id", "orderedList"); + //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)); + //console.log(Object.values(page)); + var input = document.createElement("INPUT"); + input.setAttribute("type", "checkbox"); + var label = document.createElement('label'); + + var linkObj, key, url; + if (typeof page === 'object') { + console.log("has key value"); + 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 { + 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); + } + } + + key = Object.keys(page)[0]; + + } + + } else { + var pageParts = page.split('/'); + console.log(pageParts.length); + console.log(pageParts[pageParts.length - 1] ); + linkObj = page; + if (linkObj.indexOf("http") === -1) { + linkObj = baseUrl + linkObj; + } + key = page.endsWith('/') ? pageParts[pageParts.length - 2] : pageParts[pageParts.length - 1]; + input.setAttribute("value", 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); + } + + } + input.setAttribute("name", "link"); + if (currentUrl === linkObj) { + key = key + "(Current Tab)"; + console.log("kkk"+key); + document.getElementById('addbtn').disabled = true; + } + var id = key; //Object.keys(page)[0]; + input.setAttribute("id", id); + input.onclick = chkBoxClick; + label.htmlFor = id; + + console.log("linkObj--" + linkObj); + console.log("currentUrl--" + currentUrl); + + + //var linkObj = Object.values(page)[0]; + + + + var li = document.createElement("LI"); + li.style.backgroundColor = bgColor; + if (searchPage) + li.style.margin = "10px 0"; + + //li.setAttribute("background-color" , "#FFFEEC"); + var logo = document.createElement("IMG"); + console.log("link " + Object.values(page)[0]); + logo.setAttribute("src", 'chrome://favicon/'+ linkObj); //Object.values(page)[0]); + logo.setAttribute("width", "20"); + logo.setAttribute("height", "12"); + + var link = document.createElement('a'); + link.textContent = id; + link.href = linkObj; //Object.values(page)[0]; + link.title = linkObj; + link.onclick = linkClick; + label.appendChild(link); + + + list.appendChild(li); + li.appendChild(input); + li.appendChild(logo); + li.appendChild(label); + //list.appendChild(input); + //list.appendChild(logo); + //list.appendChild(label); + //var line = document.createElement('br'); + //list.appendChild(line); + if (bgColor === "#EDEEED") {//ECF0F1 //"#F4F6F7" + bgColor = "#FFFFFF"; + } else { + bgColor = "#EDEEED"; //"#F4F6F7"; + } + }); + /*var howmany = document.getElementById("howmany"); + if (selectAll) { + howmany.textContent = allurls.length + " selected."; + } else { + howmany.textContent = "0 selected."; + }*/ + return list; + + } function selectOption() { - var content = document.getElementById('content'); - var orderedList = document.getElementById('orderedList'); - if (orderedList) { - content.removeChild(orderedList); - } - - var type = document.getElementById("typeSelect"); - var selectedType = type.options[type.selectedIndex].value; - - //var allTypes = jsonData[type.name]; - var url = new URL(currentUrl); + var content = document.getElementById('content'); + var orderedList = document.getElementById('orderedList'); + if (orderedList) { + content.removeChild(orderedList); + } + + var type = document.getElementById("typeSelect"); + var selectedType = type.options[type.selectedIndex].value; + + //var allTypes = jsonData[type.name]; + var url = new URL(currentUrl); //var allTypes = jsonData[url.hostname] || jsonData[type.name]; - var allTypes = getPreferences(url.hostname, type.name); //jsonData[url.hostname] || jsonData[name]; - if (Array.isArray(allTypes[selectedType])){ - content.appendChild(createList(allTypes[selectedType])); - } - const allUrls = document.getElementsByName("link"); - var parentNode = allUrls[0].parentNode.parentNode.childNodes; - changeSelection(parentNode); - + var allTypes = getPreferences(url.hostname, type.name); //jsonData[url.hostname] || jsonData[name]; + if (Array.isArray(allTypes[selectedType])){ + content.appendChild(createList(allTypes[selectedType])); + } + const allUrls = document.getElementsByName("link"); + var parentNode = allUrls[0].parentNode.parentNode.childNodes; + changeSelection(parentNode); + } function createDropDown (data, hierarchy) { - var dropDown = document.createElement("SELECT"); - dropDown.setAttribute("id", "typeSelect"); - dropDown.setAttribute("name", hierarchy); - var keys = Object.keys(data); - keys.forEach(function (optn) { - var options = document.createElement("option"); - options.setAttribute("value", optn); - options.setAttribute("id", optn); - var txt = document.createTextNode(optn); - options.appendChild(txt); - if (optn.indexOf("default") > -1) { - options.selected = true; - } - dropDown.appendChild(options); - }); - dropDown.onchange = selectOption; - return dropDown; - + var dropDown = document.createElement("SELECT"); + dropDown.setAttribute("id", "typeSelect"); + dropDown.setAttribute("name", hierarchy); + var keys = Object.keys(data); + keys.forEach(function (optn) { + var options = document.createElement("option"); + options.setAttribute("value", optn); + options.setAttribute("id", optn); + var txt = document.createTextNode(optn); + options.appendChild(txt); + if (optn.indexOf("default") > -1) { + options.selected = true; + } + dropDown.appendChild(options); + }); + dropDown.onchange = selectOption; + return dropDown; + } - + function getDomain(url, subdomain) { - //var isSubdom = isSubdomain(url); - subdomain = subdomain || false; + //var isSubdom = isSubdomain(url); + subdomain = subdomain || false; url = url.replace(/(https?:\/\/)?(www.)?/i, ''); @@ -1588,127 +1588,127 @@ function getDomain(url, subdomain) { } function getCurrentTabUrl(callback) { - var queryInfo = { - active: true, - currentWindow: true - }; - - chrome.tabs.query(queryInfo, function(tabs) { - - var tab = tabs[0]; - //var url = tab.url; - currentTab = tab; - callback(tab); - }); - - chrome.windows.getCurrent(function(currentWindow) { - invokedWindow = currentWindow.id; - }); - -} - -function utubeClick() { - var idx = currentTab.index + 1; - chrome.tabs.create({url: this.href, active : false, index: idx, windowId : invokedWindow}, function(tab) { - - }); -} -function isParentGoogle(parentUrl) { - // var url = new URL(parentUrl); - // console.log("azhagiye...." + url.hostname); - //return google.indexOf(url.hostname) > -1; -} - -function isFromSearch(currentURL, name) { - //console.log("Check1 " + JSON.stringify(googleSearch)); - console.log("Check22 " + currentURL); - var urlFound = false; - if (googleSearch && googleSearch[name]) { - googleSearch[name].forEach(function (obj) { - var value = Object.values(obj); - console.log("Check3 " + value); - if (value == currentURL) { - console.log("ret true"); - urlFound = true; - } - }); - } - return urlFound; -} - -function getDomainName(url) { - var hostname = new URL(url).hostname; - var hostArr = hostname.split('.'); - console.log(hostArr.length + "---yyy"); - console.log(hostArr); - if (hostArr.length === 2) { - return hostArr[0]; - } else if (hostArr.length === 4) { - if (hostArr[0] === 'www') { - return hostArr[1]; - } else { - return hostArr[2]; - } - } else { - return hostArr[1]; - } -} - -function isUrlInList(currentURL, urlList) { - //console.log("Check1 " + JSON.stringify(googleSearch)); - console.log("Check22 " + currentURL); - var urlFound = false; + var queryInfo = { + active: true, + currentWindow: true + }; + + chrome.tabs.query(queryInfo, function(tabs) { + + var tab = tabs[0]; + //var url = tab.url; +currentTab = tab; + callback(tab); + }); + + chrome.windows.getCurrent(function(currentWindow) { + invokedWindow = currentWindow.id; + }); - urlList.forEach(function (obj) { - var value = Object.values(obj); - console.log("Check3 " + value); - if (value == currentURL) { - console.log("ret true"); - urlFound = true; - } - }); - - return urlFound; } - -chrome.runtime.onMessage.addListener(function(req, sender, sendres){ - if (req.cnnLoading === "complete") { - console.log("cnn loaded....") - } - - + + function utubeClick() { + var idx = currentTab.index + 1; + chrome.tabs.create({url: this.href, active : false, index: idx, windowId : invokedWindow}, function(tab) { + + }); + } + function isParentGoogle(parentUrl) { + // var url = new URL(parentUrl); + // console.log("azhagiye...." + url.hostname); + //return google.indexOf(url.hostname) > -1; + } + + function isFromSearch(currentURL, name) { + //console.log("Check1 " + JSON.stringify(googleSearch)); + console.log("Check22 " + currentURL); + var urlFound = false; + if (googleSearch && googleSearch[name]) { + googleSearch[name].forEach(function (obj) { + var value = Object.values(obj); + console.log("Check3 " + value); + if (value == currentURL) { + console.log("ret true"); + urlFound = true; + } + }); + } + return urlFound; + } + + function getDomainName(url) { + var hostname = new URL(url).hostname; + var hostArr = hostname.split('.'); + console.log(hostArr.length + "---yyy"); + console.log(hostArr); + if (hostArr.length === 2) { + return hostArr[0]; + } else if (hostArr.length === 4) { + if (hostArr[0] === 'www') { + return hostArr[1]; + } else { + return hostArr[2]; + } + } else { + return hostArr[1]; + } + } + + function isUrlInList(currentURL, urlList) { + //console.log("Check1 " + JSON.stringify(googleSearch)); + console.log("Check22 " + currentURL); + var urlFound = false; + + urlList.forEach(function (obj) { + var value = Object.values(obj); + console.log("Check3 " + value); + if (value == currentURL) { + console.log("ret true"); + urlFound = true; + } + }); + + return urlFound; + } + + chrome.runtime.onMessage.addListener(function(req, sender, sendres){ + if (req.cnnLoading === "complete") { + console.log("cnn loaded....") + } + + }); function loadList(prefForDom, content, name) { - if (Array.isArray(prefForDom)) { - console.log("pref dom is an array"); - if (prefForDom.length > 0) { - content.appendChild(createList(prefForDom)); - } else { - noConfigFound(content); - } - } 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 && searchPage) { - document.getElementById('selectall').checked = true; - } - createRadio(content); - //document.getElementById('addbtn').hidden = "hidden"; - const allUrls = document.getElementsByName("link"); - console.log(allUrls[0]); - var parentNode = allUrls[0].parentNode.parentNode.childNodes; - changeSelection(parentNode); - + if (Array.isArray(prefForDom)) { + console.log("pref dom is an array"); + if (prefForDom.length > 0) { + content.appendChild(createList(prefForDom)); + } else { + noConfigFound(content); + } + } 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 && searchPage) { + document.getElementById('selectall').checked = true; + } + createRadio(content); + //document.getElementById('addbtn').hidden = "hidden"; + const allUrls = document.getElementsByName("link"); + console.log(allUrls[0]); + var parentNode = allUrls[0].parentNode.parentNode.childNodes; + changeSelection(parentNode); + } From 59db6b1572762662d5387540272d29488b345c36 Mon Sep 17 00:00:00 2001 From: Gautam Date: Sun, 4 Feb 2018 23:25:21 -0600 Subject: [PATCH 6/8] Modified popup.js, background.js etc for fixes. --- background.js | 340 ++--- content_script.js | 908 +++++++------ manifest.json | 2 +- options.html | 52 +- options.js | 632 ++++----- popup.html | 126 +- popup.js | 3301 ++++++++++++++++++++++++--------------------- 7 files changed, 2823 insertions(+), 2538 deletions(-) diff --git a/background.js b/background.js index eebffec..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; @@ -20,23 +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"; - //console.log("currWindow--" + currWindow + "---" + invokedWind); - //if (currWindow === invokedWind) { - 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 ) @@ -45,101 +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); - 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() {}); + 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."); - } - + if (chrome.runtime.error) { + console.log("ddd Runtime error."); + } + }); var parentUrl = ""; @@ -154,74 +154,74 @@ 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("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; - } - } + 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; + } + } }); @@ -229,13 +229,13 @@ chrome.tabs.onUpdated.addListener(function(tabId , changeInfo, info) { chrome.browserAction.onClicked.addListener(function(tab) { console.log("call adi"); 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 326a56c..2182928 100644 --- a/content_script.js +++ b/content_script.js @@ -1,311 +1,362 @@ var jsonObj = {}; //jsonObj["current"] = "search"; -//jsonObj["description"] = "google search"; + //jsonObj["description"] = "google search"; var sites = []; var queryString = ""; var hrefAdded = []; 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; - /*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; - 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; - /*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; - /*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; - 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) { - 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'); - 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; - /*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)); - 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 = []; - }); + 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)); + //console.log("obj new-" + JSON.stringify(jsonObj)); } - - - - - + + + + + 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..'); - });*/ + //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..'); + });*/ } -/* +/* if (location.origin.indexOf('yahoo') > -1) { refreshObj(); @@ -339,7 +390,7 @@ if (location.origin.indexOf('yahoo') > -1) { obj[this.text] = location.origin + $(this).attr('href'); sites.push(obj); } - + //div#title-wrapper }); jsonObj['youtube'] = sites; @@ -353,7 +404,7 @@ if (location.origin.indexOf('yahoo') > -1) { } 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); @@ -361,12 +412,12 @@ if (location.origin.indexOf('yahoo') > -1) { //$(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) { @@ -379,8 +430,8 @@ if (location.origin.indexOf('yahoo') > -1) { obj[this.text] = $(this).attr('href'); sites.push(obj); } - - + + }); $("div.srg").find("h3 > a").each(function (index) { @@ -393,7 +444,7 @@ if (location.origin.indexOf('yahoo') > -1) { obj[this.text] = $(this).attr('href'); sites.push(obj); } - + }); jsonObj['google'] = sites; console.log("Final object...\n" + JSON.stringify(jsonObj)); @@ -405,7 +456,7 @@ if (location.origin.indexOf('yahoo') > -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'); @@ -420,7 +471,7 @@ if (location.origin.indexOf('yahoo') > -1) { 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); @@ -443,160 +494,161 @@ console.log(location.origin);*/ 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 = [];//[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)); + //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); chrome.runtime.onMessage.addListener(function(req, sender, sendres){ - if (req.exec) { - refreshObj(); - return; - } - - 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)); + } + }); - 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)); - } - }); + $("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 7907c7a..f3f25c7 100644 --- a/manifest.json +++ b/manifest.json @@ -43,7 +43,7 @@ "https://www.bing.com/*", "https://www.youtube.com/*", "https://in.yahoo.com/*", - "http://wwww.cnn.com/*", + "http://www.cnn.com/*", "https://stackoverflow.com/*", "https://www.washingtonpost.com/*" ], diff --git a/options.html b/options.html index fb3c2da..807ca47 100644 --- a/options.html +++ b/options.html @@ -1,26 +1,26 @@ - My Preferences Options - + @@ -30,25 +30,25 @@
-->