Fix biliplus redirect url (#2322)

This commit is contained in:
the1812 2021-11-14 22:08:55 +08:00
parent ca4b1b2975
commit fba53a0485
2 changed files with 45 additions and 21 deletions

View File

@ -1 +1 @@
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["video/biliplus-redirect"]=t():e["video/biliplus-redirect"]=t()}(self,(function(){return function(){"use strict";var e={592:function(e,t,n){n.r(t),n.d(t,{default:function(){return l}});var o=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("a",{attrs:{href:e.url,target:"_blank",tabindex:"-1"}},[n("DefaultWidget",{attrs:{name:"转到BiliPlus",icon:"biliplus",disabled:!e.url}})],1)};o._withStripped=!0;var i=coreApis.observer,r=coreApis.ui;var s=function(e,t,n,o,i,r,s,l){var c,a="function"==typeof e?e.options:e;if(t&&(a.render=t,a.staticRenderFns=n,a._compiled=!0),o&&(a.functional=!0),r&&(a._scopeId="data-v-"+r),s?(c=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),i&&i.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(s)},a._ssrRegister=c):i&&(c=l?function(){i.call(this,(a.functional?this.parent:this).$root.$options.shadowRoot)}:i),c)if(a.functional){a._injectStyles=c;var u=a.render;a.render=function(e,t){return c.call(t),u(e,t)}}else{var d=a.beforeCreate;a.beforeCreate=d?[].concat(d,c):[c]}return{exports:e,options:a}}(Vue.extend({components:{DefaultWidget:r.DefaultWidget},data:()=>({url:""}),created(){const e="www.biliplus.com",t=/\/video\/(av[\d]+|BV.+)/i;if("space.bilibili.com"===window.location.host)this.url=document.URL.replace("space.bilibili.com/",`${e}/space/`);else if(document.URL.includes("/bangumi/play"))this.url=`https://${e}${window.location.pathname}${window.location.search}`,(0,i.videoChange)((()=>{const t=unsafeWindow.aid||document.querySelector(".av-link,.info-sec-av").innerText.replace(/[aAvV]/g,""),n=`https://${e}/video/av${t}/`;document.URL!==n?this.href=n:this.href=""}));else if(t.test(document.URL)){const[,n]=document.URL.match(t);this.url=`https://${e}/video/${n}/`}else(0,i.videoChange)((()=>{this.url=document.URL.replace(window.location.host,e)}))}}),o,[],!1,null,null,null);s.options.__file="registry/lib/components/video/biliplus-redirect/BiliplusRedirect.vue";var l=s.exports}},t={};function n(o){var i=t[o];if(void 0!==i)return i.exports;var r=t[o]={exports:{}};return e[o](r,r.exports,n),r.exports}n.d=function(e,t){for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return function(){n.d(o,{component:function(){return e}});const e={name:"biliplusRedirect",displayName:"BiliPlus跳转支持",description:{"zh-CN":"在视频/番剧/空间中, 可以从功能中的按钮点击转到BiliPlus上对应的页面."},urlInclude:[...coreApis.utils.urls.videoAndBangumiUrls,"//space.bilibili.com"],entry:none,tags:[componentsTags.video,componentsTags.utils],widget:{component:()=>Promise.resolve().then(n.bind(n,592)).then((e=>e.default))}}}(),o=o.component}()}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["video/biliplus-redirect"]=t():e["video/biliplus-redirect"]=t()}(self,(function(){return function(){"use strict";var e={183:function(e,t,o){o.r(t),o.d(t,{default:function(){return a}});var n=function(){var e=this,t=e.$createElement,o=e._self._c||t;return o("a",{attrs:{href:e.url,target:"_blank",tabindex:"-1"}},[o("DefaultWidget",{attrs:{name:"转到BiliPlus",icon:"biliplus",disabled:!e.url}})],1)};n._withStripped=!0;var i=coreApis.observer,r=coreApis.ui;const l=/\/(video|medialist\/play)\/([^\/]+\/)?(av[\d]+|BV.+)/i,s=[{condition:()=>"space.bilibili.com"===window.location.host,getUrl:e=>document.URL.replace("space.bilibili.com/",`${e}/space/`)},{condition:()=>"space.bilibili.com"===window.location.host,getUrl:e=>document.URL.replace("space.bilibili.com/",`${e}/space/`)},{condition:()=>document.URL.includes("/bangumi/play"),getUrl:(e,t)=>((0,i.videoChange)((()=>{const o=unsafeWindow.aid||document.querySelector(".av-link,.info-sec-av").innerText.replace(/[aAvV]/g,""),n=`https://${e}/video/av${o}/`;document.URL!==n?t(n):t("")})),`https://${e}${window.location.pathname}${window.location.search}`)},{condition:()=>l.test(document.URL),getUrl:e=>`https://${e}/video/${document.URL.match(l)[3]}/`}];var c=function(e,t,o,n,i,r,l,s){var c,a="function"==typeof e?e.options:e;if(t&&(a.render=t,a.staticRenderFns=o,a._compiled=!0),n&&(a.functional=!0),r&&(a._scopeId="data-v-"+r),l?(c=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),i&&i.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(l)},a._ssrRegister=c):i&&(c=s?function(){i.call(this,(a.functional?this.parent:this).$root.$options.shadowRoot)}:i),c)if(a.functional){a._injectStyles=c;var d=a.render;a.render=function(e,t){return c.call(t),d(e,t)}}else{var u=a.beforeCreate;a.beforeCreate=u?[].concat(u,c):[c]}return{exports:e,options:a}}(Vue.extend({components:{DefaultWidget:r.DefaultWidget},data:()=>({url:""}),created(){const e="www.biliplus.com",t=e=>this.url=e,o=s.find((e=>e.condition()));o?t(o.getUrl(e,t)):(0,i.videoChange)((()=>{this.url=document.URL.replace(window.location.host,e)}))}}),n,[],!1,null,null,null);c.options.__file="registry/lib/components/video/biliplus-redirect/BiliplusRedirect.vue";var a=c.exports}},t={};function o(n){var i=t[n];if(void 0!==i)return i.exports;var r=t[n]={exports:{}};return e[n](r,r.exports,o),r.exports}o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return function(){o.d(n,{component:function(){return e}});const e={name:"biliplusRedirect",displayName:"BiliPlus跳转支持",description:{"zh-CN":"在视频/番剧/空间中, 可以从功能中的按钮点击转到BiliPlus上对应的页面."},urlInclude:[...coreApis.utils.urls.videoAndBangumiUrls,"//space.bilibili.com"],entry:none,tags:[componentsTags.video,componentsTags.utils],widget:{component:()=>Promise.resolve().then(o.bind(o,183)).then((e=>e.default))}}}(),n=n.component}()}));

View File

@ -8,6 +8,46 @@
import { videoChange } from '@/core/observer'
import { DefaultWidget } from '@/ui'
const videoRegex = /\/(video|medialist\/play)\/([^\/]+\/)?(av[\d]+|BV.+)/i
interface BiliplusRedirectProvider {
condition: () => boolean
getUrl: (host: string, updateUrl: (url: string) => void) => string
}
const redirectProviders: BiliplusRedirectProvider[] = [
{
condition: () => window.location.host === 'space.bilibili.com',
getUrl: host => document.URL.replace('space.bilibili.com/', `${host}/space/`),
},
{
condition: () => window.location.host === 'space.bilibili.com',
getUrl: host => document.URL.replace('space.bilibili.com/', `${host}/space/`),
},
{
condition: () => document.URL.includes('/bangumi/play'),
getUrl: (host, updateUrl) => {
videoChange(() => {
const aid = unsafeWindow.aid || (() => {
const link = document.querySelector('.av-link,.info-sec-av') as HTMLElement
return link.innerText.replace(/[aAvV]/g, '')
})()
const url = `https://${host}/video/av${aid}/`
if (document.URL !== url) {
updateUrl(url)
} else {
updateUrl('')
}
})
return `https://${host}${window.location.pathname}${window.location.search}`
},
},
{
condition: () => videoRegex.test(document.URL),
getUrl: host => {
const id = document.URL.match(videoRegex)[3]
return `https://${host}/video/${id}/`
},
},
]
export default Vue.extend({
components: {
DefaultWidget,
@ -19,26 +59,10 @@ export default Vue.extend({
},
created() {
const host = 'www.biliplus.com'
const videoRegex = /\/video\/(av[\d]+|BV.+)/i
if (window.location.host === 'space.bilibili.com') {
this.url = document.URL.replace('space.bilibili.com/', `${host}/space/`)
} else if (document.URL.includes('/bangumi/play')) {
this.url = `https://${host}${window.location.pathname}${window.location.search}`
videoChange(() => {
const aid = unsafeWindow.aid || (() => {
const link = document.querySelector('.av-link,.info-sec-av') as HTMLElement
return link.innerText.replace(/[aAvV]/g, '')
})()
const url = `https://${host}/video/av${aid}/`
if (document.URL !== url) {
this.href = url
} else {
this.href = ''
}
})
} else if (videoRegex.test(document.URL)) {
const [, id] = document.URL.match(videoRegex)
this.url = `https://${host}/video/${id}/`
const updateUrl = (url: string) => (this.url = url)
const provider = redirectProviders.find(p => p.condition())
if (provider) {
updateUrl(provider.getUrl(host, updateUrl))
} else {
videoChange(() => {
this.url = document.URL.replace(window.location.host, host)