A Script for the Right-Click Suppressed

by Pete

The purpose of this article is to provide an extension to "Right-Click Suppression" by Rob Rohan in 18:4.

Blocking right-clicks, whether on the entire, or just images, is growing more and more popular as a form of weak copyright protection.  I've encountered sites attempting to prevent me saving material copyrighted by people other than the owner of the page!

In addition to the methods mentioned by Mr. Rohan, Windoze users can click on an image and drag it from the browser to their desktop or another folder to copy the image.  Linux users can try the provided script.

The Script

The script isninja.pl is designed to get around that kind of right-click protection without having to root though the source yourself.

Supply it with a few URLs and it will print all at the scripts (including the one used to block your right-clicks) found on those pages, along with the URLs of the images.

Optionally, it will download the images and put them in the current directory.  It you want to download the Flash presentations, the MIDI music, or whatever, it would be fairly easy to add that to the script.

In the absence of wget, Mr. Rohan's Java app would also work well.  I had to dust off my Perl skills for this, so please forgive me if it's a bit sloppy.

# Image/Script Ninja by Pete
# Takes URLs and prints the locations of images (and optionally downloads the
# images) and the scripts found on the pages. 'isninja.pl --help' for more information.
# Use it while you can, for tomorrow it will be illegal.
print "Starting Image/Script Ninja...\n\n\n";

# Make sure the user supplied the correct arguments and didn't specify '--help'.
if (@ARGV < 1 || "@ARGV" =~ /--help/) {
	print "Usage:\nisninja.pl [--getimages] url1 [url2, url3...]\n";
	print "URL(s) must end in a filename (*.html, etc.) or a trailing slash.\n";
	print "--getimages downloads the image instead of only printing its URL.\n";

# See if user wanted to save the images
if ("@ARGV" =~ /--getimages/) {
	$getimages = 1;
else {
	$getimages = 0;

# Go through each URL
for ($loop = 0; $loop < @ARGV; $loop++) {
	# Make sure it's not the argument!
	if ($ARGV[$loop] eq "--getimages") {
	# Grab the file
	@file = `wget $ARGV[$loop] --output-document=-`;
	# To keep everything seperate
	print "\n\nResults from $ARGV[$loop]...\n";
	$scrnum = 0;
	$imgnum = 0;
	# Check each line
	for ($line = 0; $line < @file; $line++) {
			# Is there an image?
			if ($file[$line] =~ /<img/i) {
				# If so, parse the line in a sloppy manner
				@fs = split(/[<>]/, $file[$line]);
				for ($loop2 = 0; $loop2 < @fs; $loop2++) {
					if ($fs[$loop2] =~ /scr/i) {
						@top = split(/\"/, $fs[$loop2]);
						for ($loop3 = 1; $top[$loop3 - 1] !~ /src/i; $loop3++) {
						$tmp = $ARGV[$loop];
						$tmp2 = chop($tmp);
						while ($tmp2 ne "/") {
							$tmp2 = chop($tmp);
						$imgurl = $tmp.'/'.$top[$loop3];
						print "Image #$imgnum; $imgurl\n";
						if ($getimages) {
							system("wget $imgurl");
	 	# Is there a script?
		if ($file[$line] =~ /<script/i) {
			# If so, print the code from <script> to </script>
			print "===Script #$scrnum===\n";
			# The nested stuff is here in case anyone uses a script
			# to print otu another script or something.
			$nested = 0;
			while ($line < @file) {
				print $file[$line];
				if ($file[$line] =~ /<script/i) {
				if ($file[$line] =~ /\/script/i) {
					if(!($nested)) {
			print "===End Script #$scrnum===\n";
print "Finished.\n";

Code: isninja.pl

Return to $2600 Index