Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
[background.js] fix resolvePlaybackLink
Browse files Browse the repository at this point in the history
  • Loading branch information
myfreeer committed Oct 17, 2016
1 parent 51f302f commit 597687d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function resolvePlaybackLink(avPlaybackLink, callback) {
xmlhttp.onreadystatechange = xmlChange;
xmlhttp.ontimeout = xmlChange;
xmlhttp.onerror = xmlChange;
xmlhttp.timeout = 3000;
//xmlhttp.timeout = 3000;
xmlhttp.send();
}

Expand Down

1 comment on commit 597687d

@myfreeer
Copy link
Owner Author

@myfreeer myfreeer commented on 597687d Oct 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

  • video rotation using css3
document.getElementById('bilibili_helper_html5_player_video').style.zIndex=0;
document.getElementsByClassName('ABP-Container')[0].style.zIndex=1;
document.getElementById('bilibili_helper_html5_player_video').style.transform='rotate(180deg)'

http://isithackday.com/hacks/videozoomandrotate/transforming-video.html

  • mirroring video
    transform: matrix(-1, 0, 0, 1, 0, 0); 
  • get real video size
document.getElementById('bilibili_helper_html5_player_video').videoHeight; // returns the intrinsic height of the video
document.getElementById('bilibili_helper_html5_player_video').videoWidth; // returns the intrinsic width of the video

ref: http://stackoverflow.com/questions/4129102/html5-video-dimensions

var vid = document.getElementById("bilibili_helper_html5_player_video");
vid.onloadedmetadata = function() {
vid.videoHeight; // returns the intrinsic height of the video
vid.videoWidth; // returns the intrinsic width of the video
}

https://github.com/myfreeer/bilibili-helper/blob/hd/bilibili_injected.js#L1006

should notice that http://biliquery.typcn.com/api/user/hash/5cc0bbf4(39999998) and hashes from less than 39999998 (0-39999998 exactly) can return a value;so we can use checkCommentHash(hash, 65E6, 4E7-2), and calculate checkCommentHash(hash, 4E7) on fails
https://github.com/myfreeer/bilibili-helper/blob/hd/bilibili_injected.js#L1006-L1031

/* crc32.js (C) 2014-present SheetJS -- http://sheetjs.com 
/*exported CRC32 */
var CRC32 = {};
(function(CRC32) {
    function signed_crc_table() {
        var c = 0,
            table = new Array(256);
        for (var n = 0; n != 256; ++n) {
            c = n;
            for (var x = 0; x < 8; x++) c = ((c & 1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1));
            table[n] = c;
        }
        return typeof Int32Array !== 'undefined' ? new Int32Array(table) : table;
    }
    var T = signed_crc_table();

    function crc32_bstr(bstr, seed) {
        var C = seed ^ -1,
            L = bstr.length - 1;
        for (var i = 0; i < L;) {
            C = (C >>> 8) ^ T[(C ^ bstr.charCodeAt(i++)) & 0xFF];
            C = (C >>> 8) ^ T[(C ^ bstr.charCodeAt(i++)) & 0xFF];
        }
        if (i === L) C = (C >>> 8) ^ T[(C ^ bstr.charCodeAt(i)) & 0xFF];
        return C ^ -1;
    }
    CRC32.bstr = crc32_bstr;
})(CRC32);

function checkCommentHash(hash, maximumMid, minimumMid) {
    maximumMid = parseInt(maximumMid) ? parseInt(maximumMid) : 65000000;
    minimumMid = parseInt(minimumMid) ? parseInt(minimumMid) : 0;
    if (!hash) return false;
    if (hash.indexOf('D') == 0) return -1;
    var hashint = parseInt(hash, 16);
    if (!hashint) return false;
    for (var i = minimumMid; i < maximumMid + 1; i++) {
        if ((CRC32.bstr("" + i) >>> 0) === hashint) {
            return i;
        }
    }
    return false;
}
$.ajaxSetup({timeout:1000});
$.get('http://biliquery.typcn.com/api/user/hash/' + sender, function(data) {
$.ajaxSetup({timeout:0});
    if (!data || data.error != 0 || typeof data.data != 'object' || !data.data[0].id) {
        var uid = checkCommentHash(sender, 65E6, 4E7 - 2);
        displayUserInfobyMid(uid);
    } else {
        var uid = parseSafe(data.data[0].id);
        if (uid) displayUserInfobyMid(uid);
    }
}, 'json').fail(function() {
    var uid = checkCommentHash(sender, 65E6);
    displayUserInfobyMid(uid);
});

var displayUserInfobyMid = function(mid) {
    if (!mid) return control.find('.result').text('查询失败 :(');
    else if (mid === -1) return control.find('.result').text('游客弹幕');
    control.find('.result').html('发送者 UID: <a href="http://space.bilibili.com/' + mid + '" target="_blank" mid="' + mid + '">' + mid + '</a>');
    var data = sessionStorage.getItem('user/' + mid);
    if (data) {
        displayUserInfo(mid, JSON.parse(data));
        return false;
    }
    $.getJSON('http://api.bilibili.com/cardrich?mid=' + mid + '&type=jsonp', function(data) {
        if (data.code == 0) {
            sessionStorage.setItem('user/' + mid, JSON.stringify({
                name: data.data.card.name,
                level_info: {
                    current_level: data.data.card.level_info.current_level
                }
            }));
            displayUserInfo(mid, data.data.card);
        }
    });
};

Please sign in to comment.