UNPKG

md-fileserver

Version:

Locally view markdown files in a browser

2 lines 3.96 kB
/*! For license information please see index.js.LICENSE.txt */ (()=>{"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){for(var o=0;o<e.length;o++){var i=e[o];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,n(i.key),i)}}function n(e){var n=function(e,n){if("object"!=t(e)||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var i=o.call(e,"string");if("object"!=t(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(n)?n:n+""}var o=function(){return t=function t(e,n,o){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var i=(o||{}).runOnInit,r=void 0!==i&&i;Object.assign(this,{fn:e,timeout:n}),this.set(),r&&e()},(n=[{key:"set",value:function(){var t=this,e=this.fn,n=this.timeout;this._timer=setTimeout((function(){t.set(),e()}),n)}},{key:"clear",value:function(){clearTimeout(this._timer)}}])&&e(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,n}();function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function r(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,c(o.key),o)}}function c(t){var e=function(t,e){if("object"!=i(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!=i(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==i(e)?e:e+""}var s=new(function(){return t=function t(){var e=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.isReestablishing=!1,this._isFollower=!0,this.interval=new o((function(){e._isFollower||e.send({follower:!0})}),1e3),this.interval.set()},(e=[{key:"connection",get:function(){return this._conn},set:function(t){this._conn=t}},{key:"dispatcher",get:function(){return this._dispatch},set:function(t){this._dispatch=t}},{key:"isFollower",get:function(){return this._isFollower},set:function(t){this._isFollower=t,this.dispatch({isRx:t});var e=document.documentElement;t?e.classList.add("follower"):(e.classList.remove("follower"),this.send({follower:!0}))}},{key:"dispatch",value:function(t){var e=this._dispatch;e&&e.dispatch(t)}},{key:"send",value:function(t){var e=this._conn;e&&e.readyState===e.OPEN&&e.send(JSON.stringify(t))}},{key:"close",value:function(){var t=this._conn;this.interval.clear(),t&&t.close()}},{key:"sendScroll",value:function(){var t={top:window.scrollY/document.body.clientHeight,left:window.scrollX/document.body.clientWidth};this.send({scroll:t})}}])&&r(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}());window.addEventListener("beforeunload",(function(){s.close()})),function t(){var e=window.WebSocket||window.MozWebSocket;if(e){var n=new e("ws://".concat(location.host));return s.connection=n,n.onmessage=function(t){(function(t){try{return JSON.parse(t)}catch(t){return console.error(t),{}}})(t.data).change===location.pathname&&location.reload()},n.onopen=function(){s.isReestablishing&&n&&(s.isReestablishing=!1,location.reload())},n.onclose=function(){s.isReestablishing=!0,setTimeout((function(){t()}),500)},n.onerror=function(t){console.log(t)},{send:function(t){return!s.isFollower&&s.send(t)}}}console.error("there is no WebSocket...")}(),document.querySelectorAll("a[href]").forEach((function(t){var e=t.getAttribute("href");/^https?:\/\//.test(e)&&t.setAttribute("target","_blank")}))})();