Skip to content

Instantly share code, notes, and snippets.

@hyuki

hyuki/LinkTXT.js Secret

Created February 23, 2022 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki/215098a794ae5e9c0d5ff9e528bbab04 to your computer and use it in GitHub Desktop.
Save hyuki/215098a794ae5e9c0d5ff9e528bbab04 to your computer and use it in GitHub Desktop.
LinkTXT.js
function initToast() {
const bodies = document.getElementsByTagName("body");
const body = bodies[0];
const div = document.createElement("div");
div.id = "TOAST-IT";
div.innerText = "TOAST-IT";
div.style.position = "fixed";
div.style.zIndex = "5000";
div.style.top = "0px";
div.style.left = "0px";
div.style.padding = "10px";
div.style.margin = "10px";
div.style.borderRadius = "5px";
div.style.display = "none";
div.style.color = "black";
div.style.backgroundColor = "#f7dfa6";
div.style.whiteSpace = "pre-wrap";
div.style.wordWrap = "break-word";
body.append(div);
}
function showToast(s) {
const div = document.getElementById("TOAST-IT");
div.innerText = s;
div.style.display = "block";
setTimeout(function() {
div.style.display = "none";
}, 5000);
}
initToast();
function saveToClipboard(s) {
navigator.clipboard.writeText(s).then(function() {
showToast(`Saved to clipboard:\n----\n${s}\n----\n`);
}, function() {
showToast(`ERROR: ${s} is NOT saved`);
});
}
function start() {
const url = location.href;
const title = document.title;
const text = `${title}\n${url}\n`;
saveToClipboard(text);
}
start();
@hyuki
Copy link
Author

hyuki commented Feb 23, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment