Skip to content

Instantly share code, notes, and snippets.

@hyuki
Created December 21, 2022 07:51
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyuki/972cbe696f383cb1051ec47dd8e5f3fd to your computer and use it in GitHub Desktop.
Save hyuki/972cbe696f383cb1051ec47dd8e5f3fd to your computer and use it in GitHub Desktop.
ShareToMastodon.js - ブラウザで見ているWebページをマストドンに投稿するブックマークレット
/*
* ShareToMastodon.js
* ブラウザで見ているWebページをマストドンに投稿するブックマークレット
* cf. https://fedibird.com/@noellabo/109549491307414163
*/
function start() {
const server = 'mastodon.example.com';
const visibility = 'public';
const title = document.title;
const url = document.URL;
const text = encodeURIComponent(`${title}\r\n${url}`);
window.open(`https://${server}/share?visibility=${visibility}&text=${text}`);
}
start();
@hyuki
Copy link
Author

hyuki commented Dec 21, 2022

ブックマークレットに変換するときにはこちらのサイトを使っています。

◆Bookmarklet Creator with Script Includer - Peter Coles
https://mrcoles.com/bookmarklet/

@hyuki
Copy link
Author

hyuki commented Dec 21, 2022

◆結城浩@social.hyuki.net: "のえるさんのブックマークレットを私がよく使う形式に直しました…" - 結城浩のマストドン
https://social.hyuki.net/@hyuki/109550580576172716

@hyuki
Copy link
Author

hyuki commented Dec 27, 2022

参照時のタイトルを入力できるように修正したものです。

/*
 * ShareToMastodon.js
 * ブラウザで見ているWebページをマストドンに投稿するブックマークレット
 * cf. https://fedibird.com/@noellabo/109549491307414163
 */

function start() {
  const server = 'mastodon.example.com';
  const visibility = 'public';
  const url = document.URL;
  let title = prompt("URL投稿タイトル(BSですべて削除すると「参照:」になります)。", '◆' + document.title);
  if (title == '') {
    title = '参照:';
  }
  const text = encodeURIComponent(`\r\n${title}\r\n${url}`);
  window.open(`https://${server}/share?visibility=${visibility}&text=${text}`);
}

start();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment