Last active
July 19, 2019 00:15
-
-
Save davidmerrick/534c20670a56464044adc7bae48e9f19 to your computer and use it in GitHub Desktop.
CaviarMe bookmarklet
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 characters
// Converts a Caviar group order link to a shareable link | |
function copyText(a){ | |
var b=document.createElement("textarea"); | |
c=document.getSelection(); | |
b.textContent=a; | |
document.body.appendChild(b); | |
c.removeAllRanges(); | |
b.select(); | |
document.execCommand("copy"); | |
c.removeAllRanges(); | |
document.body.removeChild(b) | |
} | |
function caviarMe(){ | |
let corporateLink; | |
try { | |
corporateLink = document.getElementById("js-cc-shared-cart-link-url").value; | |
} catch(err){ | |
alert("Couldn't find group link on the page. Are you on the view cart page?"); | |
} | |
let shareLink = corporateLink.replace(/teams\/.*\/group-orders\//, "carts/").replace("/checkout", ""); | |
copyText(shareLink) | |
alert("Copied good link!"); | |
} | |
caviarMe(); | |
// Minified via https://chriszarate.github.io/bookmarkleter/ | |
javascript:void%20function(){function%20a(d){var%20a=document.createElement(%22textarea%22);c=document.getSelection(),a.textContent=d,document.body.appendChild(a),c.removeAllRanges(),a.select(),document.execCommand(%22copy%22),c.removeAllRanges(),document.body.removeChild(a)}(function(){let%20b;try{b=document.getElementById(%22js-cc-shared-cart-link-url%22).value}catch(a){alert(%22Couldn't%20find%20group%20link%20on%20the%20page.%20Are%20you%20on%20the%20view%20cart%20page%3F%22)}let%20d=b.replace(/teams\/.*\/group-orders\//,%22carts/%22).replace(%22/checkout%22,%22%22);a(d),alert(%22Copied%20good%20link!%22)})()}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment