1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/**
* GNU LibreJS - A browser add-on to block nonfree nontrivial JavaScript.
* *
* Copyright (C) 2011, 2012, 2013, 2014 Loic J. Duros
* Copyright (C) 2014, 2015 Nik Nyby
*
* This file is part of GNU LibreJS.
*
* GNU LibreJS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GNU LibreJS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU LibreJS. If not, see <http://www.gnu.org/licenses/>.
*/
// page mod executing content script at every page load.
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");
var urlHandler = require("../url_handler/url_handler");
var pageWorker = require("sdk/page-worker");
var tabs = require("sdk/tabs");
var prefs = require("../addon_management/prefchange");
// contain list of recently found contact links or email addresses.
var contactList = {};
// constants. Also available in lib/ui_info.js
const CERTAIN_EMAIL_ADDRESS_FOUND = 'certainEmailAddressFound';
const UNCERTAIN_EMAIL_ADDRESS_FOUND = 'uncertainEmailAddresFound';
// Looking for contact links
const CERTAIN_LINK_FOUND = 'certainLinkFound';
const PROBABLE_LINK_FOUND = 'probableLinkFound';
const UNCERTAIN_LINK_FOUND = 'uncertainLinkFound';
const LINK_NOT_FOUND = 'contactLinkNotFound';
// Looking for identi.ca and twitter accounts.
const TWITTER_LINK_FOUND = 'twitterLinkFound';
const IDENTICA_LINK_FOUND = 'identicaLinkFound';
// phone number and address
const PHONE_NUMBER_FOUND = 'phoneNumberFound';
const SNAIL_ADDRESS_FOUND = 'snailAddressFound';
/**
* main pageMod.
* Find blocked script in all pages being opened.
* Launch the scripts that search for a complaint contact.
*
*/
pageMod.PageMod({
include: ['file://*', '*', 'data:*', 'about:*'],
contentScriptWhen: 'end',
contentScriptFile: [
data.url('complain/contact_regex.js'),
data.url('complain/link_types.js'),
data.url('settings/third-party/jquery/jquery.min.js'),
data.url('complain/contact_finder.js'),
data.url('complain/pagemod_finder.js'),
data.url('script_detector/script_detector.js')
],
onAttach: function onAttach(worker) {
if (worker.tab !== undefined && prefs.isComplaintTab()) {
// this is a tab.
if (!foundInContactList(worker.url)) {
// the hostname doesn't appear in the object literal.
// run script fetching/complaint feature if applicable.
tabProcess(worker);
} else {
worker.postMessage(foundInContactList(worker.url));
}
}
}
});
/**
* foundInContactList
*
* Provides link if contact link is found for given url, or else
* false.
*/
var foundInContactList = function (url) {
var hostname = urlHandler.getHostname(url);
if (contactList[hostname] !== undefined) {
return contactList[hostname];
} else {
return false;
}
};
/**
* tabProcess
* Find blocked/accepted scripts, prepare
* display panel and complaint panel.
*/
var tabProcess = function (worker) {
var visitedUrl = {};
// webmaster email is better than a webpage.
worker.emailFound = false;
var modUrl = '',
searchUrl = '';
modUrl = worker.url;
console.debug('pagemod triggered');
worker.port.emit('prefs', {
complaintEmailSubject: prefs.complaintEmailSubject(),
complaintEmailBody: prefs.complaintEmailBody()
});
// send local path to complain button graphic.
worker.port.emit('assetsUri',
{'event': 'assets-uri',
'value': data.url('assets/')});
worker.port.emit('pageUrl',
{'event': 'page-url',
'value': modUrl});
worker.on('message', function (respData) {
console.debug('worker is receiving a message', respData.event);
var pw;
worker.on('detach', function () {
console.debug('detaching worker');
if (pw) {
pw.destroy();
}
});
if (respData.contact !== undefined) {
// pass the message to the complaint display panel.
worker.port.emit('complaintLinkFound', respData);
} else if (respData.event === 'complaintSearch') {
if (worker.tab) {
console.debug('worker tab url', worker.tab.url);
}
if (!(respData.urlSearch.linkValue in visitedUrl)) {
visitedUrl[respData.urlSearch.linkValue] = 1;
respData.urlSearch.linkValue = urlHandler.addFragment(
respData.urlSearch.linkValue, 'librejs=true');
pw = searchSecondLevelPage(
this, respData.urlSearch.linkValue, this.url);
}
// currently not needed.
/*else {
console.debug(respData.urlSearch.linkValue, 'already visited');
}*/
}
});
};
var searchSecondLevelPage = function(
worker, urlToSearch, originalUrl) {
/*
var originalWorker = worker;
console.debug('searchSecondLevelPage');
console.debug(urlToSearch, 'and', originalUrl);
if (urlHandler.haveSameHostname(urlToSearch, originalUrl)) {
return pageWorker.Page({
contentURL: urlToSearch,
contentScriptFile: [
data.url('complain/contact_regex.js'),
data.url('complain/link_types.js'),
data.url('settings/third-party/jquery/jquery.min.js'),
data.url('complain/contact_finder.js'),
data.url('complain/worker_finder.js')
],
contentScriptWhen: "end",
onMessage: function (respData) {
console.debug(JSON.stringify(respData));
console.debug(originalWorker.url);
originalWorker.postMessage(respData);
if (respData.event === 'destroy') {
try {
console.debug('destroying worker', this.contentURL);
this.destroy();
} catch (e) {
console.debug('in worker', e);
}
}
}
});
}
*/
};
exports.testModule = {
'contactList': contactList,
'foundInContactList': foundInContactList,
'tabProcess': tabProcess
};
|