Shoutbox

URL Shortening Script? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: URL Shortening Script? (/showthread.php?tid=92310)

URL Shortening Script? by Shadowajohn on 09-21-2009 at 07:58 PM

I was just wondering if it possible to make a script that would change all links in to (for example) bit.ly links?

It would basically search the message box, and if any links were found it would submit it to bit.ly and replace the url with the shortened version?

Something similar to URL shortener in TweetDeck(if anyone uses)


RE: URL Shortening Script? by foaly on 09-21-2009 at 11:36 PM

well there is a tinyurl script:
http://www.messengerpluslive.com/scripts/view/303-TinyURL/
haven't tried it though...


RE: URL Shortening Script? by roflmao456 on 09-22-2009 at 12:32 AM

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();
    }