-
-
Save hyuki/215098a794ae5e9c0d5ff9e528bbab04 to your computer and use it in GitHub Desktop.
LinkTXT.js
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
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cf.
https://snap.hyuki.net/20220222173746/