Skip to content

Instantly share code, notes, and snippets.

@thyngster
Last active October 19, 2020 12:46
Show Gist options
  • Save thyngster/84c4d3a05faaf745996121d1f8297d98 to your computer and use it in GitHub Desktop.
Save thyngster/84c4d3a05faaf745996121d1f8297d98 to your computer and use it in GitHub Desktop.
Enable Share Preview Button . New GTM Preview
(function() {
document.querySelector('.domain-dialog__start-button button').insertAdjacentHTML('afterend', `<button id="share-preview-link" class="btn btn--create" > Share Preview </button>`);
document.querySelector('#share-preview-link').addEventListener("click", function() {
const dummy = document.createElement('p');
dummy.textContent = window.location.href;
document.body.appendChild(dummy);
const range = document.createRange();
range.setStartBefore(dummy);
range.setEndAfter(dummy);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
document.body.removeChild(dummy);
alert("Preview Share Link copied into Clipboard")
}, false);
})()
Create a bookmarkt with the following URL Text:
javascript:document.querySelector%28%22.domain-dialog__start-button%20button%22%29.insertAdjacentHTML%28%22afterend%22%2C%27%3Cbutton%20id%3D%22share-preview-link%22%20class%3D%22btn%20btn--create%22%20%3E%20Share%20Preview%20%3C%2Fbutton%3E%27%29%2Cdocument.querySelector%28%22%23share-preview-link%22%29.addEventListener%28%22click%22%2Cfunction%28%29%7Bconst%20e%3Ddocument.createElement%28%22p%22%29%3Be.textContent%3Dwindow.location.href%2Cdocument.body.appendChild%28e%29%3Bconst%20t%3Ddocument.createRange%28%29%3Bt.setStartBefore%28e%29%2Ct.setEndAfter%28e%29%3Bconst%20n%3Dwindow.getSelection%28%29%3Bn.removeAllRanges%28%29%2Cn.addRange%28t%29%2Cdocument.execCommand%28%22copy%22%29%2Cdocument.body.removeChild%28e%29%2Calert%28%22Preview%20Share%20Link%20copied%20into%20Clipboard%22%29%7D%2C%211%29%3B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment