Last active
March 23, 2021 15:55
-
-
Save maxkerp/3e50164b06598816fe556acf6246543a to your computer and use it in GitHub Desktop.
Revisions
-
maxkerp revised this gist
Feb 8, 2020 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ (function(){ // This snippet is a customized version of the code found on // stackoverflow. Since firefox only copies to the clipboard when the event // was triggered by a user, I had to add the button to the top of the page. // In chrome it might work without the need for a button, directly from a // bookmarklet. See the following for more information. // https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript?page=1&tab=votes#tab-top @@ -32,7 +32,7 @@ }); } const ticketNumber = $('#content h2').first().text().match(/#\d*/)[0]; const ticketTitle = $('#content .subject h3').text(); const textToCopy = `${ticketTitle} ${ticketNumber} - `; @@ -48,7 +48,7 @@ copyTextToClipboardButton( textToCopy, 'Copy Ticket for Tyme', buttonStyle ); })() -
maxkerp created this gist
Feb 8, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ (function(){ // This snippet is a customized version of the code found on // stackoverflow. Since firefox only copies to the clipboard when the event // was triggered by a user, we had to add the button to the top of the page. // In chrome it might work without the need for a button, directly from a // bookmarklet. See the following for more information. // https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript?page=1&tab=votes#tab-top // To create a bookmarklet you might want to use the following: // https://www.yourjs.com/bookmarklet/ function copyTextToClipboardButton(copyText, buttonText, buttonStyle) { // Firefox only copies any text if the code doing it was triggered by a user // event. This is why we have to insert a button at the top of the page. var submitButton = document.createElement("button"); Object.assign(submitButton.style, buttonStyle) submitButton.innerHTML = buttonText document.body.appendChild(submitButton); submitButton.addEventListener('click', function() { navigator.clipboard.writeText(copyText).then(function() { console.log(`Async: Copying to clipboard was successful!\n String was: ${copyText}`); }, function(err) { console.error('Async: Could not copy text: ', err); }); document.body.removeChild(submitButton); }); } const ticketNumber = $('#content h2').text(); const ticketTitle = $('#content .subject h3').text(); const textToCopy = `${ticketTitle} ${ticketNumber} - `; // Will be assigned to HTMLElement.style const buttonStyle = { position: 'fixed', top: 0, left: 0, width: '100%', fontWeight: 'bold' } copyTextToClipboardButton( textToCopy, 'Copy Ticket for ...', buttonStyle ); })()