Skip to content

Commit

Permalink
Fix TMN query generation
Browse files Browse the repository at this point in the history
Extracted queries were no longer working. This fixes it
  • Loading branch information
Vincent Toubiana committed Oct 5, 2019
1 parent 04064aa commit afb5b51
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 29 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"tmn_search.js"
],
"run_at": "document_start",
"all_frames": true
"all_frames": false
}
],
"description": "Protect against data profiling by search engines",
Expand All @@ -38,5 +38,5 @@
"webNavigation",
"storage"
],
"version": "0.10.42"
"version": "0.10.45"
}
3 changes: 1 addition & 2 deletions option-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ function TMNShowEngines(item) {

function TMNShowQueries(tmn_queries) {

var htmlStr = '<a href="#dhs">DHS</a> | <a href="#rss"> RSS </a> | <a href="#popular"> Popular </a>|<a href="#extracted"> Extracted</a>';
htmlStr += '<div style="height:1000px;overflow:auto;"><table witdh=500 cellspacing=3 bgcolor=white frame=border>';
var htmlStr = '<div id="quarryarray" style="height:1000px;overflow:auto;"><table witdh=500 cellspacing=3 bgcolor=white frame=border>';
if ( tmn_queries.dhs ) {
htmlStr += '<tr style="color:Black" bgcolor=#D6E0E0 align=center>';
htmlStr += '<td > DHS Monitored <td>';
Expand Down
2 changes: 1 addition & 1 deletion options.html

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions tmn_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,16 @@ TRACKMENOT.TMNInjected = function() {
sendPageLoaded: function() {
var req = {};
req.tmn = "pageLoaded";
req.html = document.body.innerHTML;
api.runtime.sendMessage(req);
},

handleRequest: function(request, sender, sendResponse) {
if (request.getTMNHTML) {
var req = {};
req.tmn = "setHTML";
req.html = document.body.innerHTML;
api.runtime.sendMessage(req);
}
if (request.tmnQuery) {
/*if (tmn_id >= request.tmnID) {
debug("Duplicate queries ignored");
Expand All @@ -568,8 +573,9 @@ TRACKMENOT.TMNInjected = function() {
tmn_id = request.tmnID;
var tmn_URLmap = request.tmnUrlMap;
var encodedurl = sendQuery(engine, tmn_query, tmn_mode, tmn_URLmap);
window.onload = function() {setTimeout(TRACKMENOT.TMNInjected.sendPageLoaded,1000)};
TRACKMENOT.TMNInjected.sendPageLoaded();
}

if (request.click_eng) {
try {
simulateClick(request.click_eng);
Expand Down
52 changes: 30 additions & 22 deletions trackmenot.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ TRACKMENOT.TMNSearch = function() {

function randomElt(array) {
debug("Array length: " + array.length);
var index = roll(0, array.length - 1);
var index = Math.floor(Math.random() * array.length)
return array[index];
}

Expand Down Expand Up @@ -395,7 +395,6 @@ TRACKMENOT.TMNSearch = function() {
}

var phrases = new Array();

// Parse the HTML into phrases
var l = html.split(/((<\?tr>)|(<br>)|(<\/?p>))/i);
for (var i = 0; i < l.length; i++) {
Expand All @@ -407,22 +406,20 @@ TRACKMENOT.TMNSearch = function() {
if (!matches || matches.length < 2) continue;
var newQuery = trim(matches[1]);
// if ( phrases.length >0 ) newQuery.unshift(" ");
if (newQuery && phrases.indexOf(newQuery) < 0)
phrases.push(newQuery);
if (newQuery && phrases.indexOf(newQuery.toLowerCase()) < 0) {
phrases.push(newQuery.toLowerCase());
if (!TMNQueries.extracted) TMNQueries.extracted = [];
addQuery(newQuery, TMNQueries.extracted);
}
}
}
var queryToAdd = phrases.join(" ");
if (queryToAdd.length < 4)
return;
TMNQueries.extracted = [].concat(TMNQueries.extracted);
while (TMNQueries.extracted.length > 200) {
var rand = roll(0, TMNQueries.extracted.length - 1);
TMNQueries.extracted.splice(rand, 1);
}



cout(TMNQueries.extracted)
//if (typeoffeeds.indexOf('extracted') == -1)
// typeoffeeds.push('extracted');
addQuery(queryToAdd, TMNQueries.extracted);

}

function isBlackList(term) {
Expand Down Expand Up @@ -899,7 +896,7 @@ TRACKMENOT.TMNSearch = function() {
cout("Will send click event on: " + prev_engine);
try {
api.tabs.sendMessage(tmn_tab_id, {
click_eng: getEngineById(prev_engine)
"click_eng": getEngineById(prev_engine)
});
} catch (ex) {
cout(ex);
Expand All @@ -915,6 +912,13 @@ TRACKMENOT.TMNSearch = function() {
});

}
function getTMNHTML() {
var req = {}
req.getTMNHTML ="gethtml";
api.tabs.sendMessage(tmn_tab_id, req);
cout('Message sent to the tab: ' + tmn_tab_id + ' : ' + JSON.stringify(req));
}



function handleRequest(request, sender, sendResponse) {
Expand Down Expand Up @@ -954,22 +958,24 @@ TRACKMENOT.TMNSearch = function() {

switch (request.tmn) {
case "pageLoaded":
cout("The content of the page is:" + request.html);
extractQueries(request.html);
if (!tmn_hasloaded) {
tmn_hasloaded = true;
clearTimeout(tmn_errTimeout);
reschedule();
if (tmn_options.sim_clicks && (Math.random() < 0.3) ) {
var time = roll(10, 1000);
window.setTimeout(sendClickEvent, time);
}
} else {
window.setTimeout(getTMNHTML, 1000);
}
}
sendResponse({});
break;
case "tmnError": //Remove timer and then reschedule;
case "setHTML":
cout("The content of the page is:" + request.html);
extractQueries(request.html);
brek;
case "tmnError": //Remove timer and then reschedule;
clearTimeout(tmn_errTimeout);
rescheduleOnError();
sendResponse({});
Expand Down Expand Up @@ -1226,10 +1232,12 @@ TRACKMENOT.TMNSearch = function() {
api.tabs.get(tabId, function(tab) {
api.storage.local.set({"tab_url":tab.url});
});
if (tmn_options.sim_clicks && Math.random() < 0.3 ) {
if (tmn_options.sim_clicks && (Math.random() < 0.3) ) {
var time = roll(10, 1000);
window.setTimeout(sendClickEvent, time);
}
} else {
window.setTimeout(getTMNHTML, 1000);
}
}
}
},
Expand Down

0 comments on commit afb5b51

Please sign in to comment.