Last active
September 17, 2019 04:11
-
-
Save Pinjasaur/a2e77903dbc8be1e9340e2669d2278a8 to your computer and use it in GitHub Desktop.
Bookmarklet to copy a shareable URL of a (Mass)drop.com product page (appends "?mode=guest_open") to href so unregistered users can view the page. Firefox doesn't allow `execCommand` in non-user contexts i.e. from a bookmarklet so a `prompt` is gene
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
| javascript:void(function() { | |
| "use strict"; | |
| // Check for valid URL | |
| if (/(mass)?drop.com\/buy\/.+/.test(location.href)) { | |
| var textarea = document.createElement("textarea"); | |
| // Hide the textarea | |
| // Can't be 'display: none' since `execCommand` needs to be | |
| // "user initiated" (e.g. cannot interact with 'display: none') | |
| textarea.style.position = "absolute"; | |
| textarea.style.overflow = "hidden"; | |
| textarea.style.clip = "rect(0 0 0 0)"; | |
| textarea.style.height = "1px"; | |
| textarea.style.width = "1px"; | |
| textarea.style.margin = "-1px"; | |
| textarea.style.padding = "0"; | |
| textarea.style.border = "0"; | |
| textarea.value = (location.protocol + "//" + location.hostname + location.pathname + "?mode=guest_open"); | |
| document.body.appendChild(textarea); | |
| // Handle Firefox by displaying a `prompt` | |
| if (/firefox/i.test(navigator.userAgent)) { | |
| prompt("Copy to clipboard", textarea.value); | |
| } else { | |
| try { | |
| textarea.select(); | |
| document.execCommand("copy"); | |
| } catch (e) { | |
| prompt("Copy to clipboard", textarea.value); | |
| } | |
| } | |
| document.body.removeChild(textarea); | |
| } | |
| })(); |
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
| javascript:void(function(){"use strict";if(/(mass)?drop.com\/buy\/.+/.test(location.href)){var textarea=document.createElement("textarea");textarea.style.position="absolute";textarea.style.overflow="hidden";textarea.style.clip="rect(0 0 0 0)";textarea.style.height="1px";textarea.style.width="1px";textarea.style.margin="-1px";textarea.style.padding="0";textarea.style.border="0";textarea.value=(location.protocol+"//"+location.hostname+location.pathname+"?mode=guest_open");document.body.appendChild(textarea);if(/firefox/i.test(navigator.userAgent)){prompt("Copy to clipboard",textarea.value)}else{try{textarea.select();document.execCommand("copy")}catch(e){prompt("Copy to clipboard",textarea.value)}}document.body.removeChild(textarea)}})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment