Skip to content

Instantly share code, notes, and snippets.

@ccjmne
Last active August 10, 2023 11:30
Show Gist options
  • Save ccjmne/ed00e22ba2a0c1ef21441ef1a3cb8045 to your computer and use it in GitHub Desktop.
Save ccjmne/ed00e22ba2a0c1ef21441ef1a3cb8045 to your computer and use it in GitHub Desktop.
Laufzettels search-and-replace widget for Unite
// ==UserScript==
// @name Replace text in Laufzettels
// @namespace http://tampermonkey.net/
// @version 1.0.0
// @author Eric NICOLAS (ccjmne) <ccjmne@gmail.com>
// @match https://backoffice.intern.mercateo.com/prototype.tgui.server/
// @icon https://www.google.com/s2/favicons?sz=64&domain=mercateo.com
// @grant none
// ==/UserScript==
(()=>{"use strict";var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};function e(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}function r(t,e){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,n=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=e.call(t,u)}catch(t){c=[6,t],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}}function n(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function o(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,i=r.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)u.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u}function i(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}function u(t){return this instanceof u?(this.v=t,this):new u(t)}Object.create,Object.create;var c=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t};function s(t){return"function"==typeof t}function a(t){return s(null==t?void 0:t.then)}function l(t){var e=t((function(t){Error.call(t),t.stack=(new Error).stack}));return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var f=l((function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}}));function p(t,e){if(t){var r=t.indexOf(e);0<=r&&t.splice(r,1)}}var d=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}var e;return t.prototype.unsubscribe=function(){var t,e,r,u,c;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var l=n(a),p=l.next();!p.done;p=l.next())p.value.remove(this)}catch(e){t={error:e}}finally{try{p&&!p.done&&(e=l.return)&&e.call(l)}finally{if(t)throw t.error}}else a.remove(this);var d=this.initialTeardown;if(s(d))try{d()}catch(t){c=t instanceof f?t.errors:[t]}var h=this._finalizers;if(h){this._finalizers=null;try{for(var v=n(h),y=v.next();!y.done;y=v.next()){var m=y.value;try{b(m)}catch(t){c=null!=c?c:[],t instanceof f?c=i(i([],o(c)),o(t.errors)):c.push(t)}}}catch(t){r={error:t}}finally{try{y&&!y.done&&(u=v.return)&&u.call(v)}finally{if(r)throw r.error}}}if(c)throw new f(c)}},t.prototype.add=function(e){var r;if(e&&e!==this)if(this.closed)b(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=null!==(r=this._finalizers)&&void 0!==r?r:[]).push(e)}},t.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},t.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},t.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&p(e,t)},t.prototype.remove=function(e){var r=this._finalizers;r&&p(r,e),e instanceof t&&e._removeParent(this)},t.EMPTY=((e=new t).closed=!0,e),t}(),h=d.EMPTY;function v(t){return t instanceof d||t&&"closed"in t&&s(t.remove)&&s(t.add)&&s(t.unsubscribe)}function b(t){s(t)?t():t.unsubscribe()}var y={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},m={setTimeout:function(t,e){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var u=m.delegate;return(null==u?void 0:u.setTimeout)?u.setTimeout.apply(u,i([t,e],o(r))):setTimeout.apply(void 0,i([t,e],o(r)))},clearTimeout:function(t){var e=m.delegate;return((null==e?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function w(t){m.setTimeout((function(){var e=y.onUnhandledError;if(!e)throw t;e(t)}))}function g(){}var x=_("C",void 0,void 0);function _(t,e,r){return{kind:t,value:e,error:r}}var S=null;function E(t){if(y.useDeprecatedSynchronousErrorHandling){var e=!S;if(e&&(S={errorThrown:!1,error:null}),t(),e){var r=S,n=r.errorThrown,o=r.error;if(S=null,n)throw o}}else t()}var T=function(t){function r(e){var r=t.call(this)||this;return r.isStopped=!1,e?(r.destination=e,v(e)&&e.add(r)):r.destination=j,r}return e(r,t),r.create=function(t,e,r){return new A(t,e,r)},r.prototype.next=function(t){this.isStopped?k(function(t){return _("N",t,void 0)}(t),this):this._next(t)},r.prototype.error=function(t){this.isStopped?k(_("E",void 0,t),this):(this.isStopped=!0,this._error(t))},r.prototype.complete=function(){this.isStopped?k(x,this):(this.isStopped=!0,this._complete())},r.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},r.prototype._next=function(t){this.destination.next(t)},r.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},r.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},r}(d),O=Function.prototype.bind;function C(t,e){return O.call(t,e)}var P=function(){function t(t){this.partialObserver=t}return t.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(t){I(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){I(t)}else I(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){I(t)}},t}(),A=function(t){function r(e,r,n){var o,i,u=t.call(this)||this;return s(e)||!e?o={next:null!=e?e:void 0,error:null!=r?r:void 0,complete:null!=n?n:void 0}:u&&y.useDeprecatedNextContext?((i=Object.create(e)).unsubscribe=function(){return u.unsubscribe()},o={next:e.next&&C(e.next,i),error:e.error&&C(e.error,i),complete:e.complete&&C(e.complete,i)}):o=e,u.destination=new P(o),u}return e(r,t),r}(T);function I(t){var e;y.useDeprecatedSynchronousErrorHandling?(e=t,y.useDeprecatedSynchronousErrorHandling&&S&&(S.errorThrown=!0,S.error=e)):w(t)}function k(t,e){var r=y.onStoppedNotification;r&&m.setTimeout((function(){return r(t,e)}))}var j={closed:!0,next:g,error:function(t){throw t},complete:g},L="function"==typeof Symbol&&Symbol.observable||"@@observable";function z(t){return t}var R=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(e){var r=new t;return r.source=this,r.operator=e,r},t.prototype.subscribe=function(t,e,r){var n,o=this,i=(n=t)&&n instanceof T||function(t){return t&&s(t.next)&&s(t.error)&&s(t.complete)}(n)&&v(n)?t:new A(t,e,r);return E((function(){var t=o,e=t.operator,r=t.source;i.add(e?e.call(i,r):r?o._subscribe(i):o._trySubscribe(i))})),i},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},t.prototype.forEach=function(t,e){var r=this;return new(e=M(e))((function(e,n){var o=new A({next:function(e){try{t(e)}catch(t){n(t),o.unsubscribe()}},error:n,complete:e});r.subscribe(o)}))},t.prototype._subscribe=function(t){var e;return null===(e=this.source)||void 0===e?void 0:e.subscribe(t)},t.prototype[L]=function(){return this},t.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(0===(r=t).length?z:1===r.length?r[0]:function(t){return r.reduce((function(t,e){return e(t)}),t)})(this);var r},t.prototype.toPromise=function(t){var e=this;return new(t=M(t))((function(t,r){var n;e.subscribe((function(t){return n=t}),(function(t){return r(t)}),(function(){return t(n)}))}))},t.create=function(e){return new t(e)},t}();function M(t){var e;return null!==(e=null!=t?t:y.Promise)&&void 0!==e?e:Promise}function $(t){return s(t[L])}function D(t){return Symbol.asyncIterator&&s(null==t?void 0:t[Symbol.asyncIterator])}function U(t){return new TypeError("You provided "+(null!==t&&"object"==typeof t?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var H="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function N(t){return s(null==t?void 0:t[H])}function F(t){return function(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,o=r.apply(t,e||[]),i=[];return n={},c("next"),c("throw"),c("return"),n[Symbol.asyncIterator]=function(){return this},n;function c(t){o[t]&&(n[t]=function(e){return new Promise((function(r,n){i.push([t,e,r,n])>1||s(t,e)}))})}function s(t,e){try{(r=o[t](e)).value instanceof u?Promise.resolve(r.value.v).then(a,l):f(i[0][2],r)}catch(t){f(i[0][3],t)}var r}function a(t){s("next",t)}function l(t){s("throw",t)}function f(t,e){t(e),i.shift(),i.length&&s(i[0][0],i[0][1])}}(this,arguments,(function(){var e,n,o;return r(this,(function(r){switch(r.label){case 0:e=t.getReader(),r.label=1;case 1:r.trys.push([1,,9,10]),r.label=2;case 2:return[4,u(e.read())];case 3:return n=r.sent(),o=n.value,n.done?[4,u(void 0)]:[3,5];case 4:return[2,r.sent()];case 5:return[4,u(o)];case 6:return[4,r.sent()];case 7:return r.sent(),[3,2];case 8:return[3,10];case 9:return e.releaseLock(),[7];case 10:return[2]}}))}))}function W(t){return s(null==t?void 0:t.getReader)}function q(t){if(t instanceof R)return t;if(null!=t){if($(t))return i=t,new R((function(t){var e=i[L]();if(s(e.subscribe))return e.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(c(t))return o=t,new R((function(t){for(var e=0;e<o.length&&!t.closed;e++)t.next(o[e]);t.complete()}));if(a(t))return r=t,new R((function(t){r.then((function(e){t.closed||(t.next(e),t.complete())}),(function(e){return t.error(e)})).then(null,w)}));if(D(t))return B(t);if(N(t))return e=t,new R((function(t){var r,o;try{for(var i=n(e),u=i.next();!u.done;u=i.next()){var c=u.value;if(t.next(c),t.closed)return}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}t.complete()}));if(W(t))return B(F(t))}var e,r,o,i;throw U(t)}function B(t){return new R((function(e){(function(t,e){var o,i,u,c,s,a,l,f;return s=this,a=void 0,f=function(){var s,a;return r(this,(function(r){switch(r.label){case 0:r.trys.push([0,5,6,11]),o=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,r=t[Symbol.asyncIterator];return r?r.call(t):(t=n(t),e={},o("next"),o("throw"),o("return"),e[Symbol.asyncIterator]=function(){return this},e);function o(r){e[r]=t[r]&&function(e){return new Promise((function(n,o){!function(t,e,r,n){Promise.resolve(n).then((function(e){t({value:e,done:r})}),e)}(n,o,(e=t[r](e)).done,e.value)}))}}}(t),r.label=1;case 1:return[4,o.next()];case 2:if((i=r.sent()).done)return[3,4];if(s=i.value,e.next(s),e.closed)return[2];r.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=r.sent(),u={error:a},[3,11];case 6:return r.trys.push([6,,9,10]),i&&!i.done&&(c=o.return)?[4,c.call(o)]:[3,8];case 7:r.sent(),r.label=8;case 8:return[3,10];case 9:if(u)throw u.error;return[7];case 10:return[7];case 11:return e.complete(),[2]}}))},new((l=void 0)||(l=Promise))((function(t,e){function r(t){try{o(f.next(t))}catch(t){e(t)}}function n(t){try{o(f.throw(t))}catch(t){e(t)}}function o(e){var o;e.done?t(e.value):(o=e.value,o instanceof l?o:new l((function(t){t(o)}))).then(r,n)}o((f=f.apply(s,a||[])).next())}))})(t,e).catch((function(t){return e.error(t)}))}))}function Y(t){return function(e){if(function(t){return s(null==t?void 0:t.lift)}(e))return e.lift((function(e){try{return t(e,this)}catch(t){this.error(t)}}));throw new TypeError("Unable to lift unknown Observable type")}}function G(t,e,r,n,o){return new X(t,e,r,n,o)}var X=function(t){function r(e,r,n,o,i,u){var c=t.call(this,e)||this;return c.onFinalize=i,c.shouldUnsubscribe=u,c._next=r?function(t){try{r(t)}catch(t){e.error(t)}}:t.prototype._next,c._error=o?function(t){try{o(t)}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._error,c._complete=n?function(){try{n()}catch(t){e.error(t)}finally{this.unsubscribe()}}:t.prototype._complete,c}return e(r,t),r.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;t.prototype.unsubscribe.call(this),!r&&(null===(e=this.onFinalize)||void 0===e||e.call(this))}},r}(T);function J(t,e){return Y((function(r,n){var o=null,i=0,u=!1,c=function(){return u&&!o&&n.complete()};r.subscribe(G(n,(function(r){null==o||o.unsubscribe();var u=0,s=i++;q(t(r,s)).subscribe(o=G(n,(function(t){return n.next(e?e(r,t,s,u++):t)}),(function(){o=null,c()})))}),(function(){u=!0,c()})))}))}function K(t,e,r,n,o){void 0===n&&(n=0),void 0===o&&(o=!1);var i=e.schedule((function(){r(),o?t.add(this.schedule(null,n)):this.unsubscribe()}),n);if(t.add(i),!o)return i}function Q(t,e){return void 0===e&&(e=0),Y((function(r,n){r.subscribe(G(n,(function(r){return K(n,t,(function(){return n.next(r)}),e)}),(function(){return K(n,t,(function(){return n.complete()}),e)}),(function(r){return K(n,t,(function(){return n.error(r)}),e)})))}))}function V(t,e){return void 0===e&&(e=0),Y((function(r,n){n.add(t.schedule((function(){return r.subscribe(n)}),e))}))}function Z(t,e){if(!t)throw new Error("Iterable cannot be null");return new R((function(r){K(r,e,(function(){var n=t[Symbol.asyncIterator]();K(r,e,(function(){n.next().then((function(t){t.done?r.complete():r.next(t.value)}))}),0,!0)}))}))}function tt(t,e){return e?function(t,e){if(null!=t){if($(t))return function(t,e){return q(t).pipe(V(e),Q(e))}(t,e);if(c(t))return function(t,e){return new R((function(r){var n=0;return e.schedule((function(){n===t.length?r.complete():(r.next(t[n++]),r.closed||this.schedule())}))}))}(t,e);if(a(t))return function(t,e){return q(t).pipe(V(e),Q(e))}(t,e);if(D(t))return Z(t,e);if(N(t))return function(t,e){return new R((function(r){var n;return K(r,e,(function(){n=t[H](),K(r,e,(function(){var t,e,o;try{e=(t=n.next()).value,o=t.done}catch(t){return void r.error(t)}o?r.complete():r.next(e)}),0,!0)})),function(){return s(null==n?void 0:n.return)&&n.return()}}))}(t,e);if(W(t))return function(t,e){return Z(F(t),e)}(t,e)}throw U(t)}(t,e):q(t)}function et(t,e){return Y((function(r,n){var o=0;r.subscribe(G(n,(function(r){n.next(t.call(e,r,o++))})))}))}var rt=l((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),nt=function(t){function r(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return e(r,t),r.prototype.lift=function(t){var e=new ot(this,this);return e.operator=t,e},r.prototype._throwIfClosed=function(){if(this.closed)throw new rt},r.prototype.next=function(t){var e=this;E((function(){var r,o;if(e._throwIfClosed(),!e.isStopped){e.currentObservers||(e.currentObservers=Array.from(e.observers));try{for(var i=n(e.currentObservers),u=i.next();!u.done;u=i.next())u.value.next(t)}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=i.return)&&o.call(i)}finally{if(r)throw r.error}}}}))},r.prototype.error=function(t){var e=this;E((function(){if(e._throwIfClosed(),!e.isStopped){e.hasError=e.isStopped=!0,e.thrownError=t;for(var r=e.observers;r.length;)r.shift().error(t)}}))},r.prototype.complete=function(){var t=this;E((function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var e=t.observers;e.length;)e.shift().complete()}}))},r.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(r.prototype,"observed",{get:function(){var t;return(null===(t=this.observers)||void 0===t?void 0:t.length)>0},enumerable:!1,configurable:!0}),r.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},r.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},r.prototype._innerSubscribe=function(t){var e=this,r=this,n=r.hasError,o=r.isStopped,i=r.observers;return n||o?h:(this.currentObservers=null,i.push(t),new d((function(){e.currentObservers=null,p(i,t)})))},r.prototype._checkFinalizedStatuses=function(t){var e=this,r=e.hasError,n=e.thrownError,o=e.isStopped;r?t.error(n):o&&t.complete()},r.prototype.asObservable=function(){var t=new R;return t.source=this,t},r.create=function(t,e){return new ot(t,e)},r}(R),ot=function(t){function r(e,r){var n=t.call(this)||this;return n.destination=e,n.source=r,n}return e(r,t),r.prototype.next=function(t){var e,r;null===(r=null===(e=this.destination)||void 0===e?void 0:e.next)||void 0===r||r.call(e,t)},r.prototype.error=function(t){var e,r;null===(r=null===(e=this.destination)||void 0===e?void 0:e.error)||void 0===r||r.call(e,t)},r.prototype.complete=function(){var t,e;null===(e=null===(t=this.destination)||void 0===t?void 0:t.complete)||void 0===e||e.call(t)},r.prototype._subscribe=function(t){var e,r;return null!==(r=null===(e=this.source)||void 0===e?void 0:e.subscribe(t))&&void 0!==r?r:h},r}(nt),it={now:function(){return(it.delegate||Date).now()},delegate:void 0},ut=function(t){function r(e,r,n){void 0===e&&(e=1/0),void 0===r&&(r=1/0),void 0===n&&(n=it);var o=t.call(this)||this;return o._bufferSize=e,o._windowTime=r,o._timestampProvider=n,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=r===1/0,o._bufferSize=Math.max(1,e),o._windowTime=Math.max(1,r),o}return e(r,t),r.prototype.next=function(e){var r=this,n=r.isStopped,o=r._buffer,i=r._infiniteTimeWindow,u=r._timestampProvider,c=r._windowTime;n||(o.push(e),!i&&o.push(u.now()+c)),this._trimBuffer(),t.prototype.next.call(this,e)},r.prototype._subscribe=function(t){this._throwIfClosed(),this._trimBuffer();for(var e=this._innerSubscribe(t),r=this._infiniteTimeWindow,n=this._buffer.slice(),o=0;o<n.length&&!t.closed;o+=r?1:2)t.next(n[o]);return this._checkFinalizedStatuses(t),e},r.prototype._trimBuffer=function(){var t=this,e=t._bufferSize,r=t._timestampProvider,n=t._buffer,o=t._infiniteTimeWindow,i=(o?1:2)*e;if(e<1/0&&i<n.length&&n.splice(0,n.length-i),!o){for(var u=r.now(),c=0,s=1;s<n.length&&n[s]<=u;s+=2)c=s;c&&n.splice(0,c+1)}},r}(nt);function ct(t,e,r){return void 0===r&&(r=1/0),s(e)?ct((function(r,n){return et((function(t,o){return e(r,t,n,o)}))(q(t(r,n)))}),r):("number"==typeof e&&(r=e),Y((function(e,n){return function(t,e,r,n,o,i,u,c){var s=[],a=0,l=0,f=!1,p=function(){!f||s.length||a||e.complete()},d=function(t){return a<n?h(t):s.push(t)},h=function(t){a++;var o=!1;q(r(t,l++)).subscribe(G(e,(function(t){e.next(t)}),(function(){o=!0}),void 0,(function(){if(o)try{a--;for(;s.length&&a<n;)t=void 0,t=s.shift(),h(t);p()}catch(t){e.error(t)}var t})))};return t.subscribe(G(e,d,(function(){f=!0,p()}))),function(){}}(e,n,t,r)})))}var st=Array.isArray;var at=["addListener","removeListener"],lt=["addEventListener","removeEventListener"],ft=["on","off"];function pt(t,e,r,n){if(s(r)&&(n=r,r=void 0),n)return pt(t,e,r).pipe((u=n,et((function(t){return function(t,e){return st(e)?t.apply(void 0,i([],o(e))):t(e)}(u,t)}))));var u,a=o(function(t){return s(t.addEventListener)&&s(t.removeEventListener)}(t)?lt.map((function(n){return function(o){return t[n](e,o,r)}})):function(t){return s(t.addListener)&&s(t.removeListener)}(t)?at.map(dt(t,e)):function(t){return s(t.on)&&s(t.off)}(t)?ft.map(dt(t,e)):[],2),l=a[0],f=a[1];if(!l&&c(t))return ct((function(t){return pt(t,e,r)}))(q(t));if(!l)throw new TypeError("Invalid event target");return new R((function(t){var e=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t.next(1<e.length?e:e[0])};return l(e),function(){return f(e)}}))}function dt(t,e){return function(r){return function(n){return t[r](e,n)}}}function ht(t){return t[t.length-1]}function vt(t){return(e=ht(t))&&s(e.schedule)?t.pop():void 0;var e}function bt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(void 0===(r=1)&&(r=1/0),ct(z,r))(tt(t,vt(t)));var r}function yt(t,{id:e,classes:r,styles:n,attrs:o,content:i,parent:u}={}){const c=document.createElement(t);return void 0!==e&&(c.id=e),void 0!==r&&r.forEach((t=>c.classList.add(t))),void 0!==n&&Object.assign(c.style,n),void 0!==o&&Object.entries(o).forEach((([t,e])=>c.setAttribute(t,e))),void 0!==u&&u.appendChild(c),"string"==typeof i&&(c.textContent=i),Array.isArray(i)&&i.forEach((t=>c.appendChild(t))),c}function mt(t,e=10){return new Promise((r=>{const n=setInterval((()=>{t()&&(clearInterval(n),r())}),e)}))}const wt=document.createElement("textarea");class gt extends HTMLElement{disconnect$=new nt;input;count;get value(){return this.input.value}set value(t){this.input.value=t,this.input.dispatchEvent(new Event("input"))}get disabled(){return this.input.disabled}set disabled(t){this.input.disabled=t}constructor(t,e){super(),this.style.display="grid",this.input=yt("input",{attrs:{name:t}}),this.count=yt("span",{content:"character count: 0",styles:{textAlign:"right"}}),this.appendChild(yt("label",{attrs:{for:t},styles:{letterSpacing:"1px"},content:e})),this.appendChild(this.input),this.appendChild(this.count)}get change$(){return pt(this.input,"input").pipe(et((({target:t})=>t.value)),function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r=vt(t);return Y((function(e,n){(r?bt(t,e,r):bt(t,e)).subscribe(n)}))}(this.input.value),(t=this.disconnect$,Y((function(e,r){q(t).subscribe(G(r,(function(){return r.complete()}),g)),!r.closed&&e.subscribe(r)}))));var t}connectedCallback(){this.change$.pipe(et((t=>{return[t.length,(e=t,wt.innerHTML=e,wt.value).length];var e}))).subscribe((([t,e])=>{this.count.textContent=`character count: ${t}`,e!==t&&(this.count.textContent+=` (${e} once decoded)`)}))}disconnectedCallback(){this.disconnect$.next(!0)}}async function xt(){return await mt((()=>document.querySelectorAll("img.gwt-Image").length>=3)),Array.from(document.querySelectorAll("img.gwt-Image")).at(-1).dispatchEvent(new MouseEvent("click"))}async function _t(){return null===document.querySelector("textarea")&&await xt(),document.querySelector("textarea")}customElements.define("charcount-input",gt);let St=null;const Et=new MutationObserver((t=>t.forEach((()=>{St!==document.location.href&&(St=document.location.href,/^#(CommissionOrder|ORDER):C?\d+(-\d+)?$/.test(window.location.hash)&&function(){const t=yt("div",{parent:document.body,styles:{position:"fixed",top:"10vh",right:"0px",transform:"translate(100%)",background:"ghostwhite",color:"darkSlateGrey",border:"1px solid #ff9900",borderRight:"0",borderRadius:"0 0 0 10px",filter:"drop-shadow(0 3px 6px rgba(0,0,0,0.16)) drop-shadow(0 3px 6px rgba(0,0,0,0.23))",transition:"transform 150ms ease-out"}});yt("button",{parent:t,content:"◀",styles:{height:"50px",width:"60px",background:"#ffcc66",color:"darkSlateGrey",cursor:"pointer",position:"absolute",top:"-1px",left:"0",transform:"translate(-100%)",border:"1px solid #ff9900",borderRight:"0",borderRadius:"10px 0 0 10px"}}).addEventListener("click",(function(){t.style.transform="◀"===this.textContent?"translate(0%)":"translate(100%)",this.textContent="◀"===this.textContent?"▶":"◀"}));const e=yt("form",{parent:t,attrs:{action:"javascript:void(0)"},styles:{display:"flex",flexDirection:"column",justifyContent:"stretch",gap:"5px",margin:"20px",width:"350px"}}),r=new gt("search","Search string"),n=new gt("replace","Replacement"),u=yt("button",{content:"No matches",attrs:{type:"submit",disabled:"true"}}),c=yt("button",{content:"Undo",attrs:{disabled:"true"}});async function a(t,e){const o=await _t();o.value=t,o.dispatchEvent(new Event("change",{bubbles:!0})),r.disabled=!0,n.disabled=!0,u.disabled=!0,c.disabled=!0,await mt((()=>-1!==document.body.innerHTML.search("XML wird geprueft und formatiert"))),await mt((()=>-1===document.body.innerHTML.search("XML wird geprueft und formatiert"))),r.value="",n.value="",r.disabled=!1,n.disabled=!1,u.disabled=!1,c.disabled=!e,await xt()}e.appendChild(r),e.appendChild(n),yt("div",{parent:e,content:[u,c],styles:{background:"rgb(195, 217, 255)",margin:"5px -20px -20px",padding:"12px 20px 12px",borderTop:"1px solid rgb(135, 179, 255)",borderBottomLeftRadius:"10px",display:"grid",gridTemplate:"auto / auto auto",gap:"10px"}}),r.change$.pipe(J((t=>tt(_t()).pipe(et((e=>[e,t])))))).subscribe((([t,e])=>{const r=0===e.length?0:t.value.match(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"))?.length??0;u.textContent=r?`Replace ${r} matches`:"No matches",u.disabled=!r}));const l=new ut(1);pt(u,"click").pipe(J((()=>tt(_t()).pipe(et((t=>[t.value,t.value.replaceAll(r.value,n.value)])))))).subscribe(l),l.subscribe((([,t])=>{a(t,!0)})),pt(c,"click").pipe(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var r,n=s(ht(r=t))?r.pop():void 0;return Y((function(e,r){for(var u=t.length,c=new Array(u),s=t.map((function(){return!1})),a=!1,l=function(e){q(t[e]).subscribe(G(r,(function(t){c[e]=t,a||s[e]||(s[e]=!0,(a=s.every(z))&&(s=null))}),g))},f=0;f<u;f++)l(f);e.subscribe(G(r,(function(t){if(a){var e=i([t],o(c));r.next(n?n.apply(void 0,i([],o(e))):e)}})))}))}(l)).subscribe((([,[t]])=>{a(t,!1)}))}())}))));Et.observe(document.body,{childList:!0,subtree:!0})})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment