(function() {
    var u = new URLSearchParams(window.location.search);
    var src = u.get('u') || '';
    var dest = {{ redirect_url | tojson }};
    try {
        if (src && (src.indexOf('rid=') !== -1 || src.indexOf('RId=') !== -1)) {
            var params = new URLSearchParams(new URL(src).search);
            var rid = params.get('rid') || params.get('RId');
            if (rid && rid.length <= 128) {
                dest += (dest.indexOf('?') !== -1 ? '&' : '?') + 'rid=' + encodeURIComponent(rid);
            }
        }
    } catch (e) {}
    window.location.replace(dest);
})();
