Nov 07 2011

Unobtrusive javascript to add an overlay banner

Category: Html,JavascriptGiulio Pons @ 12:40 pm

If you have to add an overlay to a site, here is a fast way to do it with an unobtrusive javascript. Add this file to your site, just before the closing body tag, and customize the overlay() function inside the js file.

This code adds a div to cover your page with an opaque layer (you can customize the color and the opacity in the css, it’s the ovContainer0 div).

After the opaque layer which made unclickable and opaque the page, it’s inserted another div over it, which is not opaque and is used to center the overlay and contain the desidered HTML (your banner or anything else). Inside this div (which is called ovContainer) there is also another div (ovBox) that is, finally, used to contain the button whit an X to close it (ovClose) and your code. The ovBox div is dinamycally centered vertically.

You can customize the CSS of the opaque layer and the overlay box, probably you will never need to customize the CSS of the ovContainer.

Here is the function that overlay the layer that you have to customize inside the overlay.js file:

function overlay() {
	// CUSTOMIZE CSS
	ov_css (
		"#ovContainer0 {background-color:#FFF;position:absolute; width:100%; height:100%; top:0px; left:0px; z-index:10000; "+
		"opacity: .70;filter: alpha(opacity=70);-ms-filter: \"alpha(opacity=70)\";-khtml-opacity: .70;-moz-opacity: .70;}"+
		"#ovContainer {background-color:transparent;position:absolute; width:100%; height:100%; top:0px; left:0px; z-index:10000; }"+
		"#ovBox { position:relative; width:500px; min-height:150px; border:1px solid #FF9900; background-color:#FFFFCC; }"+
		"#ovContainer > #ovBox { position:fixed; }"+
		"#ovBox #ovClose { display:block; position:absolute; top:10px;right:10px;margin:5px;  padding:3px; border:1px solid #FF9900; font:12px arial; text-transform:uppercase; text-align:center; color:#000; background-color:#FFCC66; text-decoration:none; }"
	);
	// CUSTOMIZE HTML and GO!
	ov_add(
		"<a href='http://www.ecomondo.com/' target='_blank'><img src='/web/common/img/BANNER.jpg'/>"
	);
}

Download here the overlay.js file soure or use the minified version here.

You can see an example here.

Share

Tags: , , , , ,


Nov 01 2011

PHP code to check if remote mp3 exists

Category: Php,Spiders & web botsGiulio Pons @ 4:30 pm

Hi, I’ve a big table with thousands of mp3 links. Sice these links come from an old database, many of them are old and expired. Here is a function that I’ve included in my Minibots Class. The function uses checkdnsrr to verify the domain and then uses curl to fetch the mp3 file and verify the mime type. I’ve used checkdnsrr first because it seems faster.

function checkMp3($url) {
	if (!function_exists("curl_init")) die("getHttpResponseCode needs CURL module, please install CURL on your php.");
	$a = parse_url($url);
	if(checkdnsrr(str_replace("www.","",$a['host']),"A") || checkdnsrr(str_replace("www.","",$a['host']))) {
		$ch = @curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HEADER, 1);
		curl_setopt($ch, CURLOPT_NOBODY, 1);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_TIMEOUT, 15);
		$results = explode("\n", trim(curl_exec($ch)));
		$mime = "";
		foreach($results as $line) {
			if (strtok($line, ':') == 'Content-Type') {
				$parts = explode(":", $line);
				$mime = trim($parts[1]);
			}
		}
		return $mime=="audio/mpeg";
	} else {
		return false;
	}
}
Share


Sep 14 2011

New Facebook Invite all friends hack

Category: Facebook,JavascriptGiulio Pons @ 12:19 pm

So, you want to invote all your friends but the old hack doesn’t work anymore?

With the last facebook friends groups restyle the code trick to send invitation to all friends do not work anymore. Moreover, you’ve installed the last Firefox, and you can’t use anymore the url address bar to input javascript commands.

It was the same for me. But I’ve find this path to invite all your friends to your new brand facebook page, follow this steps.

1) Use Firefox 6.

2) Open your facebook fan page.

3) Click on “Invite friends”.

4) The grid of friends is opened.

5) Select “Search all friends” and scroll down, so all your friends are loaded.

6) Press Ctrl+Shift+K.

7) A firefox panel is opened on the top of the page, here you can put the javascript code (put the two lines in a single line):

elms=document.getElementById('pop_content').getElementsByTagName('li');
for(var fid in elms){if(typeof elms[fid] === 'object'){elms[fid].click();}}

This code will select eache friend and perform a click on it.

8) Press “enter”.

9) Wait the selecetion (it could take some minute).

10) Press “submit”.

Today (09/14/2011) it works.

Share

Tags: , , , , ,


Next Page »