Forked from scottcate/Bookmarklet for CDA Web Trends
Last active
June 28, 2018 18:28
-
-
Save spboyer/82250c848d671d058d96101bfc54442f to your computer and use it in GitHub Desktop.
fix documentation typos
This file contains 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 characters
// Directions | |
// Step 1: Click Gist Raw, then Copy/Paste entire gist into Bookmarklets.org/maker/ | |
// Step 2: Change the first 3 variables: alias, event, docs | |
// Step 3: At the bottom of the Bookmarklets.org page, drag the Bookmarklet Hyperlink to your Browser ToolBar | |
// Step 4: Enjoy | |
javascript: | |
( | |
function () { | |
var alias = 'shboyer'; | |
var event = prompt('Enter value for the event', ''); | |
var channel = 'twitter'; | |
function copyToClipboard(text) { | |
var textarea = document.createElement("textarea"); | |
textarea.textContent = text; | |
textarea.style.position = "fixed"; /* Prevent scrolling to bottom of page in MS Edge.*/ | |
document.body.appendChild(textarea); | |
textarea.select(); | |
try { | |
return document.execCommand("copy"); /* Security exception may be thrown by some browsers.*/ | |
} catch (ex) { | |
console.warn("Copy to clipboard failed.", ex); | |
return false; | |
} finally { | |
document.body.removeChild(textarea); | |
} | |
} | |
//Get current URL | |
var baseUrl = document.location.href; | |
//remove current locale for sharing | |
const regex = /microsoft.com\/\w{2}-\w{2}\//g; | |
const subst = 'microsoft.com/'; | |
baseUrl = baseUrl.replace(regex,subst); | |
//respect or ignore currect query string | |
var separator = baseUrl.indexOf('?') > 0 ? '&' : '?'; | |
//respect or ignore hash | |
var hash = ''; | |
var hasHash = baseUrl.indexOf('#'); | |
if (hasHash != -1) { | |
hash = baseUrl.substr(hasHash); | |
baseUrl = baseUrl.replace(hash, ''); | |
} | |
//build final URL | |
var final = baseUrl + separator + 'WT.mc_id=' + event + '-' + channel + '-' + alias + hash; | |
copyToClipboard(final); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment