What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » URL Shortening Script?

URL Shortening Script?
Author: Message:
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: URL Shortening Script?
I'm too lazy busy to make the GUI, but you could probably use these functions:
JScript code:
var login = "roflmao456";
var api_key = "R_0d142cec1c6940a9d270d5420f2c90fb";
 
var get_link_hash = function(url){
    // Should work on most url shortener sites.
    return /(.*)\.(.*)\/(.*)/.test(url)?RegExp.$3:url;
    };
 
function OnEvent_Initialize(MessengerStart){
    shorten_url("http://google.com", callbackdebug);
    expand_url("http://bit.ly/bZc0H", callbackdebug);
    }
 
function callbackdebug(param){
    Debug.Trace(param);
    }
 
function shorten_url(url, callback){
    // Shortens url with bit.ly
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.open("GET", "http://api.bit.ly/shorten?version=2.0.1&longUrl=" + url + "&login=" + login + "&apiKey=" + api_key, 1);
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readystate == 4 && xmlhttp.status == 200){
            eval("var result = " + xmlhttp.responseText);
            if(result.statusCode == "OK"){
                var shortUrl = result.results[url]['shortUrl'];
                Debug.Trace("shortened " + url + ": " + shortUrl);
                if(typeof callback == "function")
                    callback(shortUrl);
                }
            }
        }
    xmlhttp.send();
    }
 
function expand_url(url, callback){
    // Expands a bit.ly url
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.open("GET", "http://api.bit.ly/expand?version=2.0.1&shortUrl=" + url + "&login=" + login + "&apiKey=" + api_key, 1);
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readystate == 4 && xmlhttp.status == 200){
            eval("var result = " + xmlhttp.responseText);
            if(result.statusCode == "OK"){
                var longUrl = result.results[get_link_hash(url)]['longUrl'];
                Debug.Trace("expanded " + url + ": " + longUrl);
                if(typeof callback == "function")
                    callback(longUrl);
                }
            }
        }
    xmlhttp.send();
    }


This post was edited on 09-22-2009 at 12:33 AM by roflmao456.
[quote]
Ultimatess6
: What a noob mod
09-22-2009 12:32 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
URL Shortening Script? - by Shadowajohn on 09-21-2009 at 07:58 PM
RE: URL Shortening Script? - by foaly on 09-21-2009 at 11:36 PM
RE: URL Shortening Script? - by roflmao456 on 09-22-2009 at 12:32 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On