From 21125fa5416182d9a932376d3c0ae0577cf60094 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Sat, 3 Dec 2016 17:22:24 +0700 Subject: [PATCH] Bugfixing, less BS in console --- option-script.js | 8 --- options.html | 4 +- trackmenot.js | 134 ++++++++++++++++++++++++++--------------------- 3 files changed, 76 insertions(+), 70 deletions(-) diff --git a/option-script.js b/option-script.js index 5a4b8a8..43738c0 100644 --- a/option-script.js +++ b/option-script.js @@ -19,7 +19,6 @@ function loadHandlers() { $("#trackmenot-opt-showqueries").click( TMNShowQueries); - $("#validate-feed").click( function() { var feeds = $("#trackmenot-seed").val(); var param = {"feeds": feeds}; @@ -56,7 +55,6 @@ function loadHandlers() { ); } - function TMNSetOptionsMenu( ) { var options = tmn._getOptions(); var feedList = options.feedList; @@ -84,17 +82,11 @@ function TMNSetOptionsMenu( ) { setFrequencyMenu(options.timeout); } - - - - function setFrequencyMenu(timeout){ var menu = $("#trackmenot-opt-timeout"); $('#trackmenot-opt-timeout option[value=' +timeout+ ']').prop('selected', true); } - - function TMNClearLogs() { tmn._clearLogs(); TMNShowLog(); diff --git a/options.html b/options.html index b28b21e..d7005a1 100644 --- a/options.html +++ b/options.html @@ -6,10 +6,10 @@ - +
- +
diff --git a/trackmenot.js b/trackmenot.js index 253824b..3aed4e1 100644 --- a/trackmenot.js +++ b/trackmenot.js @@ -23,7 +23,7 @@ TRACKMENOT.TMNSearch = function() { var tmn_tab = null; var useTab = false; var enabled = true; - var debug_ = true; + var debug_ = false; var load_full_pages = false; var last_url = ""; var stop_when = "start"; @@ -236,7 +236,7 @@ TRACKMENOT.TMNSearch = function() { function clearLog() { tmnLogs = []; - sendLogToOption(); + chrome.storage.local.set({"logs_tmn":"{}"}); } function saveOptionFromTab(options) { @@ -301,7 +301,7 @@ TRACKMENOT.TMNSearch = function() { function createTab() { if (!useTab || tmn_tab_id != -1) return; - if(debug) cout('Creating tab for TrackMeNot'); + if(debug) console.log ('Creating tab for TrackMeNot'); try { chrome.tabs.create({ 'active': false, @@ -367,7 +367,10 @@ TRACKMENOT.TMNSearch = function() { } function trim(s) { - return s.replace(/\n/g,''); + if (s !== null) { + return s.replace(/\n/g,''); + } + return s; } function cerr(msg, e){ @@ -376,11 +379,7 @@ TRACKMENOT.TMNSearch = function() { txt += "\n" + e; if (e.message)txt+=" | "+e.message; } else txt += " / No Exception"; - cout(txt); - } - - function cout (msg) { - console.log(msg); + console.log (txt); } function debug (msg) { @@ -392,12 +391,6 @@ TRACKMENOT.TMNSearch = function() { return Math.floor(Math.random()*(max+1))+min; } - function randomElt(array) { - cout("Array length: "+array.length); - var index = roll(0,array.length-1); - return array[index]; - } - function monitorBurst() { chrome.webNavigation.onCommitted.addListener(function(e) { var url = e.url; @@ -442,7 +435,7 @@ TRACKMENOT.TMNSearch = function() { result = url.match(regex); if (result) { - cout(regex + " MATCHED! on "+eng.id ); + console.log (regex + " MATCHED! on "+eng.id ); id = eng.id; break; } @@ -456,7 +449,7 @@ TRACKMENOT.TMNSearch = function() { result.push(id); return result; } - cout("REGEX_ERROR: "+url); + console.log ("REGEX_ERROR: "+url); } result.push(id); return result; @@ -470,27 +463,42 @@ TRACKMENOT.TMNSearch = function() { return engines[Math.floor(Math.random()*engines.length)]; } + /** + * The function that constructs a random search query. + * Used in doSearch, also see getSubQuery() + */ function randomQuery() { + var randomElt = function (arr) { + var index = roll(0, arr.length - 1); + return arr[index]; + } + var qtype = randomElt(typeoffeeds); - cout(qtype); - var queries = []; - if ( qtype != 'zeitgeist' && qtype!='extracted') { - var queryset = TMNQueries[qtype]; - queries = randomElt(queryset).words; - } else queries = TMNQueries[qtype]; + debug (qtype); + var queries = TMNQueries[qtype]; + if ( qtype != 'zeitgeist' && qtype != 'extracted') { + queries = randomElt(queries) + if (queries !== undefined && queries.words !== undefined) { + queries = queries.words; + } else { + // no real result to return, try again + return randomQuery(); + } + } var term = trim( randomElt(queries) ); - if (!term || term.length<1) - throw new Error("queryIdx="+queryIdx+" getQuery.term='"+term+"'"); + if (!term || term.length<1) { + throw new Error("getQuery.term='"+term+"'"); + } return term; } function validateFeeds(param) { TMNQueries.rss = []; feedList = param.feeds; - cout("Validating the feeds: "+ feedList); + console.log ("Validating the feeds: "+ feedList); var feeds = feedList.split('|'); for (var i=0;i 0) + engines = JSON.parse( localStorage.engines ); + if (options.kw_black_list && opions.kw_black_list.length > 0) { kwBlackList = options.kw_black_list.split(","); + } } catch (ex) { - cout('No option recorded: '+ex); + console.trace(ex); + console.log ('No option recorded: '+ex); } } @@ -1068,7 +1076,7 @@ TRACKMENOT.TMNSearch = function() { function preserveTMNTab() { if ( useTab && enabled) { tmn_tab = null; - cout('TMN tab has been deleted by the user, reload it'); + console.log ('TMN tab has been deleted by the user, reload it'); createTab(); return; } @@ -1093,7 +1101,7 @@ TRACKMENOT.TMNSearch = function() { } } catch(ex){ - cout("[ERROR] "+ ex +" / "+ ex.message + "\nlogging msg"); + console.log ("[ERROR] "+ ex +" / "+ ex.message + "\nlogging msg"); } tmnLogs.unshift(entry); chrome.storage.local.set({"logs_tmn":JSON.stringify(tmnLogs)}); @@ -1101,7 +1109,7 @@ TRACKMENOT.TMNSearch = function() { function sendClickEvent() { if ( prev_engine ) { - cout("About to click on " + prev_engine); + console.log ("About to click on " + prev_engine); chrome.tabs.sendMessage(tmn_tab_id,{tmn_engine:getEngineById(prev_engine)}); } } @@ -1109,7 +1117,7 @@ TRACKMENOT.TMNSearch = function() { function handleRequest(request, sender, sendResponse) { if (request.tmnLog) { - cout("Background logging : " + request.tmnLog); + console.log ("Background logging : " + request.tmnLog); var logtext = JSON.parse(request.tmnLog); log(logtext); sendResponse({}); @@ -1121,7 +1129,7 @@ TRACKMENOT.TMNSearch = function() { return; } /*if (request.userSearch) { - cout("Detected User search") + console.log ("Detected User search") enterBurst(request.userSearch); sendResponse({}); return; @@ -1135,7 +1143,7 @@ TRACKMENOT.TMNSearch = function() { return; } if ( request.setURLMap) { - cout("Background handling : " + request.setURLMap); + console.log ("Background handling : " + request.setURLMap); var vars = request.setURLMap.split('--'); var eng = vars[0]; var asearch = vars[1]; @@ -1150,7 +1158,7 @@ TRACKMENOT.TMNSearch = function() { sendResponse({}); return; } - //cout("Background page received message: " + request.tmn); + //console.log ("Background page received message: " + request.tmn); switch (request.tmn) { case "currentURL": sendResponse({ @@ -1184,7 +1192,7 @@ TRACKMENOT.TMNSearch = function() { break; case "isActiveTab": var active = (!sender.tab || sender.tab.id==tmn_tab_id); - cout("active: "+ active); + console.log ("active: "+ active); sendResponse( {"isActive": active} ); @@ -1238,14 +1246,20 @@ TRACKMENOT.TMNSearch = function() { stop_when = "end"; } + if (useRss) { typeoffeeds.push('rss'); - TMNQueries.rss = []; - var feeds = feedList.split('|'); - if ( useRss ) { + TMNQueries.rss = []; + + var feeds = feedList.split('|'); for (var i=0;i