Bilibili BV转AV

无缝地将Bilibili的BV号转为av号

  1. // ==UserScript==
  2. // @name Bilibili BV to av
  3. // @name:zh-CN Bilibili BV转AV
  4. // @author net2cn
  5. // @description Convert Bilibili's video BV id back to av id seamlessly.
  6. // @description:zh-CN 无缝地将Bilibili的BV号转为av号
  7. // @description:es ???
  8. // @namespace https://github.com/net2cn
  9. // @license MIT License
  10. // @version 0.0.2
  11. // @include /^https?:\/\/www\.bilibili\.com\/video\/[BbVv]+/
  12. // @mainpage https://github.com/net2cn/Bilibili_BV_to_av
  13. // @grant none
  14. // ==/UserScript==
  15.  
  16. function convert(){
  17. if(window.aid!=undefined) {
  18. // Use regex to match BV id and replace it with the av id. bv is not case sensitive
  19. let av_url = window.location.href.replace(/\/BV(.*)(?=\/)|\/BV(.*)(?=\?)|\/BV(.*)(?=$)/i, "/av"+window.aid)
  20. history.replaceState(null, null, av_url)
  21. }else {
  22. console.log("Unable to find aid for replacement.")
  23. }
  24. }
  25.  
  26. (function() {
  27. 'use strict';
  28. // Add listener to observe if url has changed.
  29. let previousUrl = "";
  30. const observer = new MutationObserver(function(mutations) {
  31. if (location.href !== previousUrl) {
  32. previousUrl = location.href
  33. convert()
  34. }
  35. });
  36. const config = {subtree: true, childList: true};
  37. observer.observe(document, config);
  38.  
  39. // Initial convert.
  40. convert()
  41. })();

QingJ © 2025

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