/
missingCommentHandler.min.js
1 lines (1 loc) · 3 KB
/
missingCommentHandler.min.js
1
window.dkr=window.dkr||{},dkr.missingCommentHandler=dkr.missingCommentHandler||{},dkr.missingCommentHandler.missingCommentErrorLabel={de:"Kommentar auf folgendem Pfad erforderlich",en:"Comment is required on path",pl:"Komentarz jest wymagany na ścieżce",it:"Il commento è obbligatorio",sl:"Potrebno je vnesti komentar",ro:"Comentariul este obligatoriu pe calea"},dkr.missingCommentHandler.continueBtnLabel={de:"Weiter",en:"Continue",pl:"Kontynuuj",it:"Procedi",sl:"Nadaljuj",ro:"Mai departe"},dkr.missingCommentHandler.tryAgainPathExecution=function(e){let t=document.getElementById("newCommentText"),n=document.getElementsByClassName("comments-body")[0].firstChild;var o=Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,"value").set;eventObject=new Event("input",{bubbles:!0}),o.call(n,t.value),n.dispatchEvent(eventObject),eventObject=new Event("focusout",{bubbles:!0}),n.dispatchEvent(eventObject),setTimeout((()=>{MoveToNextStep(e)}),100)},dkr.missingCommentHandler.MutationCallback=async function(e,t){if(-1==document.location.href.indexOf("/element/")&&-1==document.location.href.indexOf("/start/")&&(console.log("Disconnecting observer for "+document.location.href),delete dkr.missingCommentHandler.ModalContentObserver,t.disconnect()),null!=document.getElementById("newComment"))return;let n=document.querySelectorAll(".form-error-modal div.form-errors-panel__errors-container__error");if(2!=n.length)return;let o=document.querySelector(".form-error-modal"),r=dkr.missingCommentHandler.missingCommentErrorLabel[window.initModel.userLang.substr(0,2)];if(!r)return void alert("Label for 'missing comment on path' is not defined for language :'"+window.initModel.userLang.substr(0,2));let i=dkr.missingCommentHandler.continueBtnLabel[window.initModel.userLang.substr(0,2)],a=n[1].getAttribute("data-key");if(!a.startsWith(r))return;n[1].insertAdjacentHTML("afterend",'<div id="newComment"><textarea id="newCommentText" class="text-area standard-focus wfFormControl form-control" rows="5" cols="20" ></textarea></div>');let d=a.substring(a.indexOf(":")+1),s=ccls.utils.basicPathInformation.filter((e=>e.title==d.trim())),m=$(".form-error-modal__close-button",o);m.hide();let l=`<button id="missingCommentContinueButton" onClick="dkr.missingCommentHandler.tryAgainPathExecution(${s[0].id})" class="webcon-button animated standard-focus form-error-modal__close-button modal-button th-button-default webcon-button--padding-default standard-focus" data-key="${i}" tabindex="0" type="button"><div class="typography typography-font-size-standard webcon-button__title">${i}</div></button>`;m[0].insertAdjacentHTML("afterend",l)},void 0===dkr.missingCommentHandler.ModalContentObserver&&(dkr.missingCommentHandler.observerCounter=0,dkr.missingCommentHandler.ModalContentObserver=new MutationObserver(dkr.missingCommentHandler.MutationCallback),dkr.missingCommentHandler.ModalContentObserver.observe(document.getElementById("Modals"),{subtree:!0,childList:!0}),console.log("Missing comment observer created")),console.log("Missing comment handler loaded");