forked from Xodarap/Paranoid-Browsing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
36 lines (30 loc) · 1.05 KB
/
content.js
File metadata and controls
36 lines (30 loc) · 1.05 KB
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
function processPage(depth) {
if(depth > 8) {
console.log('Paranoid: No good links found on page. Restarting.')
chrome.extension.sendMessage({ paranoidRestart: true });
}
var allLinks = document.getElementsByTagName('a');
linkCount = allLinks.length;
if(linkCount == 0) {
console.log('Paranoid: No links found on page. Restarting.');
chrome.extension.sendMessage({ paranoidRestart: true });
return;
}
var linkSel = Math.floor(Math.random() * linkCount);
var newLink = allLinks[linkSel];
var pattern = new RegExp('^https?:\/\/.*') // basic URL check, just to avoid javascript-only links
// Don't "navigate" to links which are on the same page
// or aren't real links
if(newLink.href == document.URL ||
newLink.href == (document.URL + '#') ||
!pattern.test(newLink.href)) {
processPage(depth + 1)
}
// Wait some random, pseudo-realistic amount of time
var waitTime = Math.floor(Math.random() * 10000) + 5000;
setTimeout(function() {
console.log('Paranoid: sending to: ' + newLink.href);
newLink.click();
}, waitTime);
}
processPage(0);