singularity / sinaimg

// ==UserScript==
// @name         sinaimg
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  press 'u' to find pic owner's weibo account
// @author       edited by me, forked from mysteriouss/sinaimg.js
// @match        *://*.sinaimg.cn/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    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);
        }
    }
    document.onkeyup = function(e){
        if (e.keyCode == 85) {
            window.location = 'https://weibo.com/u/' + decode(window.location.href);
        }
    };
})();