mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
6.1 KiB
JavaScript
1 line
6.1 KiB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["utils/download-emoticons"]=e():t["utils/download-emoticons"]=e()}(globalThis,(()=>(()=>{var t,e,o={460:(t,e,o)=>{"use strict";o.r(e),o.d(e,{default:()=>m});var n=function(){var t=this,e=t._self._c;t._self._setupProxy;return e("DefaultWidget",{attrs:{disabled:t.downloading,name:"下载up主表情包",icon:"mdi-emoticon-outline"},on:{click:function(e){return t.download()}}})};n._withStripped=!0;const r=coreApis.ui,i=coreApis.utils.log,s=coreApis.ajax;function a(t,e,o){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var n=o.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}const c=(0,i.useScopedConsole)("表情包下载");const l=coreApis.download,d=coreApis.toast,u=new class{constructor(){a(this,"apiRequest",(t=>{const e={url:t,method:"GET",responseType:"json"};return(0,s.monkey)(e)})),a(this,"getImageBlob",(async t=>{const e={url:t,method:"GET",responseType:"blob"};return(0,s.monkey)(e)}))}async getEmoticonsByRoomId(t){return await this.apiRequest(`https://api.live.bilibili.com/xlive/web-ucenter/v2/emoticon/GetEmoticons?platform=pc&room_id=${t}`)}async downloadEmoticons(t){return t.map((t=>({emoticons:t.emoticons.map((t=>{try{const e=this.getImageBlob(t.url);return{emoji:t.emoji,blob:e}}catch(e){return c.error(`下载表情 ${t.emoji} 失败:`,e),null}})),pkg_name:t.pkg_name})))}async getEmoticonsArray(t){try{let e=await this.getEmoticonsByRoomId(t);if(0===e.data.data.length){c.log("获取表情包失败,尝试获取真实roomId");const o=await this.getRealRoomId(t);e=await this.getEmoticonsByRoomId(o)}return e.data.data.slice(2)}catch(t){throw new Error("获取表情包失败")}}async batchDownload(t){const e=[];for(const o of t){const t=(async()=>{const t=[],e=o.emoticons.map((t=>t.blob));for(const o of e){const e=await o;t.push(e)}return{pkg_name:o.pkg_name,emoticons:o.emoticons.map(((e,o)=>({emoji:e.emoji,blob:t[o]})))}})();e.push(t)}return Promise.all(e)}async getRealRoomId(t){try{const e=await this.apiRequest(`https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${t}`);if(0===Object.keys(e.data).length)throw new Error("获取直播间id失败");return e.data.room_id}catch(t){throw new Error("获取直播间id失败")}}};var p=function(t,e,o,n,r,i,s,a){var c,l="function"==typeof t?t.options:t;if(e&&(l.render=e,l.staticRenderFns=o,l._compiled=!0),n&&(l.functional=!0),i&&(l._scopeId="data-v-"+i),s?(c=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),r&&r.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(s)},l._ssrRegister=c):r&&(c=a?function(){r.call(this,(l.functional?this.parent:this).$root.$options.shadowRoot)}:r),c)if(l.functional){l._injectStyles=c;var d=l.render;l.render=function(t,e){return c.call(e),d(t,e)}}else{var u=l.beforeCreate;l.beforeCreate=u?[].concat(u,c):[c]}return{exports:t,options:l}}(Vue.extend({components:{DefaultWidget:r.DefaultWidget},data:()=>({downloading:!1,roomIdRegex:/^https:\/\/live\.bilibili\.com\/(?:blanc\/)?(\d+)(?:\?\.*?)?$/}),methods:{async download(){this.downloading=!0;try{const t=window.location.href;if(t.startsWith("https://live.bilibili.com/")){const e=this.roomIdRegex.exec(t)[1],o=await u.getEmoticonsArray(e);if(0===o.length)return void d.Toast.info("该up主没有专属表情包","表情包下载");const n=await u.downloadEmoticons(o),r=await u.batchDownload(n),i=new l.DownloadPackage;i.noEscape=!0;for(const t of r)if(null!==t)for(const e of t.emoticons)i.add(`${t.pkg_name}/${e.emoji}.png`,e.blob);await i.emit(`emoticons-${e}.zip`)}}catch(t){d.Toast.error("下载失败详情查看控制台","表情包下载"),(0,i.logError)(t)}finally{this.downloading=!1}}}}),n,[],!1,null,null,null);const m=p.exports},726:t=>{function e(t){var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e}e.keys=()=>[],e.resolve=e,e.id=726,t.exports=e},701:t=>{"use strict";t.exports="## 下载up主专属表情包\n\n支持下载up主专属表情包,处于任意直播间页面时,下载按钮会在`功能`面板显示,以压缩包形式保存。"}},n={};function r(t){var e=n[t];if(void 0!==e)return e.exports;var i=n[t]={exports:{}};return o[t](i,i.exports,r),i.exports}e=Object.getPrototypeOf?t=>Object.getPrototypeOf(t):t=>t.__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={};t=t||[null,e({}),e([]),e(e)];for(var a=2&n&&o;"object"==typeof a&&!~t.indexOf(a);a=e(a))Object.getOwnPropertyNames(a).forEach((t=>s[t]=()=>o[t]));return s.default=()=>o,r.d(i,s),i},r.d=(t,e)=>{for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{"use strict";r.d(i,{component:()=>o});const t=coreApis.componentApis.define,e=coreApis.utils.urls,o=(0,t.defineComponentMetadata)({name:"downloadEmoticons",displayName:"下载表情",tags:[componentsTags.utils,componentsTags.live],entry:none,author:{name:"Pencilqaq",link:"https://github.com/pencilqaq"},widget:{component:()=>Promise.resolve().then(r.bind(r,460)).then((t=>t.default))},urlInclude:e.liveUrls,commitHash:"6f513d77b2ea5ebb8dcc0962e857ffb9a8b32934",coreVersion:"2.10.4",description:(()=>{const t=r(726);return{...Object.fromEntries(t.keys().map((e=>[e.match(/index\.(.+)\.md$/)[1],t(e)]))),"zh-CN":()=>Promise.resolve().then(r.t.bind(r,701,17)).then((t=>t.default))}})()})})(),i=i.component})())); |