Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shugo/982318e821d70526d6c7333cc4715c30 to your computer and use it in GitHub Desktop.

Select an option

Save shugo/982318e821d70526d6c7333cc4715c30 to your computer and use it in GitHub Desktop.
閲覧中のWebページをmastodonに共有するためのブックマークレット。デフォルト付与するハッシュタグを決めておいたり、タイトルに含まれるハッシュタグなんかもカバーします。
javascript: (function () {
let title = document.title ? document.title : document.location.pathname.split('/').pop();
const url = document.URL;
const hashtagsearch = /\s*#\S+/g;
const hashsearch = /#/g;
const atsearch = /@/g;
/*
* 投稿先サーバFQDN
* 利用されているサーバに合わせて書き換えてください
*/
const servername = 'social.shugo.net';
/*
* デフォルト公開範囲 public/unlisted/private/direct
* 投稿フォーム画面を開いた後にも変更可能です
*/
const visibility = 'public';
/* タイトルのハッシュ、アットマークを置換してリンク化を回避 */
title = title.replace(hashsearch,'#').replace(atsearch,'@');
/* 本文 タグ文字列はhashtag-barに乗せるため、手前に空行を挟む */
const text = title + '\n' + url;
/* 投稿フォーム画面を開く(ポップアップ) */
window.open(`https://${servername}/share?visibility=${visibility}&text=${encodeURIComponent(text)}`,'_blank','width=640,height=800');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment