Created
July 30, 2021 01:21
-
-
Save htakeuchi/43f0fefe6ab9617ccd595c1b38626b25 to your computer and use it in GitHub Desktop.
表示中のページのURL、タイトル、選択範囲をクロップボードへコピーするBookmarklet
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
(() => { | |
const main = () => { | |
const textAreaElement = document.createElement("textarea"); | |
textAreaElement.textContent = getUrlInfo(); | |
const bodyElement = document.getElementsByTagName("body")[0]; | |
bodyElement.appendChild(textAreaElement); | |
textAreaElement.select(); | |
const isSuccessCopy = document.execCommand('copy'); | |
bodyElement.removeChild(textAreaElement); | |
}; | |
const getUrlInfo = () => { | |
let title = document.title; | |
const replacedStrings = { | |
':': ':', | |
'\\[': '[', | |
'\\]': ']', | |
'\\|': '|' | |
}; | |
for (let key in replacedStrings) { | |
title = title.replace(new RegExp(key, 'g'), replacedStrings[key]); | |
} | |
var q = ''; | |
if (String(document.getSelection()).length > 0) { | |
q = '“' + document.getSelection() + '”\n\n'; | |
} | |
return q + title + '\n' + document.URL + '\n'; | |
}; | |
main(); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment