mirror of
https://github.com/bolucat/Archive.git
synced 2026-04-23 00:17:16 +08:00
12 lines
14 KiB
JavaScript
12 lines
14 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["style/replace-cover"]=t():e["style/replace-cover"]=t()}(globalThis,(()=>(()=>{var e,t,r={327:(e,t,r)=>{var n=r(904),o=r(955)(n);o.push([e.id,'@charset "UTF-8";\n.bili-video-card .bili-video-card__image--wrap {\n position: relative;\n}\n\n.bili-video-card .bili-video-card__image--wrap picture {\n visibility: hidden !important;\n}\n\n.bili-video-card .bili-video-card__image--wrap .custom-preview-img {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n object-fit: cover;\n z-index: 2;\n opacity: 0;\n transition: opacity 0.3s ease;\n border-radius: inherit;\n /* 继承父元素的圆角 */\n}\n\n.bili-video-card .bili-video-card__image--wrap .custom-preview-img.loaded {\n opacity: 1;\n}\n\n/* 鼠标悬停时隐藏自定义预览图,显示原始图片 */\n.bili-video-card .bili-video-card__image--wrap:hover .custom-preview-img.loaded {\n opacity: 0;\n}\n\n.bili-video-card .bili-video-card__image--wrap:hover picture {\n visibility: visible !important;\n}\n\n/* 可选: 添加占位符背景色或加载动画 */\n.bili-video-card .bili-video-card__image--wrap .custom-preview-img:not(.loaded) {\n background-color: #f0f0f0;\n}',"",{version:3,sources:["webpack://./registry/lib/components/style/replace-cover/index.scss"],names:[],mappings:"AAAA,gBAAgB;AAChB;EACE,kBAAkB;AACpB;;AAEA;EACE,6BAA6B;AAC/B;;AAEA;EACE,kBAAkB;EAClB,MAAM;EACN,OAAO;EACP,WAAW;EACX,YAAY;EACZ,iBAAiB;EACjB,UAAU;EACV,UAAU;EACV,6BAA6B;EAC7B,sBAAsB;EACtB,aAAa;AACf;;AAEA;EACE,UAAU;AACZ;;AAEA,yBAAyB;AACzB;EACE,UAAU;AACZ;;AAEA;EACE,8BAA8B;AAChC;;AAEA,sBAAsB;AACtB;EACE,yBAAyB;AAC3B",sourcesContent:['@charset "UTF-8";\n.bili-video-card .bili-video-card__image--wrap {\n position: relative;\n}\n\n.bili-video-card .bili-video-card__image--wrap picture {\n visibility: hidden !important;\n}\n\n.bili-video-card .bili-video-card__image--wrap .custom-preview-img {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n object-fit: cover;\n z-index: 2;\n opacity: 0;\n transition: opacity 0.3s ease;\n border-radius: inherit;\n /* 继承父元素的圆角 */\n}\n\n.bili-video-card .bili-video-card__image--wrap .custom-preview-img.loaded {\n opacity: 1;\n}\n\n/* 鼠标悬停时隐藏自定义预览图,显示原始图片 */\n.bili-video-card .bili-video-card__image--wrap:hover .custom-preview-img.loaded {\n opacity: 0;\n}\n\n.bili-video-card .bili-video-card__image--wrap:hover picture {\n visibility: visible !important;\n}\n\n/* 可选: 添加占位符背景色或加载动画 */\n.bili-video-card .bili-video-card__image--wrap .custom-preview-img:not(.loaded) {\n background-color: #f0f0f0;\n}'],sourceRoot:""}]),e.exports=o},955:e=>{"use strict";
|
|
// eslint-disable-next-line func-names
|
|
e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var r=e(t);return t[2]?"@media ".concat(t[2]," {").concat(r,"}"):r})).join("")},
|
|
// eslint-disable-next-line func-names
|
|
t.i=function(e,r,n){"string"==typeof e&&(
|
|
// eslint-disable-next-line no-param-reassign
|
|
e=[[null,e,""]]);var o={};if(n)for(var i=0;i<this.length;i++){
|
|
// eslint-disable-next-line prefer-destructuring
|
|
var a=this[i][0];null!=a&&(o[a]=!0)}for(var c=0;c<e.length;c++){var s=[].concat(e[c]);n&&o[s[0]]||(r&&(s[2]?s[2]="".concat(r," and ").concat(s[2]):s[2]=r),t.push(s))}},t}},904:e=>{"use strict";function t(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==r)return;var n,o,i=[],a=!0,c=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){c=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(c)throw o}}return i}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return r(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}e.exports=function(e){var r=t(e,4),n=r[1],o=r[3];if(!o)return n;if("function"==typeof btoa){
|
|
// eslint-disable-next-line no-undef
|
|
var i=btoa(unescape(encodeURIComponent(JSON.stringify(o)))),a="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(i),c="/*# ".concat(a," */"),s=o.sources.map((function(e){return"/*# sourceURL=".concat(o.sourceRoot||"").concat(e," */")}));return[n].concat(s).concat([c]).join("\n")}return[n].join("\n")}},73:(e,t,r)=>{var n=r(453).Symbol;e.exports=n},624:(e,t,r)=>{var n=r(73),o=r(915),i=r(478),a=n?n.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":a&&a in Object(e)?o(e):i(e)}},480:(e,t,r)=>{var n=r(976),o=/^\s+/;e.exports=function(e){return e?e.slice(0,n(e)+1).replace(o,""):e}},928:(e,t,r)=>{var n="object"==typeof r.g&&r.g&&r.g.Object===Object&&r.g;e.exports=n},915:(e,t,r)=>{var n=r(73),o=Object.prototype,i=o.hasOwnProperty,a=o.toString,c=n?n.toStringTag:void 0;e.exports=function(e){var t=i.call(e,c),r=e[c];try{e[c]=void 0;var n=!0}catch(e){}var o=a.call(e);return n&&(t?e[c]=r:delete e[c]),o}},478:e=>{var t=Object.prototype.toString;e.exports=function(e){return t.call(e)}},453:(e,t,r)=>{var n=r(928),o="object"==typeof self&&self&&self.Object===Object&&self,i=n||o||Function("return this")();e.exports=i},976:e=>{var t=/\s/;e.exports=function(e){for(var r=e.length;r--&&t.test(e.charAt(r)););return r}},645:(e,t,r)=>{var n=r(717),o=r(884),i=r(86),a=Math.max,c=Math.min;e.exports=function(e,t,r){var s,l,u,d,f,p,v=0,m=!1,g=!1,y=!0;if("function"!=typeof e)throw new TypeError("Expected a function");function b(t){var r=s,n=l;return s=l=void 0,v=t,d=e.apply(n,r)}function A(e){var r=e-p;return void 0===p||r>=t||r<0||g&&e-v>=u}function h(){var e=o();if(A(e))return w(e);f=setTimeout(h,function(e){var r=t-(e-p);return g?c(r,u-(e-v)):r}(e))}function w(e){return f=void 0,y&&s?b(e):(s=l=void 0,d)}function _(){var e=o(),r=A(e);if(s=arguments,l=this,p=e,r){if(void 0===f)return function(e){return v=e,f=setTimeout(h,t),m?b(e):d}(p);if(g)return clearTimeout(f),f=setTimeout(h,t),b(p)}return void 0===f&&(f=setTimeout(h,t)),d}return t=i(t)||0,n(r)&&(m=!!r.leading,u=(g="maxWait"in r)?a(i(r.maxWait)||0,t):u,y="trailing"in r?!!r.trailing:y),_.cancel=function(){void 0!==f&&clearTimeout(f),v=0,s=p=l=f=void 0},_.flush=function(){return void 0===f?d:w(o())},_}},717:e=>{e.exports=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}},50:e=>{e.exports=function(e){return null!=e&&"object"==typeof e}},770:(e,t,r)=>{var n=r(624),o=r(50);e.exports=function(e){return"symbol"==typeof e||o(e)&&"[object Symbol]"==n(e)}},884:(e,t,r)=>{var n=r(453);e.exports=function(){return n.Date.now()}},462:(e,t,r)=>{var n=r(645),o=r(717);e.exports=function(e,t,r){var i=!0,a=!0;if("function"!=typeof e)throw new TypeError("Expected a function");return o(r)&&(i="leading"in r?!!r.leading:i,a="trailing"in r?!!r.trailing:a),n(e,t,{leading:i,maxWait:t,trailing:a})}},86:(e,t,r)=>{var n=r(480),o=r(717),i=r(770),a=/^[-+]0x[0-9a-f]+$/i,c=/^0b[01]+$/i,s=/^0o[0-7]+$/i,l=parseInt;e.exports=function(e){if("number"==typeof e)return e;if(i(e))return NaN;if(o(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=o(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=n(e);var r=c.test(e);return r||s.test(e)?l(e.slice(2),r?2:8):a.test(e)?NaN:+e}},585:(e,t,r)=>{var n=r(327);n&&n.__esModule&&(n=n.default),e.exports="string"==typeof n?n:n.toString()}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={id:e,exports:{}};return r[e](i,i.exports,o),i.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,o.t=function(r,n){if(1&n&&(r=this(r)),8&n)return r;if("object"==typeof r&&r){if(4&n&&r.__esModule)return r;if(16&n&&"function"==typeof r.then)return r}var i=Object.create(null);o.r(i);var a={};e=e||[null,t({}),t([]),t(t)];for(var c=2&n&&r;"object"==typeof c&&!~e.indexOf(c);c=t(c))Object.getOwnPropertyNames(c).forEach((e=>a[e]=()=>r[e]));return a.default=()=>r,o.d(i,a),i},o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.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";o.d(i,{component:()=>f});var e=o(462),t=o.n(e);const r=coreApis.componentApis.define,n=coreApis.componentApis.styledComponent,a=new Map;let c=0;const s=[];async function l(e){const t=e.querySelector("a.bili-video-card__image--link");if(!t)return;const r=t.getAttribute("href"),n=r?.match(/\/video\/(BV[\w]+)/);if(!n)return;const o=n[1],i=t.querySelector(".bili-video-card__image--wrap");if(!i||i.querySelector(".custom-preview-img"))return;const l=i.querySelector("picture img");if(!l)return;const u=document.createElement("img");u.className="custom-preview-img",l.alt&&(u.alt=l.alt),l.style.aspectRatio&&(u.style.aspectRatio=l.style.aspectRatio),i.appendChild(u),await async function(e){if(c>=15)await new Promise((t=>{s.push((async()=>{await e(),t()}))}));else{c+=1;try{await e()}finally{if(c-=1,s.length>0){const e=s.shift();e?.()}}}}((async()=>{try{const e=await async function(e){const t=a.get(e);if(t)return t;try{const t=new URL("https://api.bilibili.com/x/player/videoshot");t.searchParams.set("bvid",e),t.searchParams.set("index","1");let r=await fetch(t.toString());if(412===r.status&&(await new Promise((e=>setTimeout(e,3e4))),r=await fetch(t.toString()),412===r.status))return null;const n=await r.json();if(0!==n.code||!n.data?.image)return null;const{image:o,index:i=[],img_x_len:c,img_y_len:s,img_x_size:l,img_y_size:u}=n.data,d=c*s,f=Array.isArray(i)&&i.length>0?Math.floor((i.length-1)/2):0,p=Math.floor(f/d);if(p>=o.length)return null;const v=f%d,m=v%c,g=Math.floor(v/c),y=m*l,b=g*u,A=l,h=u,w=o[p].startsWith("//")?`https:${o[p]}`:o[p],_=await fetch(w,{mode:"cors"});if(!_.ok)return null;const E=await _.blob();let x;try{x=await createImageBitmap(E,y,b,A,h,{})}catch(t){console.error("[replaceCover] createImageBitmap error:",t);try{const t=await new Promise(((e,t)=>{const r=new Image;r.crossOrigin="anonymous",r.onload=()=>{try{const n=document.createElement("canvas");n.width=A,n.height=h;const o=n.getContext("2d");if(!o)return void t(new Error("Could not get canvas context in fallback."));o.drawImage(r,y,b,A,h,0,0,A,h);const i=n.toDataURL("image/jpeg",.9);e(i)}catch(e){console.error("[replaceCover] canvas error:",e),t(e)}},r.onerror=e=>t(new Error(`Image load error in fallback for ${w}: ${e}`)),r.src=w}));return a.set(e,t),t}catch(e){return console.error("[replaceCover] fallback error:",e),null}}const C=document.createElement("canvas");C.width=l,C.height=u;const j=C.getContext("2d");if(!j)return x.close(),null;j.drawImage(x,0,0),x.close();const B=C.toDataURL("image/jpeg",.9);return a.set(e,B),B}catch(e){return console.error("[replaceCover] Error fetching video preview:",e),null}}(o);if(!e)return void u.remove();await new Promise((t=>{const r=new Image;r.onload=()=>{u.src=e,u.classList.add("loaded"),t()},r.onerror=()=>{u.remove(),t()},r.src=e}))}catch(e){console.error("[replaceCover] Error processing video card:",e),u.remove()}}))}async function u(e){const t=e.filter((e=>e.classList?.contains("bili-video-card")));0!==t.length&&await Promise.allSettled(t.map((e=>l(e))))}function d(e){const t=[];for(const r of e)if("childList"===r.type&&r.addedNodes.length>0)for(const e of Array.from(r.addedNodes))if(e.nodeType===Node.ELEMENT_NODE){const r=e;r.classList?.contains("bili-video-card")&&t.push(r);r.querySelectorAll(".bili-video-card").forEach((e=>t.push(e)))}const r=Array.from(new Set(t));r.length>0&&u(r)}const f=(0,r.defineComponentMetadata)({name:"replaceCover",author:{name:"UcnacDx2",link:"https://github.com/UcnacDx2"},tags:[componentsTags.style],displayName:"替换标题党封面",description:"将视频卡片的封面替换为视频预览帧,杜绝图文不符。致敬DeArrow。",urlInclude:["www.bilibili.com"],entry:(0,n.styledComponentEntry)((()=>Promise.resolve().then(o.t.bind(o,585,23))),(async()=>{const e=["main > .feed2 > .recommended-container_floor-aside > .container","main > .feed2 > .container",".recommended-container_floor-aside > .container",".container.is-adapting",".recommend-page-container .video-card-list","#page-video .tab-list-box .video-card-list","#bili_bangumi_watch .video-card-list",".search-results-video .video-list",".space-video-list"].map((e=>document.querySelector(e))).find((e=>null!==e))??document.body,r=document.querySelectorAll(".bili-video-card");u(Array.from(r));new MutationObserver(d).observe(e,{childList:!0,subtree:!0});const n=t()((()=>{const e=document.querySelectorAll(".bili-video-card");if(0===e.length)return;const t=Array.from(e).filter((e=>{const t=e.querySelector(".bili-video-card__image--wrap");if(!t)return!1;const r=t.querySelector(".custom-preview-img");return!r||!r.src}));t.length>0&&(t.forEach((e=>{const t=e.querySelector(".custom-preview-img");t&&!t.src&&t.remove()})),u(t))}),300);window.addEventListener("resize",n),window.addEventListener("scroll",n)})),commitHash:"67168e9c79449a0e28f1488f4bc7a8972097346a",coreVersion:"2.10.7"})})(),i=i.component})()));
|
|
//# sourceMappingURL=https://raw.githubusercontent.com/the1812/Bilibili-Evolved/master/registry/dist/components/style/replace-cover.js.map
|