Created
April 6, 2025 03:51
-
-
Save at-wr/87fff916671291fd3ab65c135d59a8e6 to your computer and use it in GitHub Desktop.
activeVideoLinks for Bilibili Evolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["utils/active-video-links"]=t():e["utils/active-video-links"]=t()}(globalThis,(()=>(()=>{var e,t,o={642:e=>{function t(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}t.keys=()=>[],t.resolve=t,t.id=642,e.exports=t},401:e=>{"use strict";e.exports="这个组件会将视频简介中的普通网址转换为可点击的链接,并将<del>被 Bilibili 抛弃</del>已失效的 `acg.tv` 跳转链接修复为 `nicovideo.jp` 链接。\n\n例如: `https://acg.tv/sm37507315` → `https://www.nicovideo.jp/watch/sm37507315`\n\n<i>本组件不会保证目标链接的安全性,因此在点击前请自行验证其是否可信</i>\n"}},n={};function r(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={exports:{}};return o[e](i,i.exports,r),i.exports}t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,r.t=function(o,n){if(1&n&&(o=this(o)),8&n)return o;if("object"==typeof o&&o){if(4&n&&o.__esModule)return o;if(16&n&&"function"==typeof o.then)return o}var i=Object.create(null);r.r(i);var s={};e=e||[null,t({}),t([]),t(t)];for(var c=2&n&&o;"object"==typeof c&&!~e.indexOf(c);c=t(c))Object.getOwnPropertyNames(c).forEach((e=>s[e]=()=>o[e]));return s.default=()=>o,r.d(i,s),i},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{"use strict";r.d(i,{component:()=>u});const e=coreApis.componentApis.define,t=coreApis.utils.log,o=coreApis.utils.urls,n=(0,t.useScopedConsole)("activeVideoLinks");let s=null;const c=/(?<!(\>|'|"|\/))(http:\/\/|https:\/\/|www\.)[^(\s,;())]+/g,a=(e,t)=>{const o=e.substring(0,t),n=o.lastIndexOf("<a ");if(-1===n)return!1;return n>o.lastIndexOf("</a>")},l=()=>{try{document.querySelectorAll('a[href*="acg.tv"][href*="sm"]').forEach((e=>{const t=e.getAttribute("href");if(t){const o=t.replace("acg.tv","nicovideo.jp/watch");e.setAttribute("href",o),n.log(`Niconico Fix: ${t} → ${o}`)}})),(()=>{const e=document.querySelector(".desc-info-text");if(!e)return;const t=e.innerHTML;let o=t;const n=[...t.matchAll(c)];for(let e=n.length-1;e>=0;e--){const r=n[e],i=r[0],s=r.index??0;if(a(t,s))continue;const c=`<a href='${i.startsWith("www.")?`//${i}`:i.replace(/^https?:/,"")}' target='_blank'>${i}</a>`;o=o.substring(0,s)+c+o.substring(s+i.length)}o!==t&&(e.innerHTML=o)})()}catch(e){n.error("处理链接时遇到 Error:",e)}},d=()=>{n.log("视频链接增强已启用"),l(),s&&s.disconnect(),s=new MutationObserver(l),s.observe(document.documentElement,{childList:!0,subtree:!0}),n.log("已设置 Observer")},u=(0,e.defineComponentMetadata)({name:"activeVideoLinks",displayName:"视频链接增强",description:{"zh-CN":"将视频简介中的普通网址转换为可点击的链接,同时修复 acg.tv 链接"},tags:[componentsTags.utils],entry:d,reload:d,unload:()=>{s&&(s.disconnect(),s=null)},urlInclude:o.videoUrls,author:{name:"Alan Ye",link:"https://github.com/at-wr"},commitHash:"6afdbff8a0511f11d5645e3091e3b9daf33fb488",coreVersion:"2.10.0",description:(()=>{const e=r(642);return{...Object.fromEntries(e.keys().map((t=>[t.match(/index\.(.+)\.md$/)[1],e(t)]))),"zh-CN":()=>Promise.resolve().then(r.t.bind(r,401,17)).then((e=>e.default))}})()})})(),i=i.component})())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment