forked from the1812/Bilibili-Evolved
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quick-favorite.js
12 lines (12 loc) · 15.9 KB
/
quick-favorite.js
1
2
3
4
5
6
7
8
9
10
11
12
!function(A,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["video/quick-favorite"]=t():A["video/quick-favorite"]=t()}(self,(function(){return function(){var A,t,e={708:function(A,t,e){var i=e(645)((function(A){return A[1]}));i.push([A.id,'@charset "UTF-8";\n@font-face {\n font-family: "quick-favorite";\n src: url("data:application/x-font-ttf;base64,AAEAAAALAIAAAwAwR1NVQiCLJXoAAAE4AAAAVE9TLzJAIEqwAAABjAAAAFZjbWFw6ynBrQAAAewAAAFwZ2x5ZnI4GW4AAANkAAABDGhlYWQYiH0gAAAA4AAAADZoaGVhB4sD6wAAALwAAAAkaG10eAPoAAAAAAHkAAAACGxvY2EAhgAAAAADXAAAAAZtYXhwAQ8AZAAAARgAAAAgbmFtZa2yT/oAAARwAAACXnBvc3QnqNOhAAAG0AAAAD0AAQAAA+gAAAAAA+gAAAAAA6IAAQAAAAAAAAAAAAAAAAAAAAIAAQAAAAEAAOxSVapfDzz1AAsD6AAAAADa5Bw+AAAAANrkHD4AAAAAA6IDvwAAAAgAAgAAAAAAAAABAAAAAgBYAAMAAAAAAAIAAAAKAAoAAAD/AAAAAAAAAAEAAAAKADAAPgACREZMVAAObGF0bgAaAAQAAAAAAAAAAQAAAAQAAAAAAAAAAQAAAAFsaWdhAAgAAAABAAAAAQAEAAQAAAABAAgAAQAGAAAAAQAAAAEB9AGQAAUAAAJ6ArwAAACMAnoCvAAAAeAAMQECAAACAAUDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFBmRWQAQOoB6gED6AAAAFoD6AAAAAAAAQAAAAAAAAAAAAAD6AAAAAAABQAAAAMAAAAsAAAABAAAAVQAAQAAAAAATgADAAEAAAAsAAMACgAAAVQABAAiAAAABAAEAAEAAOoB//8AA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ljay1mYXZvcml0ZXF1aWNrLWZhdm9yaXRlVmVyc2lvbiAxLjBxdWljay1mYXZvcml0ZUdlbmVyYXRlZCBieSBzdmcydHRmIGZyb20gRm9udGVsbG8gcHJvamVjdC5odHRwOi8vZm9udGVsbG8uY29tAHEAdQBpAGMAawAtAGYAYQB2AG8AcgBpAHQAZQBSAGUAZwB1AGwAYQByAHEAdQBpAGMAawAtAGYAYQB2AG8AcgBpAHQAZQBxAHUAaQBjAGsALQBmAGEAdgBvAHIAaQB0AGUAVgBlAHIAcwBpAG8AbgAgADEALgAwAHEAdQBpAGMAawAtAGYAYQB2AG8AcgBpAHQAZQBHAGUAbgBlAHIAYQB0AGUAZAAgAGIAeQAgAHMAdgBnADIAdAB0AGYAIABmAHIAbwBtACAARgBvAG4AdABlAGwAbABvACAAcAByAG8AagBlAGMAdAAuAGgAdAB0AHAAOgAvAC8AZgBvAG4AdABlAGwAbABvAC4AYwBvAG0AAAACAAAAAAAAAAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIBAgEDABNxdWljay1mYXZvcml0ZV9fXyAxAAAAAAA=");\n}\n.video-toolbar .ops .quick-favorite {\n margin-right: 28px !important;\n position: relative;\n font-size: 0;\n font-size: 14px;\n width: auto !important;\n}\n.video-toolbar .ops .quick-favorite .text {\n display: inline;\n}\n@media screen and (max-width: 1320px), (max-height: 750px) {\n.video-toolbar .ops .quick-favorite {\n margin-right: max(calc(min(11vw, 11vh) - 117.2px), 6px) !important;\n}\n.video-toolbar .ops .quick-favorite .text {\n display: none;\n}\n}\n.video-toolbar .ops .quick-favorite-icon {\n font-family: "quick-favorite" !important;\n display: inline-block;\n font-style: normal;\n text-align: center;\n text-transform: none;\n line-height: 1;\n text-rendering: optimizeLegibility;\n -webkit-font-smoothing: antialiased;\n}\n.video-toolbar .ops .quick-favorite-icon:after {\n content: "";\n}\n.video-toolbar .ops .quick-favorite .tip,\n.video-toolbar .ops .quick-favorite .select-list,\n.video-toolbar .ops .quick-favorite .lists-tip {\n line-height: normal;\n position: absolute;\n top: calc(100% + 8px);\n left: 50%;\n transform: translateX(-50%);\n z-index: 1000;\n background: rgba(0,0,0,0.86667);\n padding: 4px 8px;\n border-radius: 4px;\n color: #eee;\n transition: all 0.2s ease-out;\n opacity: 0;\n pointer-events: none;\n}\n.video-toolbar .ops .quick-favorite .tip.show,\n.video-toolbar .ops .quick-favorite .select-list.show,\n.video-toolbar .ops .quick-favorite .lists-tip.show {\n opacity: 1;\n pointer-events: initial;\n}\n.video-toolbar .ops .quick-favorite .tip {\n padding: 8px;\n}\n.video-toolbar .ops .quick-favorite .lists-tip {\n top: calc(100% + 8px + 42px);\n color: #ccc;\n font-size: 12px;\n z-index: 100;\n}\n.video-toolbar .ops .quick-favorite .select-list {\n display: flex;\n align-items: center;\n}\n.video-toolbar .ops .quick-favorite .select-list > * {\n white-space: nowrap;\n}\n.video-toolbar .ops .quick-favorite .select-list .lists-loading {\n padding: 4px 32px;\n}\n.video-toolbar .ops .quick-favorite .select-list .lists {\n margin-left: 8px;\n}',""]),A.exports=i},645:function(A){"use strict";
// eslint-disable-next-line func-names
A.exports=function(A){var t=[];return t.toString=function(){return this.map((function(t){var e=A(t);return t[2]?"@media ".concat(t[2]," {").concat(e,"}"):e})).join("")},
// eslint-disable-next-line func-names
t.i=function(A,e,i){"string"==typeof A&&(
// eslint-disable-next-line no-param-reassign
A=[[null,A,""]]);var n={};if(i)for(var o=0;o<this.length;o++){
// eslint-disable-next-line prefer-destructuring
var r=this[o][0];null!=r&&(n[r]=!0)}for(var a=0;a<A.length;a++){var s=[].concat(A[a]);i&&n[s[0]]||(e&&(s[2]?s[2]="".concat(e," and ").concat(s[2]):s[2]=e),t.push(s))}},t}},379:function(A,t,e){"use strict";var i,n=function(){return void 0===i&&(
// @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805
// @see https://github.com/webpack-contrib/style-loader/issues/177
i=Boolean(window&&document&&document.all&&!window.atob)),i},o=function(){var A={};return function(t){if(void 0===A[t]){var e=document.querySelector(t);if(window.HTMLIFrameElement&&e instanceof window.HTMLIFrameElement)try{e=e.contentDocument.head}catch(A){e=null}A[t]=e}return A[t]}}(),r=[];function a(A){for(var t=-1,e=0;e<r.length;e++)if(r[e].identifier===A){t=e;break}return t}function s(A,t){for(var e={},i=[],n=0;n<A.length;n++){var o=A[n],s=t.base?o[0]+t.base:o[0],c=e[s]||0,l="".concat(s," ").concat(c);e[s]=c+1;var d=a(l),u={css:o[1],media:o[2],sourceMap:o[3]};-1!==d?(r[d].references++,r[d].updater(u)):r.push({identifier:l,updater:g(u,t),references:1}),i.push(l)}return i}function c(A){var t=document.createElement("style"),i=A.attributes||{};if(void 0===i.nonce){var n=e.nc;n&&(i.nonce=n)}if(Object.keys(i).forEach((function(A){t.setAttribute(A,i[A])})),"function"==typeof A.insert)A.insert(t);else{var r=o(A.insert||"head");if(!r)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");r.appendChild(t)}return t}var l,d=(l=[],function(A,t){return l[A]=t,l.filter(Boolean).join("\n")});function u(A,t,e,i){var n=e?"":i.media?"@media ".concat(i.media," {").concat(i.css,"}"):i.css;if(A.styleSheet)A.styleSheet.cssText=d(t,n);else{var o=document.createTextNode(n),r=A.childNodes;r[t]&&A.removeChild(r[t]),r.length?A.insertBefore(o,r[t]):A.appendChild(o)}}function f(A,t,e){var i=e.css,n=e.media,o=e.sourceMap;if(n?A.setAttribute("media",n):A.removeAttribute("media"),o&&"undefined"!=typeof btoa&&(i+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(o))))," */")),A.styleSheet)A.styleSheet.cssText=i;else{for(;A.firstChild;)A.removeChild(A.firstChild);A.appendChild(document.createTextNode(i))}}var p=null,v=0;function g(A,t){var e,i,n;if(t.singleton){var o=v++;e=p||(p=c(t)),i=u.bind(null,e,o,!1),n=u.bind(null,e,o,!0)}else e=c(t),i=f.bind(null,e,t),n=function(){!function(A){if(null===A.parentNode)return!1;A.parentNode.removeChild(A)}(e)};return i(A),function(t){if(t){if(t.css===A.css&&t.media===A.media&&t.sourceMap===A.sourceMap)return;i(A=t)}else n()}}A.exports=function(A,t){(t=t||{}).singleton||"boolean"==typeof t.singleton||(t.singleton=n());var e=s(A=A||[],t);return function(A){if(A=A||[],"[object Array]"===Object.prototype.toString.call(A)){for(var i=0;i<e.length;i++){var n=a(e[i]);r[n].references--}for(var o=s(A,t),c=0;c<e.length;c++){var l=a(e[c]);0===r[l].references&&(r[l].updater(),r.splice(l,1))}e=o}}}},123:function(A,t,e){"use strict";e.r(t),e.d(t,{default:function(){return m}});var i=function(){var A=this,t=A.$createElement,e=A._self._c||t;return e("span",{staticClass:"quick-favorite",class:{on:A.isFavorite},attrs:{title:"快速收藏"},on:{click:function(t){return!t.type.indexOf("key")&&A._k(t.keyCode,"left",37,t.key,["Left","ArrowLeft"])||"button"in t&&0!==t.button||t.target!==t.currentTarget?null:A.toggle()},contextmenu:function(t){if(t.preventDefault(),t.target!==t.currentTarget)return null;A.listShowing=!A.listShowing}}},[e("i",{staticClass:"quick-favorite-icon",on:{click:function(t){return!t.type.indexOf("key")&&A._k(t.keyCode,"left",37,t.key,["Left","ArrowLeft"])||"button"in t&&0!==t.button?null:A.toggle()},contextmenu:function(t){t.preventDefault(),A.listShowing=!A.listShowing}}}),A._v(" "),e("div",{staticClass:"text",on:{click:function(t){return!t.type.indexOf("key")&&A._k(t.keyCode,"left",37,t.key,["Left","ArrowLeft"])||"button"in t&&0!==t.button?null:A.toggle()},contextmenu:function(t){t.preventDefault(),A.listShowing=!A.listShowing}}},[A._v("\n 快速收藏\n ")]),A._v(" "),e("div",{ref:"selectList",staticClass:"select-list",class:{show:A.listShowing}},[A._v("\n 选择快速收藏夹:\n "),e("div",{staticClass:"lists"},[e("VDropdown",{attrs:{items:A.lists.map((function(A){return A.title})),"key-mapper":function(A){return A}},scopedSlots:A._u([{key:"item",fn:function(t){var e=t.item;return[A._v("\n "+A._s(e)+"\n ")]}}]),model:{value:A.selectedFavorite,callback:function(t){A.selectedFavorite=t},expression:"selectedFavorite"}})],1)]),A._v(" "),e("div",{staticClass:"lists-tip",class:{show:A.listShowing}},[A._v("\n 右键点击快速收藏可再次打开\n ")]),A._v(" "),e("div",{staticClass:"tip",class:{show:A.tipShowing}},[A._v(A._s(A.tipText))])])};i._withStripped=!0;var n=coreApis.settings,o=coreApis.ajax,r=e(109),a=coreApis.utils.log,s=coreApis.toast,c=coreApis.ui;const{options:l}=(0,n.getComponentSettings)("quickFavorite");var d=Vue.extend({components:{VDropdown:c.VDropdown},data:()=>({aid:unsafeWindow.aid,favoriteTitle:"",isFavorite:!1,tipText:"",tipShowing:!1,tipHandle:0,lists:[],selectedFavorite:"<未选择>",listShowing:!1}),watch:{selectedFavorite(A){if(0===this.lists.length)return;const{lists:t}=this,e=t.find((t=>t.title===A));e?(l.favoriteFolderID=e.id,this.syncFavoriteState()):console.error("list not found in selectedFavorite(value)")},async listShowing(A){if(A&&(document.addEventListener("click",(A=>{const t=this.$el,e=A.target;e===t||t.contains(e)||(this.listShowing=!1)})),0===this.lists.length))try{const A=await(0,o.getJsonWithCredentials)(`https://api.bilibili.com/medialist/gateway/base/created?pn=1&ps=100&up_mid=${(0,r.getUID)()}&is_space=0`);if(0!==A.code)throw new Error(`获取收藏夹列表失败: ${A.message}`);this.lists=lodash.get(A,"data.list",[])}catch(A){(0,a.logError)(A)}}},created(){this.syncFavoriteState()},methods:{async syncFavoriteState(){if(0!==l.favoriteFolderID)try{const A=await(0,o.getJsonWithCredentials)(`https://api.bilibili.com/x/v3/fav/folder/created/list-all?type=2&rid=${this.aid}&up_mid=${(0,r.getUID)()}`);if(0!==A.code)throw new Error(`获取收藏状态失败: ${A.message}`);const t=lodash.get(A,"data.list",[]).find((A=>A.id===l.favoriteFolderID));if(void 0===t)return void(l.favoriteFolderID=0);this.isFavorite=Boolean(t.fav_state),this.favoriteTitle=t.title,this.selectedFavorite=t.title}catch(A){(0,a.logError)(A)}},showTip(A){this.tipText=A,this.tipShowing=!0,this.tipHandle&&clearTimeout(this.tipHandle),this.tipHandle=setTimeout((()=>{this.tipShowing=!1}),2e3)},async toggle(){if(0===l.favoriteFolderID)return void(this.listShowing=!0);const A={rid:this.aid,type:2,add_media_ids:"",del_media_ids:"",csrf:(0,r.getCsrf)()};A[this.isFavorite?"del_media_ids":"add_media_ids"]=l.favoriteFolderID.toString();try{await(0,o.postTextWithCredentials)("https://api.bilibili.com/x/v3/fav/resource/deal",Object.entries(A).map((([A,t])=>`${A}=${t}`)).join("&")),this.isFavorite=!this.isFavorite,this.showTip(this.isFavorite?`已添加至收藏夹: ${this.favoriteTitle}`:`已移出收藏夹: ${this.favoriteTitle}`)}catch(A){s.Toast.error(`快速收藏失败: ${A.message}`,"快速收藏"),console.error(A)}}}}),u=e(379),f=e.n(u),p=e(708),v=e.n(p),g={insert:"head",singleton:!1};f()(v(),g),v().locals;var h=function(A,t,e,i,n,o,r,a){var s,c="function"==typeof A?A.options:A;if(t&&(c.render=t,c.staticRenderFns=e,c._compiled=!0),i&&(c.functional=!0),o&&(c._scopeId="data-v-"+o),r?(s=function(A){(A=A||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(A=__VUE_SSR_CONTEXT__),n&&n.call(this,A),A&&A._registeredComponents&&A._registeredComponents.add(r)},c._ssrRegister=s):n&&(s=a?function(){n.call(this,(c.functional?this.parent:this).$root.$options.shadowRoot)}:n),s)if(c.functional){c._injectStyles=s;var l=c.render;c.render=function(A,t){return s.call(t),l(A,t)}}else{var d=c.beforeCreate;c.beforeCreate=d?[].concat(d,s):[s]}return{exports:A,options:c}}(d,i,[],!1,null,null,null);h.options.__file="registry/lib/components/video/quick-favorite/QuickFavorite.vue";var m=h.exports},156:function(A){"use strict";A.exports=coreApis.observer},109:function(A){"use strict";A.exports=coreApis.utils}},i={};function n(A){var t=i[A];if(void 0!==t)return t.exports;var o=i[A]={id:A,exports:{}};return e[A](o,o.exports,n),o.exports}n.n=function(A){var t=A&&A.__esModule?function(){return A.default}:function(){return A};return n.d(t,{a:t}),t},t=Object.getPrototypeOf?function(A){return Object.getPrototypeOf(A)}:function(A){return A.__proto__},n.t=function(e,i){if(1&i&&(e=this(e)),8&i)return e;if("object"==typeof e&&e){if(4&i&&e.__esModule)return e;if(16&i&&"function"==typeof e.then)return e}var o=Object.create(null);n.r(o);var r={};A=A||[null,t({}),t([]),t(t)];for(var a=2&i&&e;"object"==typeof a&&!~A.indexOf(a);a=t(a))Object.getOwnPropertyNames(a).forEach((function(A){r[A]=function(){return e[A]}}));return r.default=function(){return e},n.d(o,r),o},n.d=function(A,t){for(var e in t)n.o(t,e)&&!n.o(A,e)&&Object.defineProperty(A,e,{enumerable:!0,get:t[e]})},n.o=function(A,t){return Object.prototype.hasOwnProperty.call(A,t)},n.r=function(A){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(A,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(A,"__esModule",{value:!0})};var o={};return function(){"use strict";n.d(o,{component:function(){return t}});var A=coreApis.utils.urls;const t={name:"quickFavorite",displayName:"启用快速收藏",description:{"zh-CN":"启用快速收藏, 在视频页面可以一键收藏到设定的某个收藏夹. 首次启动时或者右键点击快速收藏图标可以配置快速收藏夹."},entry:async()=>{const{playerReady:A,mountVueComponent:t,getUID:e}=await Promise.resolve().then(n.t.bind(n,109,23));if(!e())return;await A();const i=dq(".video-toolbar .ops .collect");if(!i)return;const o=await Promise.resolve().then(n.bind(n,123));let r;const{videoChange:a}=await Promise.resolve().then(n.t.bind(n,156,23));a((()=>{r||(r=t(o),i.insertAdjacentElement("afterend",r.$el)),r.aid=unsafeWindow.aid,r.syncFavoriteState()}))},unload:()=>{dqa(".ops .quick-favorite").forEach((A=>A.style.display="none"))},reload:()=>{dqa(".ops .quick-favorite").forEach((A=>A.style.display="inline-block"))},urlInclude:A.videoUrls,urlExclude:A.favoriteListUrls,tags:[componentsTags.video],options:{favoriteFolderID:{defaultValue:0,displayName:"快速收藏夹ID",hidden:!0}},plugin:{displayName:"快速收藏 - 快捷键支持",setup:({addData:A})=>{A("keymap.actions",(A=>{A.quickFavorite={displayName:"快速收藏",run:A=>{const{clickElement:t}=A;return t(".quick-favorite",A)}}})),A("keymap.presets",(A=>{A.quickFavorite="shift s"}))}},commitHash:"758500b73a42eb701eb7723934900e124e4e1ddc"}}(),o=o.component}()}));