Shock Sites Warner

By EQzE Last update Oct 12, 2005 — Installed 900 times.
// ==UserScript==
// @name           Shock Sites Warner
// @namespace      http://www.bingbangboom.us
// @description    Warns user if a page is a shock site
// @include        *
// ==/UserScript==

// list of shock sites
var sites = [
		/http:\/\/([^.]+\.)?tubgirl.com/,
		/http:\/\/([^.]+\.)?goatse\.cx/
	];
// prompt flag
var prompt = false;

// get all links on the page
var links = document.getElementsByTagName('a');

// check if a link is a shock site
for (var i = 0; i < links.length; i++) {
	for (var j = 0; j < sites.length; j++) {
		if ((links[i].getAttribute('href') + '').match(sites[j])) {
			// set background color
			links[i].style.backgroundColor = 'red';
			// check for prompt or delete
			if (!prompt) {
				links[i].removeAttribute('href');
			} else {
				links[i].addEventListener('click', function (e) {
						// confirm the user wants the page to load
						if (prompt && !confirm('This page leads to a blacklisted shock site, "' +
							this.getAttribute('href') + '". Are you sure you want to continue?'))
							e.preventDefault();
					}, true);
			}
		}
	}
}