Skip to content

Instantly share code, notes, and snippets.

@izumiikezaki
Last active February 16, 2021 05:57
Show Gist options
  • Save izumiikezaki/85f5ff238a096c445174eafa2dbee2f1 to your computer and use it in GitHub Desktop.
Save izumiikezaki/85f5ff238a096c445174eafa2dbee2f1 to your computer and use it in GitHub Desktop.
クロームのブックマークレットを使ってSlackに共有するやつ
javascript: (
function () {
const ENDPOINT = 'https://slack.com/api/chat.postMessage';
const TOKEN = 'トークン';
const CHANNEL = '#チャンネル';
const BY = "@SlackのID";
const url = location.href;
fetch(`${ENDPOINT}?token=${TOKEN}`, { method: 'POST', body: EncodeHTMLForm({ channel: CHANNEL, text: `${url} by ${BY}`, link_names: true, unfurl_links: true }), headers: { "Content-Type": "application/x-www-form-urlencoded; charset=utf-8", } });
function EncodeHTMLForm(data) {
const params = [];
for (let name in data) {
let value = data[name];
let param = encodeURIComponent(name) + '=' + encodeURIComponent(value);
params.push(param);
}
return params.join('&').replace(/%20/g, '+');
}
}()
);
javascript: (
function () {
const ENDPOINT = 'https://slack.com/api/chat.postMessage';
const TOKEN = 'トークン';
const CHANNEL = '#チャンネル';
const BY = "@SlackのID";
const url = location.href;
fetch(`${ENDPOINT}?token=${TOKEN}`,
{ method: 'POST',
body: EncodeHTMLForm({
channel: CHANNEL,
text: `${BY} is watching ${url} 👁 👁`,
link_names: true, unfurl_links: true }),
headers: { "Content-Type": "application/x-www-form-urlencoded; charset=utf-8", }
});
function EncodeHTMLForm(data) {
const params = [];
for (let name in data) {
let value = data[name];
let param = encodeURIComponent(name) + '=' + encodeURIComponent(value);
params.push(param);
}
return params.join('&').replace(/%20/g, '+');
}
}()
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment