Created
October 18, 2020 11:28
-
-
Save kemsakurai/3a0cf756f3e659067325a9d7ac7c3715 to your computer and use it in GitHub Desktop.
WebページをChatworkへ共有する形式でコピーする Tamplermonkeyの UserScript
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
// ==UserScript== | |
// @name Copy page link for Chatwork | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description 閲覧しているブラウザのページをChatworkへの共有向けにコピーする | |
// @author K.Sakurai | |
// @run-at context-menu | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var href = location.href; | |
var text = '[info][title]'+document.title.replace(/([\[\]])/g,'\\$1')+'[/title]'+location.href+'\n'+window.getSelection()+'[/info]'; | |
var temp = document.createElement('div'); | |
temp.appendChild(document.createElement('pre')).textContent = text; | |
var s = temp.style; | |
s.position = 'fixed'; | |
s.left = '-100%'; | |
document.body.appendChild(temp); | |
document.getSelection().selectAllChildren(temp); | |
var result = document.execCommand('copy'); | |
document.body.removeChild(temp); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment