Skip to content

Instantly share code, notes, and snippets.

@simonboak
Created August 7, 2019 15:47
Show Gist options
  • Save simonboak/e684a0cf9165f306d48fd56427665999 to your computer and use it in GitHub Desktop.
Save simonboak/e684a0cf9165f306d48fd56427665999 to your computer and use it in GitHub Desktop.
<a class="bookmarklet" href="javascript:(function()%7Bjavascript%3A%20(function%20()%20%7Bvar%20isTrello%3Bvar%20estimate%3Bvar%20authenticationSuccess%20%3D%20function%20()%20%7Bconsole.log(%22Successful%20authentication%22)%3B%7D%3Bvar%20authenticationFailure%20%3D%20function%20()%20%7Bconsole.log(%22Failed%20authentication%22)%3B%7D%3Bvar%20trelloSuccess%20%3D%20function%20(result)%20%7Bconsole.log(%22Trello%20Success%22)%3B%2F*var%20textareaResponse%3Bif(isTrello)%20%7BtextareaResponse%20%3D%20%24(%22textarea.js-new-comment-input%22).first()%3BtextareaResponse.html(%22Hi%2C%5Cn%5CnThis%20%5Bticket%5D(%22%20%2B%20result.url%20%2B%20%22)%20has%20been%20logged%20in%20the%20%5BDev%20Task%20Manager%5D(http%3A%2F%2Fwww.80d-stage.com%2Fhome%2Fmanager).%20Please%20manage%20it's%20priority%20there.%5CnWe%20are%20roughly%20estimating%20the%20development%20time%20to%20be%20around%20**%22%20%2B%20estimate%20%2B%20%22**.%5Cn%5CnCheers%22)%3BtextareaResponse.css(%22height%22%2C%22180px%22)%3B%7Delse%20%7Bvar%20editableElement%20%3D%20%24(%22div.fr-element%22).first()%3BeditableElement.prepend(%22%3Cdiv%20dir%3D%5C%22ltr%5C%22%3E%3Cp%3EHi%2C%3C%2Fp%3E%20%3Cp%3E%3Cbr%20%2F%3E%3C%2Fp%3E%20%3Cp%3EThis%20ticket%20has%20been%20logged%20in%20the%20%3Ca%20href%3D%5C%22http%3A%2F%2Fwww.80d-stage.com%2Fhome%2Fmanager%5C%22%3EDev%20Task%20Manager%3C%2Fa%3E.%20Please%20manage%20it's%20priority%20there.%3C%2Fp%3E%20%3Cp%3EWe%20are%20roughly%20estimating%20the%20development%20time%20to%20be%20around%20%22%20%2B%20estimate%20%2B%20%22.%20%3C%2Fp%3E%20%3Cp%3E%3Cbr%20%2F%3E%3C%2Fp%3E%20%3Cp%3ECheers%2C%3C%2Fp%3E%3Cp%3EFilipe%3C%2Fp%3E%3C%2Fdiv%3E%22)%3BeditableElement.html(editableElement.html().replace('%2F'%2C''))%3B%7D*%2F%7D%3Bvar%20trelloError%20%3D%20function%20(response)%20%7Bconsole.log(%22Trello%20Error%3A%20%22%20%2B%20response.responseText)%3B%7D%3BstartExtraction()%3Bfunction%20startExtraction()%20%7Bif%20(!window.getSelection%20%26%26%20(document.selection%20%26%26%20document.selection.type%20!%3D%20%22Control%22))%20%7Bwindow.getSelection%20%3D%20document.selection.createRange%3B%7Dif(!%24.getScript)%20%7BloadScript(%22https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F1%2Fjquery.min.js%22%2C%20createCard)%3B%7Delse%20%7BcreateCard()%3B%7D%7Dfunction%20loadScript(url%2C%20callback)%20%7Bvar%20head%20%3D%20document.getElementsByTagName(%22head%22)%5B0%5D%3Bvar%20script%20%3D%20document.createElement(%22script%22)%3Bscript.src%20%3D%20url%3Bvar%20done%20%3D%20false%3Bscript.onload%20%3D%20script.onreadystatechange%20%3D%20function%20()%20%7Bif%20(!done%20%26%26%20(!this.readyState%7C%7C%20this.readyState%20%3D%3D%20%22loaded%22%7C%7C%20this.readyState%20%3D%3D%20%22complete%22))%20%7Bdone%20%3D%20true%3Bcallback()%3Bscript.onload%20%3D%20script.onreadystatechange%20%3D%20null%3Bhead.removeChild(script)%3B%7D%7D%3Bhead.appendChild(script)%3B%7Dfunction%20createCard()%20%7Bvar%20mdConvert%20%3D%20%24.getScript(%22https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2FEndzoneSoftware%2FCDN%2Fto-markdown.min.js%22)%3Bvar%20trelloClient%20%3D%20%24.getScript(%22https%3A%2F%2Fapi.trello.com%2F1%2Fclient.js%3Fkey%3D967740853874c239660c7154e10f84f6%22)%3B%24.when(mdConvert%2C%20trelloClient).then(function%20()%20%7BTrello.authorize(%7Bname%3A%20%2280%20DAYS%20extract%20to%20Trello%22%2Cscope%3A%20%7Bread%3A%20true%2Cwrite%3A%20true%7D%2Ctype%3A%20%22popup%22%2Cexpiration%3A%20%22never%22%2Csuccess%3A%20function%20()%20%7Bconsole.log(%22Successful%20authentication%22)%3BextractAndCreateCard()%3B%7D%2Cerror%3A%20authenticationFailure%7D)%3B%7D)%7Dfunction%20extractAndCreateCard()%20%7B%2F*estimate%20%3D%20prompt(%22Please%20enter%20your%20development%20time%20estimate%20for%20this%20task%3A%22%2C%20%2230%20mins%22)%3Bif(estimate%20%3D%3D%20null)%20%7Breturn%3B%7Dvar%20cardName%20%3D%20''%3Bif(document.URL.lastIndexOf('%2F%2Fsupport.eighty-days.com')%20!%3D%20-1)%20%7BisTrello%20%3D%20false%3BcardName%20%3D%20getCardNameFromFreshdesk()%3B%7Delse%20if(document.URL.lastIndexOf('%2F%2Ftrello.com')%20!%3D%20-1)%20%7BisTrello%20%3D%20true%3BcardName%20%3D%20%20getCardNameFromTrello()%3B%7DcardName%20%3D%20prompt(%22Please%20name%20the%20card%3A%22%2C%20cardName)%3Bif(cardName%20%3D%3D%20null)%20%7Breturn%3B%7D*%2Fvar%20url%20%3D%20window.location.href%3Bvar%20targetListId%20%3D%20'5909c6870994a8a700024023'%3Bvar%20html%20%3D%20getHTMLOfSelection()%3Bif%20(!html.trim())%20%7Bhtml%20%3D%20%24(%22.description-content%20.current%22).html()%3B%7Dvar%20ticketId%20%3D%20%24('.breadcrumb__item.active').text().trim()%3Bvar%20ticketRequester%20%3D%20%24('.ticket-created-info%20.user').text().trim()%3Bvar%20cardName%20%3D%20%22%5B%23%22%20%2B%20ticketId%20%2B%20%22%5D%20%22%20%2B%20%24('.ticket-subject-heading').text().trim()%3Bvar%20markdown%20%3D%20%22Development%20time%20estimate%3A%20%22%20%2B%20estimate%20%2B%20%22%3Cbr%20%2F%3EFrom%20%22%20%2B%20url%20%2B%20%20%22%5Cn%5Cn%3Cbr%20%2F%3E%3Cblockquote%3E%22%20%2B%20html%20%2B%20%22%3C%2Fblockquote%3E%22%3Bvar%20markdown%20%3D%20%22%3Cstrong%3ETicket%20ID%3A%3C%2Fstrong%3E%20%23%22%20%2B%20ticketId%20%2B%20%22%20%3Cbr%20%2F%3E%3Cstrong%3ERequester%3A%3C%2Fstrong%3E%20%22%20%2B%20ticketRequester%3Bvar%20labels%20%3D%20%5B%5D%3Bvar%20newTaskRequest%20%3D%20%7Bname%3A%20cardName%2CidList%3A%20targetListId%2CidLabels%3A%20labels%2Cdesc%3A%20toMarkdown(markdown)%2CurlSource%3A%20url%7D%3BTrello.post('%2Fcards'%2C%20newTaskRequest%2C%20trelloSuccess%2C%20trelloError)%3B%7Dfunction%20getCardNameFromFreshdesk()%20%7Breturn%20%24(%22.ticket-subject-heading%22).first().text().trim()%3B%7Dfunction%20getCardNameFromTrello()%20%7Bvar%20cardName%20%3D%20%24(%22.mod-card-back-title%22).val()%3Bvar%20boardName%20%3D%20%24(%22.board-header%20.board-header-btn-text%22).first().text()%3Breturn%20boardName%20%2B%20%22%20-%20%22%20%2B%20cardName%3B%7Dfunction%20getHTMLOfSelection()%20%7Bvar%20range%3Bif%20(document.selection%20%26%26%20document.selection.createRange)%20%7Brange%20%3D%20document.selection.createRange()%3Breturn%20range.htmlText%3B%7D%20else%20if%20(window.getSelection)%20%7Bvar%20selection%20%3D%20window.getSelection()%3Bif%20(selection.rangeCount%20%3E%200)%20%7Brange%20%3D%20selection.getRangeAt(0)%3Bvar%20clonedSelection%20%3D%20range.cloneContents()%3Bvar%20div%20%3D%20document.createElement('div')%3Bdiv.appendChild(clonedSelection)%3Breturn%20%24(div).text()%3B%7D%20else%20%7Breturn%20''%3B%7D%7D%20else%20%7Breturn%20''%3B%7D%7D%7D)()%7D)()">Create Card</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment