UNPKG

@mlikiowa/nanaeo

Version:
3 lines (2 loc) 20.4 kB
"use strict";function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function _regeneratorRuntime(){_regeneratorRuntime=function(){return t};var e,t={},n=Object.prototype,r=n.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",l=o.asyncIterator||"@@asyncIterator",a=o.toStringTag||"@@toStringTag";function c(e,t,n,r){return Object.defineProperty(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r})}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function u(t,n,r,o){var i=n&&n.prototype instanceof m?n:m,l=Object.create(i.prototype);return c(l,"_invoke",function(t,n,r){var o=1;return function(i,l){if(3===o)throw Error("Generator is already running");if(4===o){if("throw"===i)throw l;return{value:e,done:!0}}for(r.method=i,r.arg=l;;){var a=r.delegate;if(a){var c=C(a,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(1===o)throw o=4,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=3;var u=s(t,n,r);if("normal"===u.type){if(o=r.done?4:2,u.arg===d)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(o=4,r.method="throw",r.arg=u.arg)}}}(t,r,new S(o||[])),!0),l}function s(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=u;var d={};function m(){}function p(){}function f(){}var y={};c(y,i,(function(){return this}));var h=Object.getPrototypeOf,g=h&&h(h(D([])));g&&g!==n&&r.call(g,i)&&(y=g);var v=f.prototype=m.prototype=Object.create(y);function b(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function M(e,t){function n(o,i,l,a){var c=s(e[o],e,i);if("throw"!==c.type){var u=c.arg,d=u.value;return d&&"object"==_typeof(d)&&r.call(d,"__await")?t.resolve(d.__await).then((function(e){n("next",e,l,a)}),(function(e){n("throw",e,l,a)})):t.resolve(d).then((function(e){u.value=e,l(u)}),(function(e){return n("throw",e,l,a)}))}a(c.arg)}var o;c(this,"_invoke",(function(e,r){function i(){return new t((function(t,o){n(e,r,t,o)}))}return o=o?o.then(i,i):i()}),!0)}function C(t,n){var r=n.method,o=t.i[r];if(o===e)return n.delegate=null,"throw"===r&&t.i["return"]&&(n.method="return",n.arg=e,C(t,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),d;var i=s(o,t.i,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,d;var l=i.arg;return l?l.done?(n[t.r]=l.value,n.next=t.n,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,d):l:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,d)}function O(e){this.tryEntries.push(e)}function w(t){var n=t[4]||{};n.type="normal",n.arg=e,t[4]=n}function S(e){this.tryEntries=[[-1]],e.forEach(O,this),this.reset(!0)}function D(t){if(null!=t){var n=t[i];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,l=function n(){for(;++o<t.length;)if(r.call(t,o))return n.value=t[o],n.done=!1,n;return n.value=e,n.done=!0,n};return l.next=l}}throw new TypeError(_typeof(t)+" is not iterable")}return p.prototype=f,c(v,"constructor",f),c(f,"constructor",p),p.displayName=c(f,a,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,c(e,a,"GeneratorFunction")),e.prototype=Object.create(v),e},t.awrap=function(e){return{__await:e}},b(M.prototype),c(M.prototype,l,(function(){return this})),t.AsyncIterator=M,t.async=function(e,n,r,o,i){void 0===i&&(i=Promise);var l=new M(u(e,n,r,o),i);return t.isGeneratorFunction(n)?l:l.next().then((function(e){return e.done?e.value:l.next()}))},b(v),c(v,a,"Generator"),c(v,i,(function(){return this})),c(v,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),n=[];for(var r in t)n.unshift(r);return function o(){for(;n.length;)if((r=n.pop())in t)return o.value=r,o.done=!1,o;return o.done=!0,o}},t.values=D,S.prototype={constructor:S,reset:function(t){if(this.prev=this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(w),!t)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0][4];if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function r(e){l.type="throw",l.arg=t,n.next=e}for(var o=n.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],l=i[4],a=this.prev,c=i[1],u=i[2];if(-1===i[0])return r("end"),!1;if(!c&&!u)throw Error("try statement without catch or finally");if(null!=i[0]&&i[0]<=a){if(a<c)return this.method="next",this.arg=e,r(c),!0;if(a<u)return r(u),!1}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r[0]>-1&&r[0]<=this.prev&&this.prev<r[2]){var o=r;break}}o&&("break"===e||"continue"===e)&&o[0]<=t&&t<=o[2]&&(o=null);var i=o?o[4]:{};return i.type=e,i.arg=t,o?(this.method="next",this.next=o[2],d):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n[2]===e)return this.complete(n[4],n[3]),w(n),d}},"catch":function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n[0]===e){var r=n[4];if("throw"===r.type){var o=r.arg;w(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={i:D(t),r:n,n:r},"next"===this.method&&(this.arg=e),d}},t}function _defineProperty(e,t,n){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"==_typeof(t)?t:t+""}function _toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function asyncGeneratorStep(e,t,n,r,o,i,l){try{var a=e[i](l),c=a.value}catch(e){return void n(e)}a.done?t(c):Promise.resolve(c).then(r,o)}function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function l(e){asyncGeneratorStep(i,r,o,l,a,"next",e)}function a(e){asyncGeneratorStep(i,r,o,l,a,"throw",e)}l(void 0)}))}}var RightMenu=function(){var e=volantis.GLOBAL_CONFIG.plugins.rightmenu,t=volantis.GLOBAL_CONFIG.plugins.message.enable&&volantis.GLOBAL_CONFIG.plugins.message.rightmenu.enable,n={},r=document.getElementById("rightmenu-wrapper"),o=document.getElementById("rightmenu-content"),i=document.getElementById("printHtml"),l=document.getElementById("menuMusic"),a=document.getElementById("readingModel"),c=document.getElementById("read_bkg"),u=document.querySelectorAll(".menuLoad-Content"),s=document.querySelector(".menu-Option"),d=document.querySelector('.menu-Option[data-fn-type="searchWord"]'),m=document.querySelector('.menu-Option[data-fn-type="copyText"]'),p=document.querySelector('.menu-Option[data-fn-type="copyPaste"]'),f=document.querySelector('.menu-Option[data-fn-type="copySelect"]'),y=document.querySelector('.menu-Option[data-fn-type="copyCut"]'),h=document.querySelector('.menu-Option[data-fn-type="copyHref"]'),g=document.querySelector('.menu-Option[data-fn-type="copySrc"]'),v=document.querySelector('.menu-Option[data-fn-type="copyImg"]'),b=document.querySelector('.menu-Option[data-fn-type="openTab"]'),M=document.querySelector("#menuMusic .backward"),C=document.querySelector("#menuMusic .toggle"),O=document.querySelector("#menuMusic .forward"),w=/^((https|http)?:\/\/)+[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;return n.init=function(){DOMController.visible(l,!1),DOMController.visible(s,!1),c&&c.parentNode.removeChild(c);var e=document.createElement("div");e.className="common_read_bkg common_read_hide",e.id="read_bkg",window.document.body.appendChild(e)},n.initEvent=function(){window.document.oncontextmenu=function(e){return e.ctrlKey||document.body.offsetWidth<=500?(n.hideMenu(),!0):n.popMenu(e)},r.oncontextmenu=function(e){return e.stopPropagation(),e.preventDefault(),!1},window.removeEventListener("blur",n.hideMenu),window.addEventListener("blur",n.hideMenu),document.body.removeEventListener("click",n.hideMenu),document.body.addEventListener("click",n.hideMenu),O&&C&&O&&(M.onclick=function(e){e.preventDefault(),e.stopPropagation(),RightMenuAplayer.aplayerBackward()},C.onclick=function(e){e.preventDefault(),e.stopPropagation(),RightMenuAplayer.aplayerToggle()},O.onclick=function(e){e.preventDefault(),e.stopPropagation(),RightMenuAplayer.aplayerForward()})},n.popMenu=function(e){var t=e.clientX,i=e.clientY,l=document.documentElement.clientWidth||document.body.clientWidth,a=document.documentElement.clientHeight||document.body.clientHeight;try{n.setMenuItem(e),DOMController.visible(r),r.focus(),r.style.zIndex="-2147483648";var c=o.offsetWidth,u=o.offsetHeight,s=t+c>l?t-c+10:t,d=i+u>a?i-u+10:i;d=i+u>a&&d<u&&i<u?d+(a-u-d-10):d,r.style.left=s+"px",r.style.top=d+"px",r.style.zIndex="2147483648",volantis.GLOBAL_CONFIG.plugins.message.rightmenu.notice&&n.showMessage()}catch(m){return r.blur(),console.error(m),!0}return!1},n.showMessage=function(){var n="true"===localStorage.getItem("NoticeRightMenu");t&&!n&&VolantisApp.message("右键菜单","唤醒原系统菜单请使用:<kbd>Ctrl</kbd> + <kbd>右键</kbd>",{icon:e.faicon+" fa-exclamation-square red",time:9e3},(function(){localStorage.setItem("NoticeRightMenu","true")}))},n.setMenuItem=function(r){var o=!1,c=r.target,s=window.getSelection().toString();if(DOMController.visible(b,!1),"input"===c.tagName.toLowerCase()||"textarea"===c.tagName.toLowerCase()){var M=c.value;M.length>0?(DOMController.visible(f),f.onclick=function(){r.preventDefault(),c.select()}):DOMController.visible(f,!1),s?(DOMController.visible(y),y.onclick=function(){var e=c.selectionStart,t=c.selectionEnd;n.copyString(s),c.value=M.substring(0,e)+M.substring(t,M.length),c.selectionStart=e,c.selectionEnd=e,c.focus()}):DOMController.visible(y,!1),n.readClipboard().then((function(e){e?(DOMController.visible(p),p.onclick=function(){n.insertAtCaret(c,e)}):DOMController.visible(p,!1)}))["catch"]((function(e){console.error(e),DOMController.visible(p,!1)}))}else DOMController.visible(f,!1),DOMController.visible(p,!1),DOMController.visible(y,!1);var C=c.href;C&&w.test(C)?(o=!0,DOMController.visible(h),DOMController.visible(b),h&&(h.onclick=function(){n.copyString(C)}),b.onclick=function(){window.open(C)}):DOMController.visible(h,!1);var O=c.currentSrc;O&&w.test(O)?(o=!0,DOMController.visible(g),DOMController.visible(b),g.onclick=function(){n.copyString(O)},b.onclick=function(){window.open(O)}):DOMController.visible(g,!1),O&&w.test(O)&&O.trimEnd().endsWith(".png")?(o=!0,DOMController.visible(v),v.onclick=function(){n.writeClipImg(r,(function(n){n&&t&&VolantisApp.message("系统提示","图片复制成功!",{icon:e.faicon+" fa-images"})}),(function(n){t&&VolantisApp.message("系统提示","复制失败:"+n,{icon:e.faicon+" fa-exclamation-square red"})}))}):DOMController.visible(v,!1),s?(o=!0,DOMController.visible(m),DOMController.visible(d),m.onclick=function(){n.copyString(s)},d&&(d.onclick=function(){OpenSearch(s)})):(DOMController.visible(m,!1),DOMController.visible(d,!1));var S=document.querySelector("#post.article")||null,D=window.location.pathname;S?(DOMController.visible(i),DOMController.visible(a),i&&(i.onclick=function(){if(window.location.pathname===D){t&&VolantisApp.question("",'是否打印当前页面?<br><em style="font-size: 80%">建议打印时勾选背景图形</em><br>',{},(function(){n.printHtml()}))}else n.hideMenu()}),a&&(a.onclick=function(){window.location.pathname,n.readingModel()})):(DOMController.visible(i,!1),DOMController.visible(a,!1)),volantis.GLOBAL_CONFIG.plugins.aplayer.enable&&"undefined"!=typeof RightMenuAplayer&&RightMenuAplayer.APlayer.player!==undefined?e.music_alwaysShow?DOMController.visible(l):"play"===RightMenuAplayer.APlayer.status||"undefined"===RightMenuAplayer.APlayer.status?(o=!0,DOMController.visible(l)):DOMController.visible(l,!1):DOMController.visible(l,!1),u.forEach((function(e){DOMController.visible(e,!o)})),volantis.GLOBAL_CONFIG.plugins.aplayer.enable&&e.layout.includes("music")&&RightMenuAplayer.checkAPlayer()},n.hideMenu=function(){DOMController.visible(r,!1)},n.copyString=function(n){VolantisApp.utilWriteClipText(n).then((function(){t&&VolantisApp.messageCopyright()}))["catch"]((function(n){t&&VolantisApp.message("系统提示",n,{icon:e.faicon+" fa-exclamation-square red"})}))},n.writeClipText=function(e){try{return navigator.clipboard.writeText(e).then((function(){return Promise.resolve()}))["catch"]((function(e){return Promise.reject(e)}))}catch(r){var t=document.createElement("input");t.setAttribute("readonly","readonly"),document.body.appendChild(t),t.setAttribute("value",e),t.select();try{var n=document.execCommand("copy");return document.body.removeChild(t),n&&"unsuccessful"!==n?Promise.resolve():Promise.reject("复制文本失败!")}catch(r){return document.body.removeChild(t),Promise.reject("当前浏览器不支持复制功能,请检查更新或更换其他浏览器操作!")}}},n.writeClipImg=function(){var t=_asyncToGenerator(_regeneratorRuntime().mark((function n(t,r,o){var i,l,a,c,u,s,d,m;return _regeneratorRuntime().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return i=e.customPicUrl.enable?t.target.currentSrc.replace(e.customPicUrl.old,e.customPicUrl["new"]):t.target.currentSrc,l=t.target.parentElement,n.prev=2,n.next=5,fetch(i);case 5:return a=n.sent,n.next=8,a.blob();case 8:return c=n.sent,n.next=11,navigator.clipboard.write([new ClipboardItem(_defineProperty({},c.type,c))]).then((function(){r(!0)}),(function(e){console.error("图片复制失败:",e),o(e)}));case 11:n.next=17;break;case 13:n.prev=13,n.t0=n["catch"](2),u=document;try{u.body.createTextRange?((s=document.body.createTextRange()).moveToElementText(l),s.select()):window.getSelection&&(d=window.getSelection(),(m=document.createRange()).selectNodeContents(l),d.removeAllRanges(),d.addRange(m)),document.execCommand("copy"),window.getSelection().removeAllRanges(),r(!1)}catch(p){console.error(p),o("不支持复制当前图片!")}case 17:case"end":return n.stop()}}),n,null,[[2,13]])})));return function(e,n,r){return t.apply(this,arguments)}}(),n.readClipboard=_asyncToGenerator(_regeneratorRuntime().mark((function S(){var e;return _regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,navigator.permissions.query({name:"clipboard-read"});case 2:if("granted"!==(e=t.sent).state&&"prompt"!==e.state){t.next=5;break}return t.abrupt("return",navigator.clipboard.readText().then((function(e){return e}))["catch"]((function(e){return Promise.reject(e)})));case 5:return t.abrupt("return",Promise.reject(e));case 6:case"end":return t.stop()}}),S)}))),n.insertAtCaret=function(e,t){var n=e.selectionStart,r=e.selectionEnd;if(document.selection)e.focus(),document.selection.createRange().text=t,e.focus();else if(n||"0"==n){var o=e.scrollTop;e.value=e.value.substring(0,n)+t+e.value.substring(r,e.value.length),e.focus(),e.selectionStart=n+t.length,e.selectionEnd=n+t.length,e.scrollTop=o}else e.value+=t,e.focus()},n.printHtml=function(){volantis.isReadModel&&n.readingModel(),DOMController.setAttribute("details","open","true"),DOMController.remove(".cus-article-bkg"),DOMController.remove(".iziToast-overlay"),DOMController.remove(".iziToast-wrapper"),DOMController.remove(".prev-next"),DOMController.remove("footer"),DOMController.remove("#l_header"),DOMController.remove("#l_cover"),DOMController.remove("#l_side"),DOMController.remove("#comments"),DOMController.remove("#s-top"),DOMController.remove("#BKG"),DOMController.remove("#rightmenu-wrapper"),DOMController.remove(".nav-tabs"),DOMController.remove(".parallax-mirror"),DOMController.remove(".new-meta-item.share"),DOMController.remove("div.footer"),DOMController.setStyle("body","backgroundColor","unset"),DOMController.setStyle("#l_main","width","100%"),DOMController.setStyle("#post","boxShadow","none"),DOMController.setStyle("#post","background","none"),DOMController.setStyle("#post","padding","0"),DOMController.setStyle("h1","textAlign","center"),DOMController.setStyle("h1","fontWeight","600"),DOMController.setStyle("h1","fontSize","2rem"),DOMController.setStyle("h1","marginBottom","20px"),DOMController.setStyle(".tab-pane","display","block"),DOMController.setStyle(".tab-content","borderTop","none"),DOMController.setStyle(".highlight>table pre","whiteSpace","pre-wrap"),DOMController.setStyle(".highlight>table pre","wordBreak","break-all"),DOMController.setStyle(".fancybox img","height","auto"),DOMController.setStyle(".fancybox img","weight","auto"),setTimeout((function(){window.print(),document.body.innerHTML="",window.location.reload()}),50)},n.readingModel=function(){if("function"==typeof ScrollReveal&&ScrollReveal().clean("#comments"),DOMController.fadeToggle(document.querySelector("#l_header")),DOMController.fadeToggle(document.querySelector("footer")),DOMController.fadeToggle(document.querySelector("#s-top")),DOMController.fadeToggle(document.querySelector(".article-meta#bottom")),DOMController.fadeToggle(document.querySelector(".prev-next")),DOMController.fadeToggle(document.querySelector("#l_side")),DOMController.fadeToggle(document.querySelector("#comments")),DOMController.toggleClass(document.querySelector("#l_main"),"common_read"),DOMController.toggleClass(document.querySelector("#l_main"),"common_read_main"),DOMController.toggleClass(document.querySelector("#l_body"),"common_read"),DOMController.toggleClass(document.querySelector("#safearea"),"common_read"),DOMController.toggleClass(document.querySelector("#pjax-container"),"common_read"),DOMController.toggleClass(document.querySelector("#read_bkg"),"common_read_hide"),DOMController.toggleClass(document.querySelector("h1"),"common_read_h1"),DOMController.toggleClass(document.querySelector("#post"),"post_read"),DOMController.toggleClass(document.querySelector("#l_cover"),"read_cover"),DOMController.toggleClass(document.querySelector(".widget.toc-wrapper"),"post_read"),volantis.isReadModel=volantis.isReadModel===undefined||!volantis.isReadModel,volantis.isReadModel){var r={backgroundColor:"var(--color-read-post)",icon:e.faicon+" fa-book-reader",time:5e3};t&&VolantisApp.message("系统提示","阅读模式已开启,您可以点击屏幕空白处退出。",r),document.querySelector("#l_body").removeEventListener("click",n.readingModel),document.querySelector("#l_body").addEventListener("click",(function(e){DOMController.hasClass(e.target,"common_read")&&n.readingModel()}))}else document.querySelector("#l_body").removeEventListener("click",n.readingModel),document.querySelector("#post").removeEventListener("click",n.readingModel)},{init:function(){var e=arguments.length>0&&arguments[0]!==undefined&&arguments[0];n.init(),n.initEvent(),e&&t&&VolantisApp.message("系统提示","自定义右键注册成功。")},destroy:function(){var e=arguments.length>0&&arguments[0]!==undefined&&arguments[0];n.hideMenu(),window.document.oncontextmenu=function(){return!0},e&&t&&VolantisApp.message("系统提示","自定义右键注销成功。")},hideMenu:n.hideMenu,readingModel:n.readingModel}}();Object.freeze(RightMenu),volantis.requestAnimationFrame((function(){"loading"!==document.readyState?(RightMenu.init(),volantis.pjax.send((function(){RightMenu.hideMenu()}))):document.addEventListener("DOMContentLoaded",(function(){RightMenu.init(),volantis.pjax.send((function(){RightMenu.hideMenu()}))}))})); //# sourceMappingURL=../../maps/js/plugins/rightMenu.js.map