bilibili 同时显示 av 号和 bv 号 (本地)

同时显示视频的 bv 号和 av 号

目前为 2020-03-23 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name bilibili 同时显示 av 号和 bv 号 (本地)
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description 同时显示视频的 bv 号和 av 号
  6. // @author acdzh
  7. // @match *://www.bilibili.com/video/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Your code here...
  15. function convertNewUrl() {
  16. let tables = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'.split('');
  17. let tr = {};
  18. tables.forEach((t, i) => {tr[t] = i});
  19.  
  20. let s = [11, 10, 3, 8, 4, 6, 2, 9, 5, 7];
  21. let xorNum = 177451812n;
  22. let addNum = 100618342136696320n;
  23.  
  24. let bvToAv = bv => {
  25. let r = 0n;
  26. s.forEach((n, i) => { r += BigInt(tr[bv[n]]) * BigInt(58 ** i);})
  27. return `av${(r - addNum) ^ xorNum}`;
  28. }
  29.  
  30. let aidToBv = aid => {
  31. let x = (BigInt(aid) ^ xorNum) + addNum;
  32. let r = ['B', 'V', ...new Array(8)];
  33. s.forEach((n, i) => { r[n] = tables[x / BigInt(58 ** i) % 58n];});
  34. return r.join('')
  35. }
  36.  
  37. let urlParts = location.href.split('/');
  38. if(urlParts[3] !== 'video') return '';
  39. let beforeParam = location.href.split('?')[1] || '';
  40.  
  41. let v = urlParts[4].split('?')[0];
  42. if (v[0] === 'B' || v[0] === 'b') {
  43. return `/video/${v}?${beforeParam}${beforeParam ? '&' : ''}` + (beforeParam.indexOf('aid') === -1 ? `aid=${bvToAv(v)}` : 'fuck');
  44. } else {
  45. return `/video/${aidToBv(parseInt(v.slice(2,100)))}?${beforeParam}${beforeParam ? '&' : ''}` + (beforeParam.indexOf('aid') === -1 ? `aid=${v}` : '');
  46. }
  47. }
  48.  
  49. history.replaceState({}, document.title, convertNewUrl());
  50.  
  51. /*
  52. (function(history){
  53. var pushState = history.pushState;
  54. history.pushState = function(state) {
  55. if (typeof history.onpushstate == "function") {
  56. history.onpushstate({state: state});
  57. }
  58. // ... whatever else you want to do
  59. // maybe call onhashchange e.handler
  60. return pushState.apply(history, arguments);
  61. };
  62. })(window.history);
  63.  
  64. history.onpushstate = function(e) {
  65. history.replaceState({}, document.title, convertNewUrl());
  66. }
  67. */
  68.  
  69. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址