Skip to content

Commit

Permalink
eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix7139 committed Mar 2, 2019
1 parent 8637e91 commit e60ea61
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 106 deletions.
76 changes: 34 additions & 42 deletions options/js/options.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,56 @@
var recentSearchQueries=[];
var recentSearchQueryUrls=[];
var toggle = document.getElementById('theme');

if(!localStorage.getItem('theme'))
localStorage.setItem('theme', 'light');

if(localStorage.getItem('theme') == 'light')
{
/* eslint-disable no-unused-vars */
/* eslint-disable no-restricted-globals */
/* eslint-disable vars-on-top */
var recentSearchQueries = [];
var recentSearchQueryUrls = [];
var historyListElement;
var clearHistory;
var count;
var toggle = document.getElementById("theme");

if (!localStorage.getItem("theme")) localStorage.setItem("theme", "light");

if (localStorage.getItem("theme") === "light") {
console.log("light");
toggle.checked = false;
}
else
{
} else {
console.log("dark");
toggle.checked = true;
}

function handleThemeChange(event) {
if (toggle.checked==false)
localStorage.setItem('theme', 'light');
else
localStorage.setItem('theme', 'dark');
if (toggle.checked === false) localStorage.setItem("theme", "light");
else localStorage.setItem("theme", "dark");
}

document.addEventListener("DOMContentLoaded", function () {
var toggle = document.getElementById('theme');
toggle.addEventListener('click', handleThemeChange);
toggle = document.getElementById("theme");
toggle.addEventListener("click", handleThemeChange);
});

var historyListElement = document.getElementById("historyList");
var clearHistory = document.querySelector("#clearButton");
historyListElement = document.getElementById("historyList");
clearHistory = document.querySelector("#clearButton");

recentSearchQueries=(JSON.parse(localStorage.getItem('search')));
recentSearchQueryUrls=(JSON.parse(localStorage.getItem('link')));
recentSearchQueries = (JSON.parse(localStorage.getItem("search")));
recentSearchQueryUrls = (JSON.parse(localStorage.getItem("link")));

historyListElement.textContent="";
var count=0;
recentSearchQueries.forEach(function(entr)
{


var aTag = document.createElement('a');
aTag.setAttribute('target','_blank')
aTag.setAttribute('href',recentSearchQueryUrls[count]);
historyListElement.textContent = "";
count = 0;
recentSearchQueries.forEach(function (entr) {
var aTag = document.createElement("a");
aTag.setAttribute("target", "_blank");
aTag.setAttribute("href", recentSearchQueryUrls[count]);
aTag.innerHTML = entr;
historyListElement.appendChild(aTag);
var mybr = document.createElement('br');
var mybr = document.createElement("br");
historyListElement.appendChild(mybr);
var myhr = document.createElement('hr');
var myhr = document.createElement("hr");
historyListElement.appendChild(myhr);
count++;

})


count += 1;
});


clearHistory.addEventListener("click",function()
{
clearHistory.addEventListener("click", function () {
localStorage.clear();
location.reload();

});
});
112 changes: 48 additions & 64 deletions popup/js/popup.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
//Autofill Logic
var text=document.getElementById("query");
var suggestions=document.getElementsByClassName("suggestion");
/* eslint-disable vars-on-top */
/* eslint-disable no-redeclare */
/* eslint-disable block-scoped-var */
/* eslint-disable no-unused-vars */
// Autofill Logic
var text = document.getElementById("query");
var suggestions = document.getElementsByClassName("suggestion");
function handleData(data) {
if(data[0]!="")
{
for(var i=0;i<(suggestions.length);i++)
{
if(data[1].length>0)
{
suggestions[i].classList.remove("off");
suggestions[i].innerHTML=data[1][i][0];
}
if (data[0] !== "") {
for (var i = 0; i < (suggestions.length); i += 1) {
if (data[1].length > 0) {
suggestions[i].classList.remove("off");
suggestions[i].innerHTML = data[1][i][0];
}
}
}
};
text.addEventListener("keyup",function(req,res){
if(text.value=="")
{
for(var i=0;i<(suggestions.length);i++)
{
suggestions[i].innerHTML="";
suggestions[i].classList.add("off");
}
}
text.addEventListener("keyup", function (req, res) {
if (text.value === "") {
for (var i = 0; i < (suggestions.length); i += 1) {
suggestions[i].innerHTML = "";
suggestions[i].classList.add("off");
}
}
for(var i=0;i<(suggestions.length);i++)
{
suggestions[i].addEventListener("click",function(req,res){
text.value=this.textContent;
for(var i=0;i<(suggestions.length);i++)
{
for (var i = 0; i < (suggestions.length); i += 1) {
suggestions[i].addEventListener("click", function (req, res) {
text.value = this.textContent;
for (var i = 0; i < (suggestions.length); i += 1) {
suggestions[i].classList.add("off");
}
});
}
var script = document.createElement('script');
script.setAttribute('src','https://www.google.com/complete/search?client=psy-ab&hl=en-IN&gs_rn=64&gs_ri=psy-ab&tok=_vqJWTsUOepGe_q9mSti0A&cp=0&gs_id=9&q='+text.value+'&xhr=t&callback=handleData');
var script = document.createElement("script");
script.setAttribute("src", "https://www.google.com/complete/search?client=psy-ab&hl=en-IN&gs_rn=64&gs_ri=psy-ab&tok=_vqJWTsUOepGe_q9mSti0A&cp=0&gs_id=9&q=" + text.value + "&xhr=t&callback=handleData");
document.body.appendChild(script);
});
});

//To make Suggestions Disapper when user clicks outside query field
document.body.addEventListener("click", function(){
for(var i=0;i<(suggestions.length);i++)
{
suggestions[i].classList.add("off");
}
// To make Suggestions Disapper when user clicks outside query field
document.body.addEventListener("click", function () {
for (var i = 0; i < (suggestions.length); i += 1) {
suggestions[i].classList.add("off");
}
});
text.addEventListener("click",function(event){
text.addEventListener("click", function (event) {
event.stopPropagation();
});

Expand Down Expand Up @@ -204,53 +200,41 @@ function suggestion() {
var theme;

function themeChange() {

theme = localStorage.getItem("theme");
if(theme == 'light' )
localStorage.setItem( "theme" , "dark" );
else
localStorage.setItem("theme", "light");
if (theme === "light") { localStorage.setItem("theme", "dark"); } else { localStorage.setItem("theme", "light"); }

var bg = document.getElementById("content");
bg.classList.toggle("dark");

var labels = document.getElementsByTagName('label');
var labels = document.getElementsByTagName("label");
labels[0].classList.toggle("dark-label");
labels[1].classList.toggle("dark-label");
labels[2].classList.toggle("dark-label");

}

function recordSearchHistory()
{

var recentSearchQueries=[];
if(localStorage.getItem('search'))
recentSearchQueries=JSON.parse(localStorage.getItem('search'));
var x=text.value;
if(x!="" && recentSearchQueries.indexOf(x)==-1)
{
function recordSearchHistory() {
var recentSearchQueries = [];
if (localStorage.getItem("search")) { recentSearchQueries = JSON.parse(localStorage.getItem("search")); }
var x = text.value;
if (x !== "" && recentSearchQueries.indexOf(x) === -1) {
recentSearchQueries.push(x);
localStorage.setItem('search',JSON.stringify(recentSearchQueries));
}
localStorage.setItem("search", JSON.stringify(recentSearchQueries));
}
}


document.addEventListener("DOMContentLoaded", function () {
document.querySelector("button").addEventListener("click",function()
{
recordSearchHistory();
document.querySelector("button").addEventListener("click", function () {
recordSearchHistory();
register();
} );
});
document.addEventListener("keyup", keyboardShortCutListener, false);
suggestion();
suggestionAsValue();
if (!localStorage.getItem('theme'))
localStorage.setItem('theme', 'light');
if (!localStorage.getItem("theme")) { localStorage.setItem("theme", "light"); }

if(localStorage.getItem("theme") == 'dark')
{
if (localStorage.getItem("theme") === "dark") {
themeChange();
localStorage.setItem( "theme" , "dark" );
localStorage.setItem("theme", "dark");
}
});

0 comments on commit e60ea61

Please sign in to comment.