Custom bilishare

B站(bilibili)大会员共享

  1. // ==UserScript==
  2. // @name Custom bilishare
  3. // @namespace https://github.com/invobzvr
  4. // @version 0.4
  5. // @description B站(bilibili)大会员共享
  6. // @author invobzvr
  7. // @match *://www.bilibili.com/bangumi/play/*
  8. // @grant unsafeWindow
  9. // @grant GM_deleteValue
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @license GPL-3.0
  13. // @homepageURL https://github.com/invobzvr/invotoys.js/tree/main/bilishare
  14. // @supportURL https://github.com/invobzvr/invotoys.js/issues
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. const ORI_XHRO = XMLHttpRequest.prototype.open;
  19.  
  20. XMLHttpRequest.prototype.open = function () {
  21. let url = arguments[1],
  22. idx = url.indexOf('api.bilibili.com/pgc/player/web/playurl');
  23. if (idx !== -1 && idx < 9 && access_key) {
  24. url.startsWith('//') && (url = url.replace('//', 'https://'));
  25. url = new URL(url);
  26. url.searchParams.append('access_key', access_key);
  27. arguments[1] = url;
  28. this.addEventListener('readystatechange', () => {
  29. if (this.readyState !== 4) {
  30. return;
  31. }
  32. let ret = JSON.parse(this.responseText);
  33. if (ret.code === -10403) {
  34. GM_deleteValue('access_key');
  35. alert('"access_key" may have expired');
  36. }
  37. });
  38. };
  39. return ORI_XHRO.apply(this, arguments);
  40. }
  41.  
  42. function proxyIV() {
  43. let userState;
  44. return new Promise(resolve => {
  45. let iid = setInterval(() => {
  46. if (typeof __INITIAL_STATE__.userState.vipInfo.isVip !== 'undefined') {
  47. clearInterval(iid);
  48. userState = Object.assign({}, __INITIAL_STATE__.userState);
  49. Object.defineProperty(userState.vipInfo, 'isVip', { value: true });
  50. Object.defineProperty(__INITIAL_STATE__, 'userState', { value: userState });
  51. resolve();
  52. }
  53. }, 100);
  54. });
  55. }
  56.  
  57. async function init() {
  58. await proxyIV();
  59. let ep_id = __INITIAL_STATE__.epInfo.id;
  60. bangumiCallNext(`${ep_id}.`);
  61. let iid = setInterval(() => (location.pathname.endsWith('.') && (clearInterval(iid), bangumiCallNext(ep_id))), 100);
  62. }
  63.  
  64. let access_key = GM_getValue('access_key');
  65. access_key && init();
  66. addEventListener('contextmenu', evt => {
  67. if (!evt.target.classList.contains('btn-pay')) {
  68. return;
  69. }
  70. evt.preventDefault();
  71. let val = prompt('Input "access_key":', access_key);
  72. if (!val) {
  73. return;
  74. } else if (val === 'delete') {
  75. GM_deleteValue('access_key');
  76. console.log('[access_key] deleted');
  77. } else if (val.length === 32) {
  78. GM_setValue('access_key', val);
  79. access_key = val;
  80. init();
  81. console.log('[access_key] setted');
  82. } else {
  83. alert('Invalid "access_key"');
  84. }
  85. });
  86. Object.defineProperty(unsafeWindow, 'access_key', {
  87. get: () => access_key,
  88. set: val => {
  89. if (val) {
  90. GM_setValue('access_key', val);
  91. let lak = !access_key;
  92. access_key = val;
  93. lak && init();
  94. console.log('[access_key] setted');
  95. } else {
  96. GM_deleteValue('access_key');
  97. console.log('[access_key] deleted');
  98. }
  99. }
  100. });
  101. })();

QingJ © 2025

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