-
-
Save hyuki/ca56f989939a3b6a70c49a7d231db3d6 to your computer and use it in GitHub Desktop.
LinkMD.js - ブラウザで見ているWebページのタイトルとURLをMarkdown形式でクリップボードに保存するBookmarklet(LinkMD.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 = "white"; | |
div.style.backgroundColor = "#1976D2"; | |
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}](${url})`; | |
saveToClipboard(text); | |
} | |
start(); |
Author
hyuki
commented
Feb 22, 2022
- ブラウザで見ているWebページのタイトルとURLをMarkdown形式でクリップボードに保存するBookmarklet(LinkMD.js)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment