Jump to content

URL decoding via JavaScript in Alfred


Recommended Posts

Hi everyone,

 

I have to work with Office 365 Advanced Threat Protection 'safelinks' all day long: these are URLs checked for phishing and other cybersecurity issues, then converted into a unique format.

 

https://aus01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.google.com%2F&data=04|lots of parameters and personally identifiable information that isn't important for this purpose|

 

 

There are many tools available to decode these URLs - like https://o365atp.com/ .

 

Rather than pasting URLs into that website every time, I want to use Alfred to process the Office URLs and return the 'real' URL to the clipboard.

 

Digging into the source of that website, the underlying Javascript is pretty straightforward. However my knowledge of scripting is limited to basic bash (and some Perl ten years ago) so I don't know how to convert that link variable into a query passed from Alfred. Can anyone help with this? Thanks in advance!

 

function decode_url()
{
    setTimeout("generate_decode_url()", 20);
}

function generate_decode_url()
{
    var link = document.getElementById("safelink").value;
    var url_parts = link.split("?")[1];
    var params = url_parts.split("&");
    var target_url = "Error:  couldn't find target URL.";
    for(n=0;n<params.length;n++)
    {
        namval = params[n].split("=");
        if(namval[0]=="url") target_url = namval[1];
    }
    
    decode_url = decodeURIComponent(target_url);
    document.getElementById("target_url").value = decode_url;
    
}

function clear()
{
    location.reload();
}

 

 

Edited by AGBear
clarified URL format
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...