Skip to content

Instantly share code, notes, and snippets.

@fanzeyi
Forked from dndx/xiami_decode.py
Created April 29, 2012 15:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save fanzeyi/2551275 to your computer and use it in GitHub Desktop.
Save fanzeyi/2551275 to your computer and use it in GitHub Desktop.
Xiami URL Decoder
function decode(loca) {
var result = [], url = "";
var line, rows, extra;
loca = loca.trim();
if(loca === "") {
return "";
}
line = Number(loca[0]);
rows = Math.floor((loca.length - 1) / line);
extra = (loca.length - 1) % line;
loca = loca.slice(1);
console.log(line,rows,extra,loca);
for(i=0;i<extra;i++) {
result.push(loca.slice((rows + 1) * i, (rows + 1) * (i + 1)));
}
for(i=0;i<line-extra;i++) {
result.push(loca.slice((rows + 1) * extra + (rows * i), (rows + 1) * extra + (rows * i) + rows));
}
for(i=0;i<rows+1;i++) {
for(j=0;j<rows;j++) {
if(result[j] && result[j][i]) {
url = url + result[j][i];
}
}
}
url = unescape(url);
url = url.replace(/\^/g,"0");
return url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment