Skip to content

Instantly share code, notes, and snippets.

@JasonMillward
Created March 14, 2012 23:42
Show Gist options
  • Save JasonMillward/2040446 to your computer and use it in GitHub Desktop.
Save JasonMillward/2040446 to your computer and use it in GitHub Desktop.
jQuery link follower (Simulates browsing through links on your website)
/**
* jQuery Link follower
*
*
* Used to simulate browsing a website.
* Can be used in conjunction with Tor to falsify hits and visitors.
*
* Place in header of template and view page in normal browser.
* Watch console for information
*
* If page is not on your website, or going somewhere it shouldn't
* add additional exclusions (This should become an array in the future)
*
*
*/
// Array for link storing
var links = [];
// Website to stay on
var yourWebsite = "github.com";
jQuery.noConflict(), jQuery(document).ready(function() {
// Random function
function rand(a, b) {
return Math.floor(Math.random() * (b - a + 1) + a);
}
// For every anchor element, find the href if it exists
// If it exists, and link is on your domain/website
// add it to the links array
// If not, retry with another anchor element
$("a").each(function() {
var href = $(this).attr("href");
if (typeof href != "undefined"
&& href.indexOf(yourWebsite) !== -1
&& href.indexOf("wp-admin") === -1
&& href !== document.location.href
) {
links.push($(this).attr("href"));
}
});
// Create the timeout, anywhere from 2 to 5 minutes
var timeOut = rand(120000, 300000);
// The new page to be redirected to is one in the links array
var page = links[Math.floor(Math.random() * links.length)];
// Because some browsers don't support console logging
try {
console.log("Event fired!");
console.log("Delay set for " + timeOut);
console.log("New location set for: " + page);
} catch (e) {
}
// After the timeout period, fire the event.
setTimeout(function() {
window.location = page;
}, timeOut);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment