Skip to content

Instantly share code, notes, and snippets.

@dggodfrey
Created April 23, 2020 18:29
Show Gist options
  • Save dggodfrey/b45395eec10186c137403e9b5a85f4b2 to your computer and use it in GitHub Desktop.
Save dggodfrey/b45395eec10186c137403e9b5a85f4b2 to your computer and use it in GitHub Desktop.
Adds basic structure to JIRA ticket
(function() {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function checkElement(element, name) {
return new Promise((resolve, reject) => {
if (element) {
resolve();
} else {
const message = `SNIPPET - element ${name} not found`;
console.warn(message);
reject(message);
}
})
}
/* Just the copied html contents of editableSelector */
const content = `<p>Description: </p><div class="ak-editor-panel" data-panel-type="info"><span class="ak-editor-panel__icon"><span class="sc-iAyFgw dQHGJR" role="img" aria-label="Panel info"><svg width="24" height="24" viewBox="0 0 24 24" focusable="false" role="presentation"><path d="M12 20a8 8 0 1 1 0-16 8 8 0 0 1 0 16zm0-8.5a1 1 0 0 0-1 1V15a1 1 0 0 0 2 0v-2.5a1 1 0 0 0-1-1zm0-1.125a1.375 1.375 0 1 0 0-2.75 1.375 1.375 0 0 0 0 2.75z" fill="currentColor" fill-rule="evenodd"></path></svg></span></span><div class="ak-editor-panel__content"><p><strong>Dev Notes</strong>:<br><br></p><ul class="ak-ul"><li><p><br></p></li></ul></div></div><div class="ak-editor-panel" data-panel-type="warning"><span class="ak-editor-panel__icon"><span class="sc-iAyFgw dQHGJR" role="img" aria-label="Panel warning"><svg width="24" height="24" viewBox="0 0 24 24" focusable="false" role="presentation"><path d="M13.31 5.343l7.359 13.17A1 1 0 0 1 19.796 20H4.204a1 1 0 0 1-.873-1.488l7.36-13.169a1.5 1.5 0 0 1 2.618 0zM12 8.5a1.091 1.091 0 0 0-1.081 1.239l.513 3.766a.573.573 0 0 0 1.136 0l.513-3.766A1.091 1.091 0 0 0 12 8.5zm0 8.63a1.125 1.125 0 1 0 0-2.25 1.125 1.125 0 0 0 0 2.25z" fill="currentColor" fill-rule="evenodd"></path></svg></span></span><div class="ak-editor-panel__content"><p><strong>Dependencies/Gotchas:</strong><br><br></p><ul class="ak-ul"><li><p><br></p></li></ul></div></div><hr contenteditable="false"><p><strong>QA Suggestions:</strong></p><div class="ak-editor-panel" data-panel-type="success"><span class="ak-editor-panel__icon"><span class="sc-iAyFgw dQHGJR" role="img" aria-label="Panel success"><svg width="24" height="24" viewBox="0 0 24 24" focusable="false" role="presentation"><path d="M12 20a8 8 0 1 1 0-16 8 8 0 0 1 0 16zm1.364-10.964l-2.152 4.11-1.543-1.39a1 1 0 1 0-1.338 1.487l2.5 2.25a1 1 0 0 0 1.555-.279l2.75-5.25a1 1 0 0 0-1.772-.928z" fill="currentColor" fill-rule="evenodd"></path></svg></span></span><div class="ak-editor-panel__content"><p><em><strong>automated</strong></em></p><ol class="ak-ol"><li><p>N/A</p></li></ol></div></div><div class="ak-editor-panel" data-panel-type="note"><span class="ak-editor-panel__icon"><span class="sc-iAyFgw dQHGJR" role="img" aria-label="Panel note"><svg width="24" height="24" viewBox="0 0 24 24" focusable="false" role="presentation"><path d="M8 4h8a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2zm1.5 4a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h5a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-5zm0 4a.5.5 0 0 0-.5.5v1a.5.5 0 0 0 .5.5h3a.5.5 0 0 0 .5-.5v-1a.5.5 0 0 0-.5-.5h-3z" fill="currentColor" fill-rule="evenodd"></path></svg></span></span><div class="ak-editor-panel__content"><p><em><strong>manual</strong></em></p><ol class="ak-ol"><li><p><br></p></li></ol></div></div><p><br></p>`;
const descriptionWrapper = 'div[data-test-id*="rich-text.description"] div[class^=ReadViewContentWrapper]';
/* with content, with no content (respectively) */
const descriptionSelector = `${descriptionWrapper} div[role="presentation"], ${descriptionWrapper} button`;
const editableSelector = 'div[data-test-id*="rich-text.editor-container"] div[contenteditable="true"]';
async function RUN() {
console.log('running');
const descriptionElement = document.querySelector(descriptionSelector);
await checkElement(descriptionElement, 'Description Element');
descriptionElement.click();
await sleep(1000);
const editableElement = document.querySelector(editableSelector);
await checkElement(editableElement, 'Editable Element');
editableElement.innerHTML += content;
};
window.RUNJIRADESCRRIPTIONFORMATTER = RUN;
RUN();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment