Skip to content

Instantly share code, notes, and snippets.

@hackerxian
Forked from mysteriouss/sinaimg.js
Last active September 5, 2017 07:02
Show Gist options
  • Save hackerxian/d8b6cc9863852e0968c621ae537ff061 to your computer and use it in GitHub Desktop.
Save hackerxian/d8b6cc9863852e0968c621ae537ff061 to your computer and use it in GitHub Desktop.
//http://www.cnblogs.com/gaizai/p/4233780.html
//https://www.v2ex.com/t/388152?p=2
(function () {
'use strict';
function string10to62(number) {
var chars = '0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ'.split('');
var radix = chars.length;
var qutient = +number;
var arr = [];
while (qutient !== 0) {
var mod = qutient % radix; // 余数
arr.unshift(chars[mod])
qutient = (qutient - mod) / radix; //求商
}
return arr.join('');
}
function string62to10(number_code) {
number_code = String(number_code);
var chars = '0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ',
radix = chars.length,
len = number_code.length,
i = 0,
origin_number = 0;
while (i < len) {
origin_number += Math.pow(radix, i++) * chars.indexOf(number_code.charAt(len - i) || 0);
}
return origin_number;
}
function decode(url) {
var lastIndexOfSlash = url.lastIndexOf('/');
var number = url.substr(lastIndexOfSlash + 1, 8);
if (number.startsWith('00')) {
return string62to10(number);
} else {
return parseInt(number, 16);
}
}
window.location = 'https://weibo.com/u/' + decode(window.location.href);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment