mirror of
https://github.com/Oreolek/TrackMeNot-Chrome.git
synced 2024-06-26 03:41:00 +03:00
Added features from the Firefox version
Code of Chrome and Firefox versions are now similar, there are only few lines that are specific to each version
This commit is contained in:
parent
59a7f8ba7c
commit
52ac38c9f0
|
@ -5,20 +5,22 @@
|
||||||
"description": "TMN portage on Chrome",
|
"description": "TMN portage on Chrome",
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
"default_icon": "tmn.png",
|
"default_icon": "tmn.png",
|
||||||
"popup": "menu.html"
|
"default_popup": "tmn_menu.html"
|
||||||
|
},
|
||||||
|
"background": {
|
||||||
|
"scripts": ["trackmenot.js"]
|
||||||
},
|
},
|
||||||
"background": "tmn_page.html",
|
|
||||||
"options_page": "options.html",
|
"options_page": "options.html",
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": ["http://*/*"],
|
"matches": ["http://*/*","https://*/*"],
|
||||||
"js": ["tmn_search.js", "rep_processor.js"],
|
"js": ["tmn_search.js"],
|
||||||
"run_at": "document_start",
|
"run_at": "document_start",
|
||||||
"all_frames" : true
|
"all_frames" : true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"tabs","http://*/*"
|
"tabs","https://*/*","webNavigation","storage"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
var tmn = null;
|
if(!TRACKMENOT) var TRACKMENOT = {};
|
||||||
|
|
||||||
|
TRACKMENOT.Menus = function() {
|
||||||
|
var tmn = null;
|
||||||
var tmn_option_query = '';
|
var tmn_option_query = '';
|
||||||
var tmn_option_engine = '';
|
var tmn_option_engine = '';
|
||||||
var options = null;
|
var options = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$("#trackmenot-menu-useTab").click(toggleTabFrame);
|
|
||||||
$("#trackmenot-enabled").click(toggleOnOff);
|
|
||||||
$("#trackmenot-menu-help").click(showHelp);
|
|
||||||
|
|
||||||
function _cout (msg) { console.log(msg); }
|
function _cout (msg) { console.log(msg); }
|
||||||
|
|
||||||
|
@ -15,43 +16,50 @@
|
||||||
window.open("http://www.cs.nyu.edu/trackmenot/faq.html")
|
window.open("http://www.cs.nyu.edu/trackmenot/faq.html")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
function toggleOnOff() {
|
toggleOnOff: function() {
|
||||||
options.enabled = !options.enabled
|
options.enabled = !options.enabled
|
||||||
tmn_options = {"options":options};
|
if( !options.enabled) tmn._stopTMN();
|
||||||
self.port.emit("TMNSaveOptions",tmn_options.options);
|
else tmn._restartTMN();
|
||||||
loadMenu(tmn_options)
|
|
||||||
}
|
tmn._saveOptions();
|
||||||
|
TRACKMENOT.Menus.onLoadMenu();
|
||||||
|
},
|
||||||
|
|
||||||
function toggleTabFrame() {
|
toggleTabFrame: function() {
|
||||||
options.useTab = !options.useTab
|
options.useTab = !options.useTab
|
||||||
tmn_options = {"options":options};
|
tmn.changeTabStatus(options.useTab);
|
||||||
self.port.emit("TMNSaveOptions",tmn_options.options);
|
tmn.saveOptions();
|
||||||
loadMenu(tmn_options)
|
TRACKMENOT.Menus.onLoadMenu();
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
onLoadMenu: function( ) {
|
||||||
|
tmn = chrome.extension.getBackgroundPage().TRACKMENOT.TMNSearch;
|
||||||
|
options = tmn._getOptions(); ;
|
||||||
|
tmn_option_query = tmn._getQuery();
|
||||||
|
tmn_option_engine = tmn._getEngine();
|
||||||
|
|
||||||
|
$("#trackmenot-label").html(tmn_option_engine + " '"+ tmn_option_query+"'");
|
||||||
|
|
||||||
|
|
||||||
|
if ( options.enabled) {
|
||||||
|
$("#trackmenot-enabled").html('Disable');
|
||||||
|
$("#trackmenot-img-enabled").attr("src", "images/skin/off_icon.png");
|
||||||
|
} else {
|
||||||
|
$("#trackmenot-enabled").html('Enable');
|
||||||
|
$("#trackmenot-img-enabled").attr("src", "images/skin/on_icon.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.useTab) $("#trackmenot-menu-useTab").html('Stealth');
|
||||||
|
else $("#trackmenot-menu-useTab").html('Tab')
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$("#trackmenot-menu-win").click(function() {
|
}();
|
||||||
self.port.emit("TMNOpenOption")
|
|
||||||
})
|
|
||||||
|
|
||||||
function loadMenu( panel_inputs) {
|
|
||||||
|
|
||||||
options = panel_inputs.options;
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
if ( panel_inputs.query && panel_inputs.engine )
|
$("#trackmenot-menu-useTab").click(TRACKMENOT.Menus.toggleTabFrame);
|
||||||
$("#trackmenot-label").html(panel_inputs.engine + " '"+ panel_inputs.query+"'");
|
$("#trackmenot-enabled").click(TRACKMENOT.Menus.toggleOnOff);
|
||||||
|
$("#trackmenot-menu-win").click(function() { window.open(chrome.extension.getURL('options.html'));});
|
||||||
|
TRACKMENOT.Menus.onLoadMenu()
|
||||||
if ( options.enabled) {
|
});
|
||||||
$("#trackmenot-enabled").html('Disable');
|
|
||||||
$("#trackmenot-img-enabled").attr("src", "images/skin/off_icon.png");
|
|
||||||
} else {
|
|
||||||
$("#trackmenot-enabled").html('Enable');
|
|
||||||
$("#trackmenot-img-enabled").attr("src", "images/skin/on_icon.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.useTab) $("#trackmenot-menu-useTab").html('Stealth');
|
|
||||||
else $("#trackmenot-menu-useTab").html('Tab')
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
self.port.on("TMNSendOption",loadMenu )
|
|
||||||
|
|
159
option-script.js
159
option-script.js
|
@ -1,66 +1,70 @@
|
||||||
|
|
||||||
var tmn_options ={};
|
var tmn_options ={};
|
||||||
|
var tmn = chrome.extension.getBackgroundPage().TRACKMENOT.TMNSearch;
|
||||||
$("#apply-options").click( function() {
|
var options = null;
|
||||||
tmn_options = {"options":saveOptions()};
|
|
||||||
TMNSetOptionsMenu(tmn_options);
|
function loadHandlers() {
|
||||||
alert("Configuration saved");
|
$("#apply-options").click( function() {
|
||||||
self.port.emit("TMNSaveOptions",tmn_options.options);
|
tmn_options = {"options":saveOptions()};
|
||||||
}
|
TMNSetOptionsMenu(tmn_options);
|
||||||
);
|
alert("Configuration saved");
|
||||||
|
chrome.runtime.sendMessage({'tmn':"TMNSaveOptions",'option':tmn_options.options});
|
||||||
$("#show-add").click( function() {
|
|
||||||
$("#add-engine-table").show();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
$("#show-log").click( function() {
|
|
||||||
self.port.emit("TMNOptionsShowLog");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$("#trackmenot-opt-showqueries").click( function() {
|
|
||||||
self.port.emit("TMNOptionsShowQueries");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$("#validate-feed").click( function() {
|
|
||||||
var feeds = $("#trackmenot-seed").val();
|
|
||||||
var param = {"feeds": feeds}
|
|
||||||
self.port.emit("TMNValideFeeds",param);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$("#clear-log").click( function() {
|
|
||||||
self.port.emit("TMNOptionsClearLog");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$("#search-engine-list").on('click', 'button.smallbutton', function(event) {
|
|
||||||
var del_engine = event.target.id.split("_").pop();
|
|
||||||
self.port.emit("TMNDelEngine",{'engine':del_engine});
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$("#add-engine").click( function() {
|
|
||||||
var engine = {}
|
|
||||||
engine.name = $("#newengine-name").val();
|
|
||||||
engine.urlmap = $("#newengine-map").val();
|
|
||||||
if(engine.urlmap.indexOf('trackmenot') <0 ) {
|
|
||||||
alert("Did not find 'trackmenot' in the URL")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
self.port.emit("TMNAddEngine",engine);
|
);
|
||||||
}
|
|
||||||
);
|
$("#show-add").click( function() {
|
||||||
|
$("#add-engine-table").show();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
$("#show-log").click( function() {
|
||||||
|
chrome.runtime.sendMessage({'tmn':"TMNOptionsShowLog"});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$("#trackmenot-opt-showqueries").click( function() {
|
||||||
|
chrome.runtime.sendMessage({'tmn':"TMNOptionsShowQueries"});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$("#validate-feed").click( function() {
|
||||||
|
var feeds = $("#trackmenot-seed").val();
|
||||||
|
var param = {"feeds": feeds}
|
||||||
|
chrome.runtime.sendMessage({'tmn':"TMNValideFeeds",'param':param});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$("#clear-log").click( function() {
|
||||||
|
chrome.runtime.sendMessage({'tmn':"TMNOptionsClearLog"});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
function TMNSetOptionsMenu( tab_inputs) {
|
$("#search-engine-list").on('click', 'button.smallbutton', function(event) {
|
||||||
var options = tab_inputs.options;
|
var del_engine = event.target.id.split("_").pop();
|
||||||
|
chrome.runtime.sendMessage({'tmn':"TMNDelEngine",'engine':del_engine});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$("#add-engine").click( function() {
|
||||||
|
var engine = {}
|
||||||
|
engine.name = $("#newengine-name").val();
|
||||||
|
engine.urlmap = $("#newengine-map").val();
|
||||||
|
if(engine.urlmap.indexOf('trackmenot') <0 ) {
|
||||||
|
alert("Did not find 'trackmenot' in the URL")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
chrome.runtime.sendMessage({'tmn':"TMNAddEngine",'engine': engine});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function TMNSetOptionsMenu( ) {
|
||||||
|
var options = tmn._getOptions();
|
||||||
var feedList = options.feedList;
|
var feedList = options.feedList;
|
||||||
var kw_black_list = options.kw_black_list;
|
var kw_black_list = options.kw_black_list;
|
||||||
console.log("Enabled: " +options.enabled)
|
//console.log("Enabled: " +options.enabled)
|
||||||
$("#add-engine-table").hide();
|
$("#add-engine-table").hide();
|
||||||
$("#trackmenot-opt-enabled").prop('checked', options.enabled);
|
$("#trackmenot-opt-enabled").prop('checked', options.enabled);
|
||||||
$("#trackmenot-opt-useTab").prop('checked',options.useTab);
|
$("#trackmenot-opt-useTab").prop('checked',options.useTab);
|
||||||
|
@ -76,7 +80,7 @@ function TMNSetOptionsMenu( tab_inputs) {
|
||||||
var engines = options.searchEngines.split(',');
|
var engines = options.searchEngines.split(',');
|
||||||
for( var i=0; i< engines.length;i++)
|
for( var i=0; i< engines.length;i++)
|
||||||
$("#"+engines[i]).prop('checked',true);
|
$("#"+engines[i]).prop('checked',true);
|
||||||
|
|
||||||
setFrequencyMenu(options.timeout);
|
setFrequencyMenu(options.timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +140,7 @@ function TMNShowEngines(engines) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function TMNShowQueries(param) {
|
function TMNShowQueries(param) {
|
||||||
var queries = param.queries.split(',');
|
var queries = param.queries.split(',');
|
||||||
var htmlStr = '<table witdh=500 cellspacing=3 bgcolor=white frame=border>';
|
var htmlStr = '<table witdh=500 cellspacing=3 bgcolor=white frame=border>';
|
||||||
for (var i=0; i< 3000 && i<queries.length ; i++) {
|
for (var i=0; i< 3000 && i<queries.length ; i++) {
|
||||||
htmlStr += '<tr style="color:Black">';
|
htmlStr += '<tr style="color:Black">';
|
||||||
|
@ -174,12 +178,47 @@ function saveOptions() {
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleRequest(request, sender, sendResponse) {
|
||||||
|
if (!request.options) return;
|
||||||
|
switch (request.options) {
|
||||||
|
case "TMNSetOptionsMenu":
|
||||||
|
TMNSetOptionsMenu(request.param);
|
||||||
|
sendResponse({})
|
||||||
|
break;
|
||||||
|
case "TMNSendLogs":
|
||||||
|
TMNShowLog(request.param.logs);
|
||||||
|
sendResponse({})
|
||||||
|
break;
|
||||||
|
case "TMNSendQueries":
|
||||||
|
TMNShowQueries(request.param.queries);
|
||||||
|
sendResponse({})
|
||||||
|
break;
|
||||||
|
case "TMNSendEngines":
|
||||||
|
TMNShowEngines(request.param);
|
||||||
|
sendResponse({})
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
sendResponse({}); // snub them.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
TMNShowEngines(tmn._getTargetEngines());
|
||||||
|
TMNSetOptionsMenu();
|
||||||
|
loadHandlers();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
chrome.runtime.onMessage.addListener(handleRequest);
|
||||||
|
/*
|
||||||
self.port.on("TMNSetOptionsMenu",TMNSetOptionsMenu)
|
self.port.on("TMNSetOptionsMenu",TMNSetOptionsMenu)
|
||||||
self.port.on("TMNSendLogs",TMNShowLog)
|
self.port.on("TMNSendLogs",TMNShowLog)
|
||||||
self.port.on("TMNSendQueries",TMNShowQueries)
|
self.port.on("TMNSendQueries",TMNShowQueries)
|
||||||
self.port.on("TMNSendEngines",TMNShowEngines)
|
self.port.on("TMNSendEngines",TMNShowEngines)*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,7 @@
|
||||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
||||||
<link href="style.css" rel="stylesheet">
|
<link href="style.css" rel="stylesheet">
|
||||||
|
<script src="jquery.js"></script>
|
||||||
|
<script src="menu-script.js"></script>
|
||||||
<html>
|
<html>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
@ -25,7 +27,7 @@
|
||||||
<td>
|
<td>
|
||||||
<hbox>
|
<hbox>
|
||||||
<img width='16' height='16' id="trackmenot-img-enabled" src="images/skin/on_icon.png" />
|
<img width='16' height='16' id="trackmenot-img-enabled" src="images/skin/on_icon.png" />
|
||||||
<label id="trackmenot-enabled" >
|
<label id="trackmenot-enabled" > Enabled </label>
|
||||||
</hbox>
|
</hbox>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -33,7 +35,7 @@
|
||||||
<td>
|
<td>
|
||||||
<hbox >
|
<hbox >
|
||||||
<img width='16' height='16' src="images/skin/option_icon.png" />
|
<img width='16' height='16' src="images/skin/option_icon.png" />
|
||||||
<label data-l10n-id="tmn.menu.options" id="trackmenot-menu-win" > </label>
|
<label data-l10n-id="tmn.menu.options" id="trackmenot-menu-win" > Options </label>
|
||||||
</hbox>
|
</hbox>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -41,7 +43,7 @@
|
||||||
<td>
|
<td>
|
||||||
<hbox >
|
<hbox >
|
||||||
<img width='16' height='16' src="images/skin/help_icon.png" />
|
<img width='16' height='16' src="images/skin/help_icon.png" />
|
||||||
<label data-l10n-id="tmn.menu.help" id="trackmenot-menu-help" > </label>
|
<label data-l10n-id="tmn.menu.help" id="trackmenot-menu-help" > Help </label>
|
||||||
</hbox>
|
</hbox>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
294
tmn_search.js
294
tmn_search.js
|
@ -26,6 +26,105 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
var engine = '';
|
var engine = '';
|
||||||
// var allEvents = ['blur','change','click','dblclick','DOMMouseScroll','focus','keydown','keypress','keyup','load','mousedown','mousemove','mouseout','mouseover','mouseup','select'];
|
// var allEvents = ['blur','change','click','dblclick','DOMMouseScroll','focus','keydown','keypress','keyup','load','mousedown','mousemove','mouseout','mouseover','mouseup','select'];
|
||||||
|
|
||||||
|
function getYahooId() {
|
||||||
|
var id = "A0geu";
|
||||||
|
while (id.length < 24) {
|
||||||
|
var lower = Math.random() < .5;
|
||||||
|
var num = parseInt(Math.random() * 38);
|
||||||
|
if (num === 37) {
|
||||||
|
id += '_';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (num === 36) {
|
||||||
|
id += '.';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (num < 10) {
|
||||||
|
id += String.fromCharCode(num + 48);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
num += lower ? 87 : 55;
|
||||||
|
id += String.fromCharCode(num);
|
||||||
|
}
|
||||||
|
//cout("GENERATED ID="+id);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
var testAd_google = function(anchorClass,anchorlink) {
|
||||||
|
return ( anchorlink
|
||||||
|
&& (anchorClass=='l' || anchorClass=='l vst')
|
||||||
|
&& anchorlink.indexOf('http')==0
|
||||||
|
&& anchorlink.indexOf('https')!=0);
|
||||||
|
}
|
||||||
|
|
||||||
|
var testAd_yahoo= function(anchorClass,anchorlink) {
|
||||||
|
return ( anchorClass=='\"yschttl spt\"' || anchorClass=='yschttl spt');
|
||||||
|
}
|
||||||
|
|
||||||
|
var testAd_aol = function(anchorClass,anchorlink) {
|
||||||
|
return (anchorClass=='\"find\"' || anchorClass=='find'
|
||||||
|
&& anchorlink.indexOf('https')!=0 && anchorlink.indexOf('aol')<0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
var testAd_bing = function(anchorClass,anchorlink) {
|
||||||
|
return ( anchorlink
|
||||||
|
&& anchorlink.indexOf('http')==0
|
||||||
|
&& anchorlink.indexOf('https')!=0
|
||||||
|
&& anchorlink.indexOf('msn')<0
|
||||||
|
&& anchorlink.indexOf('live')<0
|
||||||
|
&& anchorlink.indexOf('bing')<0
|
||||||
|
&& anchorlink.indexOf('microsoft')<0
|
||||||
|
&& anchorlink.indexOf('WindowsLiveTranslator')<0 ) }
|
||||||
|
|
||||||
|
var testAd_baidu = function(anchorClass,anchorlink) {
|
||||||
|
return ( anchorlink
|
||||||
|
&& anchorlink.indexOf('baidu')<0
|
||||||
|
&& anchorlink.indexOf('https')!=0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var getButton_google =" var getButton = function( ) {var button = getElementsByAttrValue(document,'button', 'name', 'btnG' ); if ( !button ) button = getElementsByAttrValue(document,'button', 'name', 'btnK' );return button;}"
|
||||||
|
var getButton_yahoo= " var getButton = function( ) {return getElementsByAttrValue(document,'input', 'class', 'sbb' ); } "
|
||||||
|
var getButton_bing= " var getButton = function( ) {return document.getElementById('sb_form_go');} "
|
||||||
|
var getButton_aol = " var getButton = function ( ) {return document.getElementById('csbbtn1'); }"
|
||||||
|
var getButton_baidu = " var getButton = function ( ){ return getElementsByAttrValue(document,'input', 'value', '????' ); }"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SearchBox_google = "var searchbox = function( ) { return getElementsByAttrValue(document,'input', 'name', 'q' ); } "
|
||||||
|
SearchBox_yahoo = "var searchbox = function( ) { return document.getElementById('yschsp');}"
|
||||||
|
SearchBox_bing= "var searchbox = function( ) {return document.getElementById('sb_form_q'); } "
|
||||||
|
SearchBox_aol= "var searchbox = function( ) {return document.getElementById('csbquery1'); }"
|
||||||
|
SearchBox_baidu= "var searchbox = function( ) {return document.getElementById('kw');}"
|
||||||
|
|
||||||
|
|
||||||
|
var suggest_google = ['gsr' , 'td', function ( elt ) {
|
||||||
|
return (elt.hasAttribute('class') && elt.getAttribute('class') == 'gac_c' )
|
||||||
|
}]
|
||||||
|
|
||||||
|
var suggest_yahoo = ['atgl' , 'a', function ( elt ) {
|
||||||
|
return elt.hasAttribute('gossiptext')
|
||||||
|
}]
|
||||||
|
|
||||||
|
var suggest_bing = ['sa_drw' , 'li', function ( elt ) {
|
||||||
|
return (elt.hasAttribute('class') && elt.getAttribute('class') == 'sa_sg' )
|
||||||
|
}]
|
||||||
|
|
||||||
|
var suggest_baidu = ['st' , 'tr', function ( elt ) {
|
||||||
|
return (elt.hasAttribute('class') && elt.getAttribute('class') == 'ml' )
|
||||||
|
}]
|
||||||
|
|
||||||
|
var suggest_aol = ['ACC' , 'a', function ( elt ) {
|
||||||
|
return (elt.hasAttribute('class') && elt.getAttribute('class') == 'acs')
|
||||||
|
}]
|
||||||
|
|
||||||
|
var engines = [
|
||||||
|
{'id':'google','name':'Google Search', 'urlmap':"https://www.google.com/search?hl=en&q=|", 'regexmap':"^(https?:\/\/[a-z]+\.google\.(co\\.|com\\.)?[a-z]{2,3}\/(search){1}[\?]?.*?[&\?]{1}q=)([^&]*)(.*)$", "host":"(www\.google\.(co\.|com\.)?[a-z]{2,3})$","testad":"var testad = function(ac,al) {return ( al&& (ac=='l' || ac=='l vst')&& al.indexOf('http')==0 && al.indexOf('https')!=0);}",'box':SearchBox_google,'button':getButton_google} ,
|
||||||
|
{'id':'yahoo','name':'Yahoo! Search', 'urlmap':"http://search.yahoo.com/search;_ylt=" +getYahooId()+"?ei=UTF-8&fr=sfp&fr2=sfp&p=|&fspl=1", 'regexmap':"^(https?:\/\/[a-z.]*?search\.yahoo\.com\/search.*?p=)([^&]*)(.*)$", "host":"([a-z.]*?search\.yahoo\.com)$","testad":"var testad = function(ac,al) {return ( ac=='\"yschttl spt\"' || ac=='yschttl spt');}",'box':SearchBox_yahoo,'button':getButton_yahoo},
|
||||||
|
{'id':'bing','name':'Bing Search', 'urlmap':"http://www.bing.com/search?q=|", 'regexmap':"^(https?:\/\/www\.bing\.com\/search\?[^&]*q=)([^&]*)(.*)$", "host":"(www\.bing\.com)$","testad":"var testad = function(ac,al) {return ( al&& al.indexOf('http')==0&& al.indexOf('https')!=0 && al.indexOf('msn')<0 && al.indexOf('live')<0 && al.indexOf('bing')<0&& al.indexOf('microsoft')<0 && al.indexOf('WindowsLiveTranslator')<0 ) }",'box':SearchBox_bing,'button':getButton_bing},
|
||||||
|
{'id':'baidu','name':'Baidu Search', 'urlmap':"http://www.baidu.com/s?wd=|", 'regexmap':"^(https?:\/\/www\.baidu\.com\/s\?.*?wd=)([^&]*)(.*)$", "host":"(www\.baidu\.com)$","testad":"var testad = function(ac,al) {return ( al&& al.indexOf('baidu')<0 && al.indexOf('https')!=0 );}",'box':SearchBox_baidu,'button':getButton_baidu},
|
||||||
|
{'id':'aol','name':'Aol Search', 'urlmap':"http://search.aol.com/aol/search?q=|", 'regexmap':"^(https?:\/\/[a-z0-9.]*?search\.aol\.com\/aol\/search\?.*?q=)([^&]*)(.*)$", "host":"([a-z0-9.]*?search\.aol\.com)$","testad":"var testad = function(ac,al){return(ac=='\"find\"'||ac=='find'&& al.indexOf('https')!=0 && al.indexOf('aol')<0 );}",'box':SearchBox_aol,'button':getButton_aol}
|
||||||
|
]
|
||||||
|
|
||||||
function roll(min,max){
|
function roll(min,max){
|
||||||
return Math.floor(Math.random()*(max+1))+min;
|
return Math.floor(Math.random()*(max+1))+min;
|
||||||
}
|
}
|
||||||
|
@ -60,17 +159,17 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
function pressEnter(elt) {
|
function pressEnter(elt) {
|
||||||
var timers = getTimingArray();
|
var timers = getTimingArray();
|
||||||
var evtDown = document.createEvent("KeyboardEvent");
|
var evtDown = document.createEvent("KeyboardEvent");
|
||||||
evtDown.initKeyEvent( "keydown", true, true, unsafeWindow, false, false, false, false, 13, 0 );
|
evtDown.initKeyboardEvent( "keydown", true, true, document.defaultView, false, false, false, false, 13, 0 );
|
||||||
window.setTimeout(function(){
|
window.setTimeout(function(){
|
||||||
elt.dispatchEvent(evtDown);
|
elt.dispatchEvent(evtDown);
|
||||||
},timers[0])
|
},timers[0])
|
||||||
var evtPress= document.createEvent("KeyboardEvent");
|
var evtPress= document.createEvent("KeyboardEvent");
|
||||||
evtPress.initKeyEvent( "keypress", true, true, unsafeWindow, false, false, false, false, 13, 0 );
|
evtPress.initKeyboardEvent( "keypress", true, true, document.defaultView, false, false, false, false, 13, 0 );
|
||||||
window.setTimeout(function(){
|
window.setTimeout(function(){
|
||||||
elt.dispatchEvent(evtPress);
|
elt.dispatchEvent(evtPress);
|
||||||
},timers[1])
|
},timers[1])
|
||||||
var evtUp = document.createEvent("KeyboardEvent");
|
var evtUp = document.createEvent("KeyboardEvent");
|
||||||
evtUp.initKeyEvent( "keyup", true, true, unsafeWindow, false, false, false, false, 13, 0 );
|
evtUp.initKeyboardEvent( "keyup", true, true, document.defaultView, false, false, false, false, 13, 0 );
|
||||||
window.setTimeout(function(){
|
window.setTimeout(function(){
|
||||||
elt.dispatchEvent(evtUp);
|
elt.dispatchEvent(evtUp);
|
||||||
},timers[2])
|
},timers[2])
|
||||||
|
@ -83,14 +182,14 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
function downKey(chara, searchBox) {
|
function downKey(chara, searchBox) {
|
||||||
var charCode = chara[chara.length-1].charCodeAt(0)
|
var charCode = chara[chara.length-1].charCodeAt(0)
|
||||||
var evtDown = document.createEvent("KeyboardEvent");
|
var evtDown = document.createEvent("KeyboardEvent");
|
||||||
evtDown.initKeyEvent( "keydown", true, true, unsafeWindow, false, false, false, false, 0, charCode );
|
evtDown.initKeyboardEvent( "keydown", true, true, document.defaultView, false, false, false, false, 0, charCode );
|
||||||
searchBox.dispatchEvent(evtDown)
|
searchBox.dispatchEvent(evtDown)
|
||||||
}
|
}
|
||||||
|
|
||||||
function pressKey(chara, searchBox) {
|
function pressKey(chara, searchBox) {
|
||||||
var charCode = chara[chara.length-1].charCodeAt(0)
|
var charCode = chara[chara.length-1].charCodeAt(0)
|
||||||
var evtPress = document.createEvent("KeyboardEvent");
|
var evtPress = document.createEvent("KeyboardEvent");
|
||||||
evtPress.initKeyEvent( "keypress", true, true, unsafeWindow, false, false, false, false, 0, charCode );
|
evtPress.initKeyboardEvent( "keypress", true, true, document.defaultView, false, false, false, false, 0, charCode );
|
||||||
searchBox.dispatchEvent(evtPress)
|
searchBox.dispatchEvent(evtPress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +202,7 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
function releaseKey(chara, searchBox) {
|
function releaseKey(chara, searchBox) {
|
||||||
var charCode = chara[chara.length-1].charCodeAt(0)
|
var charCode = chara[chara.length-1].charCodeAt(0)
|
||||||
var evtUp = document.createEvent("KeyboardEvent");
|
var evtUp = document.createEvent("KeyboardEvent");
|
||||||
evtUp.initKeyEvent( "keyup", true, true, unsafeWindow, false, false, false, false, 0, charCode );
|
evtUp.initKeyboardEvent( "keyup", true, true, document.defaultView, false, false, false, false, 0, charCode );
|
||||||
searchBox.dispatchEvent(evtUp)
|
searchBox.dispatchEvent(evtUp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +232,7 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
'query' : link,
|
'query' : link,
|
||||||
'id':tmn_id
|
'id':tmn_id
|
||||||
});
|
});
|
||||||
_log(logEntry)
|
log(logEntry)
|
||||||
try {
|
try {
|
||||||
clickElt(pageLinks[i])
|
clickElt(pageLinks[i])
|
||||||
debug("link clicked")
|
debug("link clicked")
|
||||||
|
@ -159,7 +258,7 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
|
|
||||||
|
|
||||||
function clickElt(elt) {
|
function clickElt(elt) {
|
||||||
var win = unsafeWindow;
|
var win = document.defaultView;
|
||||||
if ( !elt) return;
|
if ( !elt) return;
|
||||||
var timers = getTimingArray();
|
var timers = getTimingArray();
|
||||||
var evtDown = document.createEvent("MouseEvents");
|
var evtDown = document.createEvent("MouseEvents");
|
||||||
|
@ -309,7 +408,7 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
var response = {
|
var response = {
|
||||||
url: window.location.href
|
url: window.location.href
|
||||||
};
|
};
|
||||||
self.port.emit("TMNUpdateURL",response);
|
chrome.runtime.sendMessage(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
function queryToURL ( url, query) {
|
function queryToURL ( url, query) {
|
||||||
|
@ -340,7 +439,7 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
'query' : queryToSend,
|
'query' : queryToSend,
|
||||||
'id' : tmn_id
|
'id' : tmn_id
|
||||||
});
|
});
|
||||||
_log(logEntry)
|
log(logEntry)
|
||||||
updateStatus(queryToSend);
|
updateStatus(queryToSend);
|
||||||
if ( host =="" || !host.match(reg) ) {
|
if ( host =="" || !host.match(reg) ) {
|
||||||
try {
|
try {
|
||||||
|
@ -348,7 +447,7 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
return encodedUrl;
|
return encodedUrl;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
cout("Caught exception: "+ ex);
|
cout("Caught exception: "+ ex);
|
||||||
self.port.emit("TMNSetTabUrl", {
|
chrome.runtime.sendMessage({
|
||||||
"url": encodedUrl
|
"url": encodedUrl
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
|
@ -375,7 +474,7 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
return encodedUrl;
|
return encodedUrl;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
cout("Caught exception: "+ ex);
|
cout("Caught exception: "+ ex);
|
||||||
self.port.emit("TMNSetTabUrl", {
|
chrome.runtime.sendMessage( {
|
||||||
"url": encodedUrl
|
"url": encodedUrl
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
|
@ -385,31 +484,123 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateURLRegexp( eng, url) {
|
||||||
|
|
||||||
|
var pre = result[1];
|
||||||
|
var query = result[2];
|
||||||
|
var post = result[3];
|
||||||
|
var eng = result[4];
|
||||||
|
var asearch = pre+'|'+post;
|
||||||
|
if (!tmn_tab || worker.tab.index != tmn_tab.index ) {
|
||||||
|
debug("Worker find a match for url: "+ url + " on engine "+ eng +"!")
|
||||||
|
if (burstEnabled) enterBurst ( eng )
|
||||||
|
var engine = getEngineById(eng)
|
||||||
|
if ( engine && engine.urlmap != asearch ) {
|
||||||
|
engine.urlmap = asearch;
|
||||||
|
chrome.storage.set({engines :JSON.stringify(engines)}) ;
|
||||||
|
var logEntry = createLog('URLmap', eng, null,null,null, asearch)
|
||||||
|
log(logEntry);
|
||||||
|
debug("Updated url fr search engine "+ eng + ", new url is "+asearch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var regex = regexMap[eng];
|
||||||
|
cout(" regex: "+regex+" ->\n "+url);
|
||||||
|
result = url.match(regex);
|
||||||
|
cout("updateURLRegexp")
|
||||||
|
if (!result) {
|
||||||
|
cout("Can't find a regexp matching searched url")
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.length !=4 ){
|
||||||
|
if (result.length ==6 && eng == "google" ) {
|
||||||
|
result.splice(2,2);
|
||||||
|
result.push(eng);
|
||||||
|
}
|
||||||
|
cout("REGEX_ERROR: "+url);
|
||||||
|
for (var i in result)
|
||||||
|
cout(" **** "+i+")"+result[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- EXTRACT DATA FROM THE URL
|
||||||
|
var pre = result[1];
|
||||||
|
var post = result[3];
|
||||||
|
var asearch = pre+'|'+post;
|
||||||
|
|
||||||
|
|
||||||
|
if(eng=="google" && !url.match("^(https?:\/\/[a-z]+\.google\.(co\\.|com\\.)?[a-z^\/]{2,3}\/(search){1}\?.*?[&\?]{1}q=)([^&]*)(.*)$") || url.indexOf("sclient=psy-ab")>0 || url.indexOf("#")>0 )
|
||||||
|
return true;
|
||||||
|
// -- NEW SEARCH URL: ADD TO USER_MAP
|
||||||
|
if (asearch ){
|
||||||
|
setCurrentURLMap(eng, asearch);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function checkForSearchUrl(url) {
|
||||||
|
var result = null;
|
||||||
|
for (var i=0;i< engines.length; i++){
|
||||||
|
var eng = engines[i]
|
||||||
|
var regex = eng.regexmap;
|
||||||
|
debug(" regex: "+regex+" ->\n "+url);
|
||||||
|
result = url.match(regex);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
cout(regex + " MATCHED! on "+eng.id );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!result)return null;
|
||||||
|
|
||||||
|
if (result.length !=4 ){
|
||||||
|
if (result.length ==6 && eng.id == "google" ) {
|
||||||
|
result.splice(2,2);
|
||||||
|
result.push(eng.id);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
cout("REGEX_ERROR: "+url);
|
||||||
|
/* for (var i in result)
|
||||||
|
cout(" **** "+i+")"+result[i])*/
|
||||||
|
}
|
||||||
|
result.push(eng.id);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSafeHost( host ) {
|
||||||
|
for (var i=0;i< engines.length; i++){
|
||||||
|
var eng = engines[i]
|
||||||
|
var regex = eng.hostMap;
|
||||||
|
cout("regex :" +regex)
|
||||||
|
if (host.match(regex)) {
|
||||||
|
return eng;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function sendPageLoaded() {
|
function sendPageLoaded() {
|
||||||
var req = {
|
var req = {
|
||||||
tmn: "pageLoaded",
|
tmn: "pageLoaded",
|
||||||
html: unsafeWindow.document.body.innerHTML
|
html: document.defaultView.document.body.innerHTML
|
||||||
}
|
}
|
||||||
self.port.emit("TMNRequest",req);
|
chrome.runtime.sendMessage(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function _log(msg) {
|
function log(msg) {
|
||||||
var req = {
|
chrome.runtime.sendMessage({tmnLog:msg} )
|
||||||
tmnLog: msg
|
|
||||||
}
|
|
||||||
self.port.emit("TMNRequest",req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateStatus(msg) {
|
function updateStatus(msg) {
|
||||||
var req = {
|
var req = {
|
||||||
updateStatus: msg
|
updateStatus: msg
|
||||||
}
|
}
|
||||||
self.port.emit("TMNRequest",req);
|
chrome.runtime.sendMessage(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCurrentURLMap( eng, url ) {
|
function setCurrentURLMap( eng, url ) {
|
||||||
|
@ -417,10 +608,25 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
var req = {
|
var req = {
|
||||||
setURLMap: Eng_URL
|
setURLMap: Eng_URL
|
||||||
}
|
}
|
||||||
self.port.emit("TMNRequest",req);
|
chrome.runtime.sendMessage(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function notifyUserSearch(eng, url) {
|
||||||
|
// Here we update the regecxpfpor the queried engine
|
||||||
|
updateURLRegexp(eng, url);
|
||||||
|
chrome.runtime.sendMessage({
|
||||||
|
userSearch: eng
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTMNCurrentURL() {
|
||||||
|
chrome.runtime.sendMessage({
|
||||||
|
tmn: "currentURL"
|
||||||
|
},
|
||||||
|
function(response) {
|
||||||
|
setTMNCurrentURL(response.url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function setTMNCurrentURL(url) {
|
function setTMNCurrentURL(url) {
|
||||||
tmnCurrentURL= url;
|
tmnCurrentURL= url;
|
||||||
|
@ -428,7 +634,7 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
var message = {
|
var message = {
|
||||||
url: tmnCurrentURL
|
url: tmnCurrentURL
|
||||||
};
|
};
|
||||||
self.port.emit("TMNUpdateURL", message);
|
chrome.runtime.sendMessage( message);
|
||||||
sendPageLoaded();
|
sendPageLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,7 +648,7 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
handleRequest : function(request) {
|
handleRequest : function(request, sender, sendResponse) {
|
||||||
debug("Received: "+ request.tmnQuery + " on engine: "+ request.tmnEngine + " mode: " +request.tmnMode)
|
debug("Received: "+ request.tmnQuery + " on engine: "+ request.tmnEngine + " mode: " +request.tmnMode)
|
||||||
if (request.tmnQuery) {
|
if (request.tmnQuery) {
|
||||||
var tmn_query = request.tmnQuery;
|
var tmn_query = request.tmnQuery;
|
||||||
|
@ -460,11 +666,41 @@ TRACKMENOT.TMNInjected = function() {
|
||||||
return; // snub them.
|
return; // snub them.
|
||||||
} ,
|
} ,
|
||||||
|
|
||||||
|
|
||||||
|
checkIsActiveTab : function() {
|
||||||
|
chrome.runtime.sendMessage({
|
||||||
|
tmn: "isActiveTab"
|
||||||
|
}, function(response) {
|
||||||
|
if (response.isActive){
|
||||||
|
cout('Message sent from active tab');
|
||||||
|
TRACKMENOT.TMNInjected.hasLoaded();
|
||||||
|
} else {
|
||||||
|
var host = window.location.host;
|
||||||
|
var eng = isSafeHost(host);
|
||||||
|
if ( eng ) {
|
||||||
|
cout('User search detected!!');
|
||||||
|
notifyUserSearch(eng, window.location.href);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} )
|
||||||
|
} ,
|
||||||
|
|
||||||
|
hasLoaded :function(){
|
||||||
|
var host = window.location.host;
|
||||||
|
if (!isSafeHost(host) ) {
|
||||||
|
cout ("Host "+ host+ " is unsafe")
|
||||||
|
window.stop();
|
||||||
|
//history.go(-1);
|
||||||
|
}
|
||||||
|
// sendPageLoaded();
|
||||||
|
getTMNCurrentURL();
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
|
TRACKMENOT.TMNInjected.checkIsActiveTab();
|
||||||
|
chrome.runtime.onMessage.addListener( TRACKMENOT.TMNInjected.handleRequest );
|
||||||
|
|
||||||
|
/*self.port.on("TMNTabRequest", TRACKMENOT.TMNInjected.handleRequest );
|
||||||
|
self.port.on("TMNClickResult", TRACKMENOT.TMNInjected.clickResult );*/
|
||||||
self.port.on("TMNTabRequest", TRACKMENOT.TMNInjected.handleRequest );
|
|
||||||
self.port.on("TMNClickResult", TRACKMENOT.TMNInjected.clickResult );
|
|
||||||
|
|
453
trackmenot.js
453
trackmenot.js
|
@ -30,7 +30,7 @@ var _ = require("l10n").get;
|
||||||
var sp = require("sdk/simple-prefs");*/
|
var sp = require("sdk/simple-prefs");*/
|
||||||
|
|
||||||
|
|
||||||
|
var _ = chrome.i18n.getMessage;
|
||||||
|
|
||||||
|
|
||||||
if(!TRACKMENOT) var TRACKMENOT = {};
|
if(!TRACKMENOT) var TRACKMENOT = {};
|
||||||
|
@ -49,7 +49,7 @@ TRACKMENOT.TMNSearch = function() {
|
||||||
var engine = 'google';
|
var engine = 'google';
|
||||||
var TMNQueries = {};
|
var TMNQueries = {};
|
||||||
var branch = "extensions.trackmenot."
|
var branch = "extensions.trackmenot."
|
||||||
var feedList = _("tmn.rss.default-feeds");// 'http://www.techmeme.com/index.xml|http://rss.slashdot.org/Slashdot/slashdot|http://feeds.nytimes.com/nyt/rss/HomePage';
|
var feedList = 'http://www.techmeme.com/index.xml|http://rss.slashdot.org/Slashdot/slashdot|http://feeds.nytimes.com/nyt/rss/HomePage';
|
||||||
var tmnLogs = [];
|
var tmnLogs = [];
|
||||||
var disableLogs = false;
|
var disableLogs = false;
|
||||||
var saveLogs = true;
|
var saveLogs = true;
|
||||||
|
@ -74,7 +74,9 @@ TRACKMENOT.TMNSearch = function() {
|
||||||
var currentTMNURL = '';
|
var currentTMNURL = '';
|
||||||
var tmn_option_tab = null;
|
var tmn_option_tab = null;
|
||||||
var worker_tab, worker_opt;
|
var worker_tab, worker_opt;
|
||||||
var search_script = [data.url("jquery.js"),data.url("tmn_search.js")];
|
|
||||||
|
|
||||||
|
//var search_script = [data.url("jquery.js"),data.url("tmn_search.js")];
|
||||||
|
|
||||||
var skipex =new Array(
|
var skipex =new Array(
|
||||||
/calendar/i,/advanced/i,/click /i,/terms/i,/Groups/i,
|
/calendar/i,/advanced/i,/click /i,/terms/i,/Groups/i,
|
||||||
|
@ -129,7 +131,7 @@ TRACKMENOT.TMNSearch = function() {
|
||||||
|
|
||||||
var getButton_google =" var getButton = function( ) {var button = getElementsByAttrValue(document,'button', 'name', 'btnG' ); if ( !button ) button = getElementsByAttrValue(document,'button', 'name', 'btnK' );return button;}"
|
var getButton_google =" var getButton = function( ) {var button = getElementsByAttrValue(document,'button', 'name', 'btnG' ); if ( !button ) button = getElementsByAttrValue(document,'button', 'name', 'btnK' );return button;}"
|
||||||
var getButton_yahoo= " var getButton = function( ) {return getElementsByAttrValue(document,'input', 'class', 'sbb' ); } "
|
var getButton_yahoo= " var getButton = function( ) {return getElementsByAttrValue(document,'input', 'class', 'sbb' ); } "
|
||||||
var getButton_bing= " var getButton = function( ) {return document.getElementById('sb_form_go');} "
|
var getButton_bing= " var getButton = function( ) {return document.getElementById('sb_form_go');} "
|
||||||
var getButton_aol = " var getButton = function ( ) {return document.getElementById('csbbtn1'); }"
|
var getButton_aol = " var getButton = function ( ) {return document.getElementById('csbbtn1'); }"
|
||||||
var getButton_baidu = " var getButton = function ( ){ return getElementsByAttrValue(document,'input', 'value', '????' ); }"
|
var getButton_baidu = " var getButton = function ( ){ return getElementsByAttrValue(document,'input', 'value', '????' ); }"
|
||||||
|
|
||||||
|
@ -189,18 +191,13 @@ var engines = [
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var tmn_panel = panels.Panel({
|
|
||||||
width:115,
|
|
||||||
height:125,
|
|
||||||
contentURL: data.url("tmn_menu.html"),
|
|
||||||
contentScriptFile: [data.url("jquery.js"),data.url("menu-script.js")],
|
|
||||||
onShow: sendOptionParameters
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function updateEngineList() {
|
function updateEngineList() {
|
||||||
ss.storage.engines = JSON.stringify(engines) ;
|
chrome.storage.set({engines : JSON.stringify(engines)}) ;
|
||||||
sendMessageToOptionScript("TMNSendEngines",engines);
|
sendMessageToOptionScript("TMNSendEngines",engines);
|
||||||
sendOptionToTab();
|
sendOptionToTab();
|
||||||
}
|
}
|
||||||
|
@ -208,7 +205,7 @@ var engines = [
|
||||||
|
|
||||||
|
|
||||||
function sendMessageToOptionScript(title, message) {
|
function sendMessageToOptionScript(title, message) {
|
||||||
worker_opt.port.emit(title,message)
|
chrome.runtime.sendMessage({"options":title,"param":message})
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMessageFromOptionScript(title, handler) {
|
function handleMessageFromOptionScript(title, handler) {
|
||||||
|
@ -217,7 +214,7 @@ var engines = [
|
||||||
|
|
||||||
|
|
||||||
function sendMessageToPanelScript(title, message) {
|
function sendMessageToPanelScript(title, message) {
|
||||||
tmn_panel.port.emit(title,message)
|
hrome.runtime.sendMessage(title,message)
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMessageFromPanelScript(title, handler) {
|
function handleMessageFromPanelScript(title, handler) {
|
||||||
|
@ -232,9 +229,9 @@ var engines = [
|
||||||
|
|
||||||
function sendQueriesToOption() {
|
function sendQueriesToOption() {
|
||||||
var allqueries = "";
|
var allqueries = "";
|
||||||
for each( var arr in TMNQueries) {
|
for ( var arr of TMNQueries) {
|
||||||
if (arr && arr.length) {
|
if (arr && arr.length) {
|
||||||
for each (var elt in arr)
|
for (var elt of arr)
|
||||||
if ( elt&& elt.words && elt.words.length) allqueries+= elt.words.join(',');
|
if ( elt&& elt.words && elt.words.length) allqueries+= elt.words.join(',');
|
||||||
else allqueries+= elt+",";
|
else allqueries+= elt+",";
|
||||||
}
|
}
|
||||||
|
@ -243,14 +240,7 @@ var engines = [
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var widget = widgets.Widget({
|
|
||||||
id: "tmn_widget",
|
|
||||||
label: "TMN",
|
|
||||||
width: 150,
|
|
||||||
contentURL: data.url("tmn_widget.html"),
|
|
||||||
contentScriptFile: [data.url("jquery.js"),data.url("widget-script.js")],
|
|
||||||
panel: tmn_panel
|
|
||||||
});
|
|
||||||
|
|
||||||
function sendOptionParameters() {
|
function sendOptionParameters() {
|
||||||
debug("Sending perameters")
|
debug("Sending perameters")
|
||||||
|
@ -266,24 +256,19 @@ var engines = [
|
||||||
onReady: runScript
|
onReady: runScript
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sp.on("tmnOptionPref", function() {
|
|
||||||
openOptionWindow()
|
|
||||||
});
|
|
||||||
|
|
||||||
function runScript(tab) {
|
function runScript(tab) {
|
||||||
worker_opt = tab.attach({
|
worker_opt = tab.attach({
|
||||||
contentScriptFile: [data.url("jquery.js"),data.url("option-script.js")]
|
contentScriptFile: [data.url("jquery.js"),data.url("option-script.js")]
|
||||||
});
|
});
|
||||||
sendOptionToTab();
|
sendOptionToTab();
|
||||||
handleMessageFromOptionScript("TMNSaveOptions",saveOptionFromTab)
|
/*handleMessageFromOptionScript("TMNSaveOptions",saveOptionFromTab)
|
||||||
handleMessageFromOptionScript("TMNOptionsShowLog", sendLogToOption)
|
handleMessageFromOptionScript("TMNOptionsShowLog", sendLogToOption)
|
||||||
handleMessageFromOptionScript("TMNOptionsShowQueries", sendQueriesToOption)
|
handleMessageFromOptionScript("TMNOptionsShowQueries", sendQueriesToOption)
|
||||||
handleMessageFromOptionScript("TMNOptionsClearLog", clearLog)
|
handleMessageFromOptionScript("TMNOptionsClearLog", clearLog)
|
||||||
handleMessageFromOptionScript("TMNValideFeeds", validateFeeds)
|
handleMessageFromOptionScript("TMNValideFeeds", validateFeeds)
|
||||||
handleMessageFromOptionScript("TMNAddEngine",addEngine)
|
handleMessageFromOptionScript("TMNAddEngine",addEngine)
|
||||||
handleMessageFromOptionScript("TMNDelEngine",delEngine)
|
handleMessageFromOptionScript("TMNDelEngine",delEngine)*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -340,13 +325,20 @@ var engines = [
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function iniTab(tab) {
|
function iniTab(tab) {
|
||||||
tmn_tab_id = tab.id;
|
tmn_tab_id = tab.id;
|
||||||
tmn_win_id = tab.windowId;
|
tmn_win_id = tab.windowId;
|
||||||
localStorage["tmn_tab_id"] = tmn_tab_id;
|
chrome.storage.local.set({"tmn_tab_id": tmn_tab_id});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTMNTab() {
|
||||||
|
debug("Trying to access to the tab: " + tmn_tab_id);
|
||||||
|
return tmn_tab_id;
|
||||||
|
}
|
||||||
|
|
||||||
function deleteTab() {
|
function deleteTab() {
|
||||||
if (!useTabe ) return;
|
if (!useTabe ) return;
|
||||||
chrome.tabs.remove(tmn_tab_id);
|
chrome.tabs.remove(tmn_tab_id);
|
||||||
|
@ -355,7 +347,7 @@ var engines = [
|
||||||
|
|
||||||
function createTab() {
|
function createTab() {
|
||||||
if (!useTab || tmn_tab_id != -1) return;
|
if (!useTab || tmn_tab_id != -1) return;
|
||||||
if(debug) _cout('Creating tab for TrackMeNot')
|
if(debug) cout('Creating tab for TrackMeNot')
|
||||||
try {
|
try {
|
||||||
chrome.tabs.create({
|
chrome.tabs.create({
|
||||||
'selected': false,
|
'selected': false,
|
||||||
|
@ -485,43 +477,37 @@ var engines = [
|
||||||
|
|
||||||
|
|
||||||
function monitorBurst() {
|
function monitorBurst() {
|
||||||
pageMod.PageMod({
|
chrome.webNavigation.onCommitted.addListener(function(e) {
|
||||||
//include: /.[a-z]+\.(google|yahoo|bing|baidu)\.(co\\.|com\\.)?[a-z]{2,3}.*/,
|
var url = e.url;
|
||||||
include: ["*"],
|
var tab_id = e.tabId;
|
||||||
contentScriptFile: data.url("stoping-script.js"),
|
var result = checkForSearchUrl(url);
|
||||||
contentScriptWhen : stop_when,
|
if (!result) {
|
||||||
onAttach: function onAttach(worker) {
|
if ( tab_id == tmn_tab_id) {
|
||||||
if (!worker.tab) return
|
|
||||||
var url = worker.tab.url;
|
|
||||||
var result = checkForSearchUrl(url);
|
|
||||||
if (!result) {
|
|
||||||
if ( tmn_tab && worker.tab.index == tmn_tab.index) {
|
|
||||||
debug("TMN tab tryign to visit: "+ url)
|
debug("TMN tab tryign to visit: "+ url)
|
||||||
worker.port.emit("TMNStopLoading");
|
//worker.port.emit("TMNStopLoading");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// -- EXTRACT DATA FROM THE URL
|
// -- EXTRACT DATA FROM THE URL
|
||||||
var pre = result[1];
|
var pre = result[1];
|
||||||
var query = result[2];
|
var query = result[2];
|
||||||
var post = result[3];
|
var post = result[3];
|
||||||
var eng = result[4];
|
var eng = result[4];
|
||||||
var asearch = pre+'|'+post;
|
var asearch = pre+'|'+post;
|
||||||
if (!tmn_tab || worker.tab.index != tmn_tab.index ) {
|
if (tmn_tab_id == -1 || tab_id != tmn_tab_id ) {
|
||||||
debug("Worker find a match for url: "+ url + " on engine "+ eng +"!")
|
debug("Worker find a match for url: "+ url + " on engine "+ eng +"!")
|
||||||
if (burstEnabled) enterBurst ( eng )
|
if (burstEnabled) enterBurst ( eng )
|
||||||
var engine = getEngineById(eng)
|
var engine = getEngineById(eng)
|
||||||
if ( engine && engine.urlmap != asearch ) {
|
if ( engine && engine.urlmap != asearch ) {
|
||||||
engine.urlmap = asearch;
|
engine.urlmap = asearch;
|
||||||
ss.storage.engines = JSON.stringify(engines) ;
|
chrome.storage.set({engines :JSON.stringify(engines)}) ;
|
||||||
var logEntry = createLog('URLmap', eng, null,null,null, asearch)
|
var logEntry = createLog('URLmap', eng, null,null,null, asearch)
|
||||||
log(logEntry);
|
log(logEntry);
|
||||||
debug("Updated url fr search engine "+ eng + ", new url is "+asearch);
|
debug("Updated url fr search engine "+ eng + ", new url is "+asearch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -674,7 +660,7 @@ var engines = [
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
queryList.push(term);
|
queryList.push(term);
|
||||||
//gtmn._cout("adding("+gtmn._queries.length+"): "+term);
|
//gtmn.cout("adding("+gtmn._queries.length+"): "+term);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -750,11 +736,11 @@ var engines = [
|
||||||
onComplete: function (response) {
|
onComplete: function (response) {
|
||||||
if (response.status ==200 ) {
|
if (response.status ==200 ) {
|
||||||
var keywords = response.json.keywords;
|
var keywords = response.json.keywords;
|
||||||
for each(var cat in keywords) {
|
for (var cat of keywords) {
|
||||||
TMNQueries.dhs[i] = {};
|
TMNQueries.dhs[i] = {};
|
||||||
TMNQueries.dhs[i].category_name = cat.category_name;
|
TMNQueries.dhs[i].category_name = cat.category_name;
|
||||||
TMNQueries.dhs[i].words = [];
|
TMNQueries.dhs[i].words = [];
|
||||||
for each (var word in cat.category_words)
|
for (var word of cat.category_words)
|
||||||
TMNQueries.dhs[i].words.push(word.name)
|
TMNQueries.dhs[i].words.push(word.name)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -768,21 +754,41 @@ var engines = [
|
||||||
req.get();
|
req.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function doRssFetch(feedUrl){
|
function doRssFetch(feedUrl){
|
||||||
if (!feedUrl) return;
|
var req;
|
||||||
|
try {
|
||||||
var req = Request({
|
req = new XMLHttpRequest();
|
||||||
url: feedUrl,
|
}
|
||||||
onComplete: function (response) {
|
catch (e) {
|
||||||
if (response.status == 200) {
|
try {
|
||||||
cout(response.text);
|
req = new ActiveXObject('Msxml2.XMLHTTP');
|
||||||
var parser = Cc["@mozilla.org/xmlextras/domparser;1"].createInstance(Ci.nsIDOMParser);
|
}
|
||||||
var doc = parser.parseFromString(response.text,'text/xml');
|
catch (e) {
|
||||||
addRssTitles(doc, feedUrl);
|
try {
|
||||||
}
|
req = new ActiveXObject('Microsoft.XMLHTTP');
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log('XMLHttpRequest not supported');
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
req.get();
|
try {
|
||||||
|
req.open('GET', feedUrl, true);
|
||||||
|
req.onreadystatechange = function(aEvt){
|
||||||
|
if (req.readyState == 4) {
|
||||||
|
if (req.status == 200)
|
||||||
|
var adds = addRssTitles(req.responseXML, feedUrl);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
req.send(null);
|
||||||
|
} catch (ex) {
|
||||||
|
cout("[WARN] doRssFetch("+feedUrl+")\n"
|
||||||
|
+" "+ex.message+" | Using defaults...");
|
||||||
|
return ; // no adds here...
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSubQuery(queryWords) {
|
function getSubQuery(queryWords) {
|
||||||
|
@ -819,27 +825,36 @@ var engines = [
|
||||||
return term;
|
return term;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateIcon (url) {
|
|
||||||
var Uri = new URL(url);
|
|
||||||
var iconURL = "http://" + Uri.host +"/favicon.ico";
|
function updateOnErr() {
|
||||||
widget.port.emit("UpdateIcon", iconURL)
|
var details = {
|
||||||
}
|
'text':'Error'
|
||||||
|
};
|
||||||
function updateOnErr() {
|
var tooltip = {
|
||||||
widget.label = 'Error'
|
'title': 'TMN Error'
|
||||||
widget.tooltip = 'TMN Error'
|
};
|
||||||
widget.port.emit("UpdateText", 'TMN Error')
|
chrome.browserAction.setBadgeBackgroundColor({
|
||||||
|
'color':[255,0,0,255]
|
||||||
|
})
|
||||||
|
chrome.browserAction.setBadgeText(details);
|
||||||
|
chrome.browserAction.setTitle(tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateOnSend ( queryToSend ) {
|
function updateOnSend ( queryToSend ) {
|
||||||
tmn_query = queryToSend;
|
tmn_query = queryToSend;
|
||||||
widget.label = queryToSend
|
var details = {
|
||||||
widget.tooltip = engine+" '"+queryToSend+"'"
|
'text':queryToSend
|
||||||
if (!burstEnabled || burstCount == 0)
|
};
|
||||||
widget.port.emit("UpdateText", " TMN: '"+queryToSend+"'")
|
var tooltip = {
|
||||||
else
|
'title': engine+': '+queryToSend
|
||||||
widget.port.emit("UpdateText", " TMN (" + burstCount +"): '"+queryToSend+"'")
|
};
|
||||||
}
|
chrome.browserAction.setBadgeBackgroundColor({
|
||||||
|
'color':[113,113,198,255]
|
||||||
|
})
|
||||||
|
chrome.browserAction.setBadgeText(details);
|
||||||
|
chrome.browserAction.setTitle(tooltip);
|
||||||
|
}
|
||||||
|
|
||||||
function createLog(type,engine,mode,query,id,asearch) {
|
function createLog(type,engine,mode,query,id,asearch) {
|
||||||
var logEntry = { 'type' : type, "engine" : engine };
|
var logEntry = { 'type' : type, "engine" : engine };
|
||||||
|
@ -894,9 +909,9 @@ var engines = [
|
||||||
}
|
}
|
||||||
if (Math.random() < 0.9) queryToSend = queryToSend.toLowerCase();
|
if (Math.random() < 0.9) queryToSend = queryToSend.toLowerCase();
|
||||||
if (queryToSend[0]==' ' ) queryToSend = queryToSend.substr(1); //remove the first space ;
|
if (queryToSend[0]==' ' ) queryToSend = queryToSend.substr(1); //remove the first space ;
|
||||||
updateIcon(url)
|
|
||||||
if ( useTab ) {
|
if ( useTab ) {
|
||||||
if ( getTMNTab() == null ) createTab();
|
if ( getTMNTab() == -1 ) createTab();
|
||||||
var TMNReq = {
|
var TMNReq = {
|
||||||
tmnQuery: queryToSend,
|
tmnQuery: queryToSend,
|
||||||
tmnEngine: getEngineById(engine),
|
tmnEngine: getEngineById(engine),
|
||||||
|
@ -905,43 +920,42 @@ var engines = [
|
||||||
tmnMode: tmn_mode,
|
tmnMode: tmn_mode,
|
||||||
tmnID : tmn_id++
|
tmnID : tmn_id++
|
||||||
}
|
}
|
||||||
debug('Sending messaget to the tab ');
|
|
||||||
try {
|
try {
|
||||||
worker_tab.port.emit("TMNTabRequest", TMNReq) ;
|
chrome.tabs.sendMessage( tmn_tab_id, TMNReq);
|
||||||
debug('Message sent to the tab');
|
debug('Message sent to the tab');
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
cout("Error : "+ex)
|
cout("Error : "+ex)
|
||||||
cout("Creating a new tab")
|
cout("Creating a new tab")
|
||||||
deleteTab();
|
deleteTab();
|
||||||
timer.setTimeout(function() {worker_tab.port.emit("TMNTabRequest", TMNReq)},1000) ;
|
window.setTimeout(function() {chrome.tabs.sendMessage( tmn_tab_id, TMNReq)},1000) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
var queryURL = queryToURL(url ,queryToSend);
|
var queryURL = queryToURL(url ,queryToSend);
|
||||||
debug("The encoded URL is " + queryURL)
|
cout("The encoded URL is " + queryURL)
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
updateOnSend(queryToSend)
|
xhr.open("GET", queryURL, true);
|
||||||
var req = Request({
|
xhr.onreadystatechange = function() {
|
||||||
url: queryURL,
|
if (xhr.readyState == 4) {
|
||||||
onComplete: function (response) {
|
clearTimeout(tmn_errTimeout);
|
||||||
timer.clearTimeout(tmn_errTimeout);
|
if (xhr.status >= 200 && xhr.status<400 ) {
|
||||||
if (response.status >= 200 && response.status<400) {
|
|
||||||
timer.clearTimeout(tmn_errTimeout);
|
|
||||||
reschedule();
|
reschedule();
|
||||||
var logEntry = createLog('query', engine, tmn_mode, queryToSend, tmn_id++);
|
|
||||||
extractQueries(response.text);
|
|
||||||
} else {
|
} else {
|
||||||
var logEntry = createLog('error', engine, tmn_mode, queryToSend, tmn_id);
|
|
||||||
rescheduleOnError();
|
rescheduleOnError();
|
||||||
|
var logEntry = JSON.stringify({
|
||||||
|
'type' : 'query',
|
||||||
|
"engine" : engine,
|
||||||
|
'mode' : tmn_mode,
|
||||||
|
'query' : queryToSend,
|
||||||
|
'id' : tmn_id++
|
||||||
|
});
|
||||||
|
log(logEntry);
|
||||||
}
|
}
|
||||||
log(logEntry);
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
xhr.send();
|
||||||
req.get();
|
|
||||||
debug("Querry sent to :"+queryURL)
|
|
||||||
currentTMNURL = queryURL;
|
currentTMNURL = queryURL;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1012,8 +1026,8 @@ var engines = [
|
||||||
if (isBursting()) engine = burstEngine;
|
if (isBursting()) engine = burstEngine;
|
||||||
else engine = chooseEngine(searchEngines.split(','));
|
else engine = chooseEngine(searchEngines.split(','));
|
||||||
debug('NextSearchScheduled on: '+engine);
|
debug('NextSearchScheduled on: '+engine);
|
||||||
tmn_errTimeout = timer.setTimeout(rescheduleOnError, delay*3);
|
tmn_errTimeout = window.setTimeout(rescheduleOnError, delay*3);
|
||||||
tmn_searchTimer = timer.setTimeout(doSearch, delay);
|
tmn_searchTimer = window.setTimeout(doSearch, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
function enterBurst ( burst_engine ) {
|
function enterBurst ( burst_engine ) {
|
||||||
|
@ -1030,7 +1044,7 @@ var engines = [
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteTabWithUrl(tabURL) {
|
function deleteTabWithUrl(tabURL) {
|
||||||
for each (var tab in tabs)
|
for (var tab of tabs)
|
||||||
if (tab.url == tabURL) {
|
if (tab.url == tabURL) {
|
||||||
tab.close();
|
tab.close();
|
||||||
return;
|
return;
|
||||||
|
@ -1041,9 +1055,9 @@ var engines = [
|
||||||
function saveOptions() {
|
function saveOptions() {
|
||||||
//ss.storage.kw_black_list = kwBlackList.join(",");
|
//ss.storage.kw_black_list = kwBlackList.join(",");
|
||||||
var options = getOptions();
|
var options = getOptions();
|
||||||
ss.storage.options_tmn = JSON.stringify(options);
|
localStorage["options_tmn"] = JSON.stringify(options);
|
||||||
ss.storage.tmn_id = tmn_id;
|
localStorage["tmn_id"] = tmn_id;
|
||||||
ss.storage.gen_queries = JSON.stringify(TMNQueries);
|
localStorage["gen_queries"] = JSON.stringify(TMNQueries);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1081,14 +1095,14 @@ var engines = [
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreOptions () {
|
function restoreOptions () {
|
||||||
if (!ss.storage.options_tmn) {
|
if (!localStorage["options_tmn"]) {
|
||||||
initOptions();
|
initOptions();
|
||||||
cout("Init: "+ enabled)
|
cout("Init: "+ enabled)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var options = JSON.parse(ss.storage.options_tmn);
|
var options = JSON.parse(localStorage["options_tmn"]);
|
||||||
enabled = options.enabled;
|
enabled = options.enabled;
|
||||||
debug("Restore: "+ enabled)
|
debug("Restore: "+ enabled)
|
||||||
useBlackList = options.use_black_list;
|
useBlackList = options.use_black_list;
|
||||||
|
@ -1099,12 +1113,11 @@ var engines = [
|
||||||
disableLogs = options.disableLogs;
|
disableLogs = options.disableLogs;
|
||||||
saveLogs = options.saveLogs;
|
saveLogs = options.saveLogs;
|
||||||
useTab = options.useTab;
|
useTab = options.useTab;
|
||||||
if (ss.storage.gen_queries) TMNQueries = JSON.parse(ss.storage.gen_queries);
|
TMNQueries = JSON.parse(localStorage["gen_queries"]);
|
||||||
feedList = options.feedList;
|
feedList = options.feedList;
|
||||||
if (ss.storage.tmn_id) tmn_id = ss.storage.tmn_id;
|
tmn_id = options.tmn_id;
|
||||||
if (ss.storage.logs_tmn) tmnLogs = JSON.parse( ss.storage.logs_tmn );
|
tmnLogs = JSON.parse( localStorage["logs_tmn"] );
|
||||||
if (ss.storage.engines) engines = JSON.parse( ss.storage.engines);
|
engines = JSON.parse( localStorage["engines"]);
|
||||||
if (ss.storage.last_tmn_url && ss.storage.last_tmn_url != '' ) deleteTabWithUrl( ss.storage.last_tmn_url);
|
|
||||||
if (options.kw_black_list && opions.kw_black_list.length > 0) kwBlackList = options.kw_black_list.split(",");
|
if (options.kw_black_list && opions.kw_black_list.length > 0) kwBlackList = options.kw_black_list.split(",");
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
cout('No option recorded: '+ex)
|
cout('No option recorded: '+ex)
|
||||||
|
@ -1117,6 +1130,30 @@ var engines = [
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function restartTMN() {
|
||||||
|
createTab();
|
||||||
|
enabled = true;
|
||||||
|
chrome.browserAction.setBadgeText({'text':'On'});
|
||||||
|
chrome.browserAction.setTitle({'title':'On'});
|
||||||
|
scheduleNextSearch(4000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function stopTMN() {
|
||||||
|
enabled = false;
|
||||||
|
if (useTab)
|
||||||
|
deleteTab();
|
||||||
|
|
||||||
|
chrome.browserAction.setBadgeBackgroundColor({
|
||||||
|
'color':[255,0,0,255]
|
||||||
|
})
|
||||||
|
chrome.browserAction.setBadgeText({'text':'Off'});
|
||||||
|
chrome.browserAction.setTitle({'title':'Off'});
|
||||||
|
window.clearTimeout(tmn_searchTimer);
|
||||||
|
window.clearTimeout(tmn_errTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
function preserveTMNTab() {
|
function preserveTMNTab() {
|
||||||
if ( useTab && enabled) {
|
if ( useTab && enabled) {
|
||||||
|
@ -1131,36 +1168,7 @@ var engines = [
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
function _readPrefs() {
|
|
||||||
options.timeout = prefs.get(branch+"timeout");
|
|
||||||
options.enabled = prefs.get(branch+"enabled");
|
|
||||||
options.disableLogs = prefs.get(branch+"logDisabled");
|
|
||||||
options.saveLogs = prefs.get(branch+"logPreserved");
|
|
||||||
options.burstMode = prefs.get(branch+"burstEnabled");
|
|
||||||
options.searchEngines = prefs.get(branch+"searchEngines");
|
|
||||||
|
|
||||||
var rssFeeds = prefs.get(branch+"rssFeedList");
|
|
||||||
if (rssFeeds && rssFeeds.length>0)
|
|
||||||
options.feedList = rssFeeds;
|
|
||||||
}
|
|
||||||
|
|
||||||
function addTMNContentHandler() {
|
|
||||||
var i = 0;
|
|
||||||
var prefBranch = null;
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
if( prefs.get("browser.contentHandlers.types." + i + ".title") == "TrackMeNot")
|
|
||||||
return
|
|
||||||
i++;
|
|
||||||
} catch (e) {
|
|
||||||
if (prefs) {
|
|
||||||
prefs.set("browser.contentHandlers.types."+i+".title", "TrackMeNot");
|
|
||||||
prefs.set("browser.contentHandlers.types."+i+".type", "application/vnd.mozilla.maybe.feed");
|
|
||||||
prefs.set("browser.contentHandlers.types."+i+".uri", "chrome://trackmenot/content/tmn_feed.html?tmn_feed=%s");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function log (entry) {
|
function log (entry) {
|
||||||
if (disableLogs) return;
|
if (disableLogs) return;
|
||||||
|
@ -1179,7 +1187,7 @@ var engines = [
|
||||||
cout("[ERROR] "+ ex +" / "+ ex.message + "\nlogging msg");
|
cout("[ERROR] "+ ex +" / "+ ex.message + "\nlogging msg");
|
||||||
}
|
}
|
||||||
tmnLogs.unshift(entry);
|
tmnLogs.unshift(entry);
|
||||||
ss.storage.logs_tmn = JSON.stringify(tmnLogs);
|
chrome.storage.local.set({"logs_tmn":JSON.stringify(tmnLogs)});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendClickEvent() {
|
function sendClickEvent() {
|
||||||
|
@ -1190,11 +1198,13 @@ var engines = [
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleRequest(request, sender, sendResponse) {
|
||||||
if (request.tmnLog) {
|
|
||||||
_cout("Background logging : " + request.tmnLog);
|
|
||||||
|
if (request.tmnLog) {
|
||||||
|
cout("Background logging : " + request.tmnLog);
|
||||||
var logtext = JSON.parse(request.tmnLog);
|
var logtext = JSON.parse(request.tmnLog);
|
||||||
TRACKMENOT.TMNSearch._log(logtext);
|
log(logtext);
|
||||||
sendResponse({});
|
sendResponse({});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1217,7 +1227,7 @@ var engines = [
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( request.setURLMap) {
|
if ( request.setURLMap) {
|
||||||
_cout("Background handling : " + request.setURLMap);
|
cout("Background handling : " + request.setURLMap);
|
||||||
var vars = request.setURLMap.split('--');
|
var vars = request.setURLMap.split('--');
|
||||||
var eng = vars[0];
|
var eng = vars[0];
|
||||||
var asearch = vars[1];
|
var asearch = vars[1];
|
||||||
|
@ -1228,11 +1238,11 @@ var engines = [
|
||||||
"engine" : eng,
|
"engine" : eng,
|
||||||
'newUrl' : asearch
|
'newUrl' : asearch
|
||||||
};
|
};
|
||||||
TRACKMENOT.TMNSearch._log(logEntry);
|
TRACKMENOT.TMNSearch.log(logEntry);
|
||||||
sendResponse({});
|
sendResponse({});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//_cout("Background page received message: " + request.tmn);
|
//cout("Background page received message: " + request.tmn);
|
||||||
switch (request.tmn) {
|
switch (request.tmn) {
|
||||||
case "currentURL":
|
case "currentURL":
|
||||||
sendResponse({
|
sendResponse({
|
||||||
|
@ -1256,30 +1266,54 @@ var engines = [
|
||||||
break;
|
break;
|
||||||
case "isActiveTab":
|
case "isActiveTab":
|
||||||
var active = (!sender.tab || sender.tab.id==tmn_tab_id);
|
var active = (!sender.tab || sender.tab.id==tmn_tab_id);
|
||||||
_cout("active: "+ active)
|
cout("active: "+ active)
|
||||||
sendResponse({
|
sendResponse({
|
||||||
isActive: active
|
isActive: active
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "TMNSaveOptions":
|
||||||
|
saveOptionFromTab(request.option);
|
||||||
|
sendResponse({});
|
||||||
|
break;
|
||||||
|
case "TMNResetOptions":
|
||||||
|
resetOptions();
|
||||||
|
sendResponse({});
|
||||||
|
break;
|
||||||
|
case "TMNOptionsShowLog":
|
||||||
|
sendLogToOption();
|
||||||
|
sendResponse({});
|
||||||
|
break;
|
||||||
|
case "TMNOptionsShowQueries":
|
||||||
|
sendQueriesToOption();
|
||||||
|
sendResponse({});
|
||||||
|
break;
|
||||||
|
case "TMNOptionsClearLog":
|
||||||
|
clearLog();
|
||||||
|
sendResponse({});
|
||||||
|
break;
|
||||||
|
case "TMNValideFeeds":
|
||||||
|
validateFeeds(request.param);
|
||||||
|
sendResponse({});
|
||||||
|
break;
|
||||||
|
case "TMNAddEngine":
|
||||||
|
alert(request.engine)
|
||||||
|
addEngine(request.engine);
|
||||||
|
sendResponse({});
|
||||||
|
break;
|
||||||
|
case "TMNDelEngine":
|
||||||
|
delEngine(request.engine);
|
||||||
|
sendResponse({});
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
sendResponse({}); // snub them.
|
sendResponse({}); // snub them.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleRequest(request, sender, sendResponse) {
|
|
||||||
if (request.tmnLog) {
|
|
||||||
debug("Background logging : " + request.tmnLog);
|
|
||||||
var logtext = JSON.parse(request.tmnLog);
|
|
||||||
log(logtext);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (request.updateStatus) {
|
|
||||||
updateOnSend(request.updateStatus);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
debug( "Recieved message: "+ request.tmn)
|
/* debug( "Recieved message: "+ request.tmn)
|
||||||
switch (request.tmn) {
|
switch (request.tmn) {
|
||||||
case "pageLoaded": //Remove timer and then reschedule;
|
case "pageLoaded": //Remove timer and then reschedule;
|
||||||
prev_engine = engine;
|
prev_engine = engine;
|
||||||
|
@ -1293,7 +1327,7 @@ var engines = [
|
||||||
extractQueries(html);
|
extractQueries(html);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1301,12 +1335,12 @@ return {
|
||||||
|
|
||||||
_handleRequest : function(request, sender, sendResponse) {
|
_handleRequest : function(request, sender, sendResponse) {
|
||||||
handleRequest(request, sender, sendResponse);
|
handleRequest(request, sender, sendResponse);
|
||||||
}
|
},
|
||||||
|
|
||||||
|
|
||||||
startTMN : function () {
|
startTMN : function () {
|
||||||
restoreOptions();
|
restoreOptions();
|
||||||
|
//chrome.browserAction.setPopup("tmn_menu.html");
|
||||||
typeoffeeds.push('zeitgeist');
|
typeoffeeds.push('zeitgeist');
|
||||||
TMNQueries.zeitgeist = zeitgeist;
|
TMNQueries.zeitgeist = zeitgeist;
|
||||||
|
|
||||||
|
@ -1334,7 +1368,7 @@ return {
|
||||||
monitorBurst();
|
monitorBurst();
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
|
|
||||||
chrome.browserAction.setBadgeText({
|
chrome.browserAction.setBadgeText({
|
||||||
'text':'ON'
|
'text':'ON'
|
||||||
});
|
});
|
||||||
|
@ -1342,8 +1376,7 @@ return {
|
||||||
'title': 'TMN is ON'
|
'title': 'TMN is ON'
|
||||||
});
|
});
|
||||||
|
|
||||||
if ( !useTab && !tmn_frame ) createFrame();
|
createTab();
|
||||||
else createTab();
|
|
||||||
scheduleNextSearch(4000);
|
scheduleNextSearch(4000);
|
||||||
} else {
|
} else {
|
||||||
chrome.browserAction.setBadgeText({
|
chrome.browserAction.setBadgeText({
|
||||||
|
@ -1353,8 +1386,7 @@ return {
|
||||||
'title': 'TMN is OFF'
|
'title': 'TMN is OFF'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Firefox Block
|
/* Firefox Block
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
|
@ -1369,13 +1401,44 @@ return {
|
||||||
widget.port.emit("UpdateText", 'TMN: Off')
|
widget.port.emit("UpdateText", 'TMN: Off')
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
windows.on('close',function() {
|
chrome.windows.onRemoved.addListener(function() {
|
||||||
deleteTab();
|
deleteTab();
|
||||||
if (!saveLogs)
|
if (!saveLogs)
|
||||||
ss.storage.logs_tmn = "";
|
chrome.storage.local.set({"logs_tmn" : ""});
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_getOptions:function() {
|
||||||
|
return getOptions();
|
||||||
|
},
|
||||||
|
|
||||||
|
_restartTMN:function() {
|
||||||
|
return restartTMN();
|
||||||
|
},
|
||||||
|
|
||||||
|
_stopTMN:function() {
|
||||||
|
return stopTMN();
|
||||||
|
},
|
||||||
|
|
||||||
|
_getEngine:function() {
|
||||||
|
return engine;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getTargetEngines:function() {
|
||||||
|
return engines;
|
||||||
|
},
|
||||||
|
|
||||||
|
_getQuery:function() {
|
||||||
|
return this.queryToSend;
|
||||||
|
},
|
||||||
|
|
||||||
|
_saveOptions: function() {
|
||||||
|
return saveOptions();
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1386,8 +1449,10 @@ return {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
chrome.extension.onRequest.addListener(TRACKMENOT.TMNSearch._handleRequest);
|
chrome.runtime.onMessage.addListener(TRACKMENOT.TMNSearch._handleRequest);
|
||||||
|
|
||||||
//chrome.tabs.onSelectionChanged.addListener(TRACKMENOT.TMNSearch._hideTMNTab);
|
//chrome.tabs.onSelectionChanged.addListener(TRACKMENOT.TMNSearch._hideTMNTab);
|
||||||
chrome.tabs.onRemoved.addListener(TRACKMENOT.TMNSearch._preserveTMNTab);
|
chrome.tabs.onRemoved.addListener(TRACKMENOT.TMNSearch._preserveTMNTab);
|
||||||
chrome.windows.onRemoved.addListener(TRACKMENOT.TMNSearch._deleteTabWhenClosing);
|
chrome.windows.onRemoved.addListener(TRACKMENOT.TMNSearch._deleteTabWhenClosing);
|
||||||
|
|
||||||
|
TRACKMENOT.TMNSearch.startTMN();
|
||||||
|
|
Loading…
Reference in a new issue