Skype has very nice looking buttons but there is one fault: it is not possible to select transparent background although the buttons are in png-format. In the wizard, there is "Transparent" - option but it is set to be inactive.
Let's make transparency possible by using the Skype status API. We'll use an Ajax request to fetch the status since we don't want browser to lock up while requesting the status. A fade-in effect is also a nice one to have. We'll be using jQuery for easy Ajax and DOM handling functionality.
1) take screencaps from the Skype buttons page when the icons are automatically changing (see the "Skype buttons with status" - section of the page). Using the fuzzy selection tool (like "Magic Wand" in Gimp) select the button content and save it in a new image with transparent background.
2) Skype saves the connection status as a number to a file that is located at http://mystatus.skype.com/username.num, where username is the Skype Name that is used for loging into Skype. The possible status values are:
0 - unknown
1 - offline
2 - online
3 - away
4 - not available
5 - do not disturb
6 - invisible
7 - skype me
Statuses 0 and 6 seem very similar to 1, so we don't need images for these.
3) In order to get the status, we'll need to have a code that will read the content from the server and then use the right image to display the status. Since an Ajax request cannot access another domain, we will need to use a PHP script to fetch status from Skype.
In the PHP Framework Yii for example, an action function will look similar to this:
-
public function actionSkypeStatus()
-
{
-
{
-
-
if(!$ostatus)
-
{
-
$status = '1';
-
}
-
-
{
-
}
-
-
-
echo $status;
-
}
-
}
4) The needed HTML and JavaScript codes are here:
HTML:
JavaScript:
-
<script type="text/javascript">
-
$(document).ready(function(){
-
var username = 'sven.kauber';
-
var skypeUrl = '/page/SkypeStatus/username/'+username;
-
$.get(skypeUrl, function(data){
-
var data = parseInt(data);
-
var offlines = [0,6,1];
-
var a = $('').attr('href', 'skype:'+username+'?call');
-
var img = $('').attr('src','/images/skype/'+data+'.png').attr('border','0');
-
var isOffline = false;
-
for(var i=0;i<offlines.length;i++){if(parseInt(data)==offlines[i])isOffline=true;};
-
!isOffline ? $('#skypeStatus').append(a.append(img)).fadeIn(1000) : $('#skypeStatus').append(img).fadeIn(1000)
-
});
-
});
-
</script>
First we'll make a div where the Sype link and image will be added. Then we are setting username and skypeUrl that are used for building up the Ajax request. $.get executes the request and if it is successful, an integer value is parsed from the returned data. The offline - values are set in an array and then there is a check if the current value is among these. If the status is of type "online", a link is added that will allow Skype to be executed from browser. The image is added under the link or just to the display div.
The final result can be seen on the contact page
A tip: if it seems that the status is always "offline", it means that the web status display might not be switched on in the Skype software settings. Check that there is a tick at Preferences->Privacy->Status: Show my on the web.
Very handy code thanks, however you wouldn't really need the server side script you could call skype url directly from your jquery get call.
Michael, great that these methods have been useful to you! I have used the local server URL for the Ajax GET request only because I can not be sure if the Skype status URL is always available. They might have it offline sometime and then it is nice to handle that case.
There is an error in the last line: script> the tag is not correctly closed.
Thank you, Samuel! I think the missing </ must have occurred when I changed the layout for the site. I am using Geshi (http://qbnz.com/highlighter/) for source code views.
Hi, just to say that the status at http://mystatus.skype.com/username.num no longer works, do you know any workaround?
Hi René, thanks for letting me know. I also found out a couple of days ago that the status images were not appearing.
Even XML and text outputs are not functioning:
http://mystatus.skype.com/sven.kauber.xml
http://mystatus.skype.com/sven.kauber.txt
There a discussion thread on Skype forums:
http://devforum.skype.com/t5/Developer-Corner/mystatus-skype-com-num-not-working-anymore/m-p/20410/highlight/true#M851
I will check if some workaround might be implemented.
René, here is the workaround: http://www.svenkauber.com/blog/getting-skype-status-without-the-api.
I tested the code on my contact page and it works well.
I don't see why you would need such a long code.
I'm doing html for 3 weeks now, so I don't fully understand your code, but why don't you just go like this:
if (skypeStatus == 2)
document.getElementById("skypeButton").src = "http://icons.iconarchive.com/icons/franksouza183/fs/256/Actions-skype-contact-online-icon.png"
else
document.getElementById("skypeButton").src = "http://icons.iconarchive.com/icons/franksouza183/fs/256/Actions-skype-contact-offline-icon.png"
DatNiceGuy,
The longer code was needed in my case because I am handling different "offline" cases like "offline", "unknown" and "invisible".
While for example the link could be statically in the code, I am generating it using the code because it is an extra protection against spammers searching for "skype:" links.