diff --git a/README.md b/README.md index 0495bd2..c1ff304 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![website](https://img.shields.io/website-up-down-green-red/https/shields.io.svg?label=website)](http://btools.cc) ## 前言 -如果你想参观代码(屎山),请先看这里。 +如果你想参观代码(**屎山**),请先看这里。 代码是纯jQuery项目,没其他框架,没用其他工具,目录结构、文件名、函数名我记几个儿随便瞎起的,所以观赏性极差,劝你做好心理准备。 ## 介绍 @@ -70,6 +70,11 @@ Btools(逼砣),本插件主要目的是以B站为主的网站页面优化, * 修复历史表情无法出现的BUG * 修复点击楼中楼历史表情输入到主评论框的BUG * 现在历史表情可以增加更多的表情 + * 修复视频简介超链接只能获取到最后一个的BUG +* `2020-04-13` + * 收藏夹失效视频又双叒叕回来了(兼容BV) + * 优化收藏夹失效视频的获取方式,现在可以一次获取一整页 + * 现在视频页面中的“打开封面”按钮会根据播放器的位置而改变 * #### [关于查看失效视频半全恢复说明](https://btools.cc/announcement-2019-11-04/) diff --git a/background.html b/background.html index 8ef4bd6..45b4e90 100644 --- a/background.html +++ b/background.html @@ -6,5 +6,6 @@ + diff --git a/background.js b/background.js index 453eaf2..d34b22a 100644 --- a/background.js +++ b/background.js @@ -7,38 +7,26 @@ var BtoolsInfo = { // 安装完成后 chrome.runtime.onInstalled.addListener(function(details) { - + // 1.1.3 清除本地缓存 + chrome.storage.sync.set({ + localCache: {} + }); }); chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { - switch(request.type) { - case 'fetch': - fetch(request.url) - .then(function(response) { return response.json() }) - .then(function(json) { return sendResponse(json) }) - .catch(function(error) { return sendResponse(null) }); - return true; // Will respond asynchronously. - break; - case 'post': - fetch(request.url, { - method: 'POST', - mode: 'cors', - credentials: 'include', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - }, - body: JSON.stringify(request.data) - }) - .then(function(response) { return response.json() }) - .then(function(json) { return sendResponse(json) }) - .catch(function(error) { return sendResponse(null) }); - return true; // Will respond asynchronously. - break; - case 'getInfo': - sendResponse(BtoolsInfo); - break; - } + switch(request.type) { + case 'fetch': + fetch(request.url) + .then(function(response) { return response.json() }) + .then(function(json) { return sendResponse(json) }) + .catch(function(error) { return sendResponse(null) }); + return true; // Will respond asynchronously. + break; + case 'getInfo': + sendResponse(BtoolsInfo); + break; + } }); /* diff --git a/core/Btools.js b/core/Btools.js index 6b90965..cb0faaf 100644 --- a/core/Btools.js +++ b/core/Btools.js @@ -23,31 +23,75 @@ var Btools = { } } +var avbv = { + table: 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF', + xor: 177451812, + add: 8728348608, + s: [11, 10, 3, 8, 4, 6] +} + // BV2AV - 参考 http://bv2av.com/ function bv2av(bv) { - var table = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'; - var s = [11, 10, 3, 8, 4, 6]; - - var xor = 177451812; - var add = 8728348608; - var result = 0; for(var i = 0; i < 6; i++) { - result += table.indexOf(bv[s[i]]) * 58 ** i; + result += avbv.table.indexOf(bv[avbv.s[i]]) * Math.pow(58, i); } - var av = (result - add ^ xor); + var av = (result - avbv.add ^ avbv.xor); return av; } +function av2bv(av) { + av = (av ^ avbv.xor) + avbv.add; + var result = ['B', 'V', '1', ' ', ' ', '4', ' ', '1', ' ', '7', ' ', ' ']; + for(var i = 0; i < 6; i++) { + result[avbv.s[i]] = avbv.table[Math.floor(av / Math.pow(58, i)) % 58]; + } + return result.join(''); +} + chrome.runtime.sendMessage({ type: 'getInfo' }, function(info) { Btools.version = info.version; Btools.releaseVersion = info.releaseVersion; Btools.info = '%c ____ __ ___\n/\\ _`\\ /\\ \\__ /\\_ \\\n\\ \\ \\L\\ \\\\ \\ ,_\\ ___ ___\\//\\ \\ ____\n \\ \\ _ <\'\\ \\ \\/ / __`\\ / __`\\\\ \\ \\ /\',__\\\n \\ \\ \\L\\ \\\\ \\ \\_/\\ \\L\\ \\/\\ \\L\\ \\\\_\\ \\_/\\__, `\\ \n \\ \\____/ \\ \\__\\ \\____/\\ \\____//\\____\\/\\____/\n \\/___/ \\/__/\\/___/ \\/___/ \\/____/\\/___/\n\n version ' + info.version; }); +/* +var getCookie = function (NameOfCookie) { + if (document.cookie.length > 0) { + begin = document.cookie.indexOf(NameOfCookie + "="); + if (begin !== -1) { + begin += NameOfCookie.length + 1; + end = document.cookie.indexOf(";", begin); + if (end === -1) end = document.cookie.length; + return unescape(document.cookie.substring(begin, end)); + } + } + return null; +} +*/ + +/* +$.ajax({ + type: 'POST', + url: 'https://api.bilibili.com/x/web-interface/archive/like', + data: { + aid: 882653974, + like: 1, + csrf: getCookie('bili_jct') + }, + success: function(json) { + return console.log(json) + }, + error: function(error) { + return console.log(error) + }, + dataType: 'json' +}); +*/ + // 监听加载状态改变 document.onreadystatechange = function() { if (document.readyState === 'complete') { diff --git a/core/openImg/m.js b/core/openImg/m.js index b1745b3..173df5d 100644 --- a/core/openImg/m.js +++ b/core/openImg/m.js @@ -59,6 +59,16 @@ openImgSet.timer = setInterval(function(){ ]); } + $(window).resize(function() { + var bofqiTop = $('#bofqi').offset().top + 22; + var bofqiLeft = $('#bofqi').offset().left - 40; + console.log(bofqiTop); + $('.BtoolsLogoBtn').css({ + 'top': bofqiTop, + 'left': bofqiLeft + }); + }); + clearInterval(openImgSet.timer); // 直播封面获取 diff --git a/core/viv/m.js b/core/viv/m.js index 5d04620..a0b6bd7 100644 --- a/core/viv/m.js +++ b/core/viv/m.js @@ -14,9 +14,7 @@ var VivSet = { timerOff: false, eqNum: 0, fav: null, - expiredTimer: null, expired: null, // 存储失效视频 - expiredIndex: 0, // 当前正在获取信息的失效视频 count: 0, pn: 1, isKey: false, @@ -144,16 +142,20 @@ function VivInit() { if(VivSet.fav !== null) { $(this).find('a:eq(1),.meta-mask,a.disabled').HKM('clear'); - var upMid = VivSet.fav[index].upper.mid; + var upMid = VivSet.fav[index].hasOwnProperty('upper') ? VivSet.fav[index].upper.mid : ''; + if(upMid != '') { + $(this).find('a:eq(1),.meta-mask,a.disabled').HKM([ + { + 'key': 85, + 'title': '打开UP主空间', + 'action': function() { + window.open('http://space.bilibili.com/' + upMid); + void(0); + } + } + ]); + } $(this).find('a:eq(1),.meta-mask,a.disabled').HKM([ - { - 'key': 85, - 'title': '打开UP主空间', - 'action': function() { - window.open('http://space.bilibili.com/' + upMid); - void(0); - } - }, { 'key': 68, 'title': '详情信息', @@ -309,7 +311,7 @@ function favJson() { // 如果本地有缓存 if(BtoolsConfig.localCache.hasOwnProperty(item.id)) { var videoInfo = BtoolsConfig.localCache[item.id]; - var liDisabled = $('.fav-video-list li[data-aid=' + item.id + ']'); + var liDisabled = $('.fav-video-list li[data-aid=' + av2bv(item.id) + ']'); liDisabled.addClass('BtoolsVivFinded'); @@ -328,7 +330,7 @@ function favJson() { } else { // 否则查询 - VivSet.expired.push(item); + VivSet.expired.push(item.id); } } }); @@ -338,31 +340,39 @@ function favJson() { } }); - if(VivSet.expired !== null && VivSet.expiredTimer === null) { + if(VivSet.expired !== null && VivSet.expired.length !== 0) { if($('.fav-video-list li.disabled').length == $('.fav-video-list li.BtoolsVivFinded').length) { - if(VivSet.expiredTimer !== null) { - clearInterval(VivSet.expiredTimer); - VivSet.expired = null; - VivSet.expiredTimer = null; - } + VivSet.expired = null; return; } - VivSet.expiredTimer = setInterval(function() { - var video = VivSet.expired[VivSet.expiredIndex]; - if(video === undefined || !video.hasOwnProperty('id')) return; - var url = 'https://www.biliplus.com/api/view?id=' + video.id; - chrome.runtime.sendMessage({ + + var url = 'https://www.biliplus.com/api/aidinfo?aid=' + VivSet.expired.join(','); + chrome.runtime.sendMessage({ type: 'fetch', url: url - }, - function(json) { - if(json !== null) { - var isPic = json.hasOwnProperty("pic"); - var isTitle = json.hasOwnProperty("title"); - var isCode = json.hasOwnProperty("code"); - var liDisabled = $('.fav-video-list li[data-aid=' + video.id + ']'); - - if($('.BtoolsVivLoaddingBG').length === 0) { + }, function(json) { + + $.each(VivSet.expired, function(index, expiredItem) { + + if(typeof json.data == 'undefined' || typeof json.data[expiredItem] == 'undefined') { + // 添加到插件本地存储 + addLocalCache(expiredItem, { + title: '缓存失效', + pic: '' + }); + return true; + } + + var item = json.data[expiredItem]; + + var isPic = item.hasOwnProperty("pic"); + var isTitle = item.hasOwnProperty("title"); + var isCode = item.hasOwnProperty("code"); + + var liDisabled = $('.fav-video-list li[data-aid=' + av2bv(expiredItem) + ']'); + + if(liDisabled.find('.BtoolsVivLoaddingBG').length !== 0) return true; + liDisabled.css({ 'position': 'relative' }).append('
' + Btools.logo() + '

正在查找···

'); @@ -373,64 +383,64 @@ function favJson() { $('.BtoolsVivLoadding').css({ 'left': (liDisabled.outerWidth() / 2) - ($('.BtoolsVivLoadding').outerWidth() / 2) }); - } - if(isPic) { - liDisabled.find('.disabled-cover').remove(); - liDisabled.find('.cover img').attr({ - 'src': json.pic + '@380w_240h_100Q_1c.webp', - 'alt': '图片文件失效' - }).css({ - '-webkit-filter': 'none' - }); - } - if(isTitle) { - liDisabled.find('.title').text(json.title).css({ - 'color': '#F66', - 'font-weight': '700' - }); - - // 失效视频 搜索视频 - liDisabled.find('a:eq(1),.meta-mask,a.disabled').HKM([ - { - 'key': 83, - 'title': '搜索标题', - 'position': 'first', - 'action': function() { - window.open('https://www.baidu.com/s?wd=' + json.title); - void(0); + if(isPic) { + liDisabled.find('.disabled-cover').remove(); + liDisabled.find('.cover img').attr({ + 'src': item.pic + '@380w_240h_100Q_1c.webp', + 'alt': '图片文件失效' + }).css({ + '-webkit-filter': 'none' + }); + } + if(isTitle) { + liDisabled.find('.title').text(item.title).css({ + 'color': '#F66', + 'font-weight': '700' + }); + + // 失效视频 搜索视频 + liDisabled.find('a:eq(1),.meta-mask,a.disabled').HKM([ + { + 'key': 83, + 'title': '搜索标题', + 'position': 'first', + 'action': function() { + window.open('https://www.baidu.com/s?wd=' + item.title); + void(0); + } } - } - ]); - } - if(isCode && json.code === -404) { - liDisabled.find('.title').text('缓存失效').css({ - 'color': '#F66', - 'font-weight': '700' - }); - } - if(isPic || isTitle || (isCode && json.code !== -503)) { - setTimeout(function() { - liDisabled.find('.BtoolsVivLoadding,.BtoolsVivLoaddingBG').remove(); - }, 1000); - liDisabled.addClass('BtoolsVivFinded'); + ]); + } + + if(isCode && item.code === -404) { + liDisabled.find('.title').text('缓存失效').css({ + 'color': '#F66', + 'font-weight': '700' + }); + } + + if(isPic || isTitle || (isCode && item.code !== -503)) { + setTimeout(function() { + liDisabled.find('.BtoolsVivLoadding,.BtoolsVivLoaddingBG').remove(); + }, 1000); + liDisabled.addClass('BtoolsVivFinded'); + + } // 添加到插件本地存储 - addLocalCache(video.id, { - title: isTitle ? json.title : '缓存失效', - pic: isPic ? json.pic : '' + addLocalCache(expiredItem, { + title: isTitle ? item.title : '缓存失效', + pic: isPic ? item.pic : '' }); - VivSet.expiredIndex++; - } - if(VivSet.expiredIndex == $('.fav-video-list li.disabled').length) { + if(VivSet.expiredIndex == $('.fav-video-list li.disabled').length) { + + } + }); + }); + - clearInterval(VivSet.expiredTimer); - VivSet.expiredTimer = null; - } - } - }); - }, 2000); } } diff --git a/manifest.json b/manifest.json index 5d84979..c2963bd 100644 --- a/manifest.json +++ b/manifest.json @@ -79,6 +79,7 @@ "permissions": [ "notifications", + "cookies", "storage", "tabs", "http://*/*", diff --git a/manifest_chrome.json b/manifest_chrome.json index 2ba89c2..30c02ef 100644 --- a/manifest_chrome.json +++ b/manifest_chrome.json @@ -81,6 +81,7 @@ [ "declarativeContent", "notifications", + "cookies", "storage", "tabs", "http://*/*",