2
1

More than 3 years have passed since last update.

あるだけで一寸嬉しいちょっとした簡易ブックマークレット(たち)

Last updated at Posted at 2020-06-19

概要

最近自分で作ったブックマークレットの内、
利用頻度が高く、作って良かったと感じたものをいくつか記載。

※『作った』とかいう表現は大げさだけど

ブックマークレットたち

上へ

所謂『1つ上の階層』に移動する。

javascript:(function(){
  window.location.href = window.location.href.replace(/[^\/]+\/?$/g, '');
})();
☝ (ブックマーク登録用)
javascript:(function(){window.location.href = window.location.href.replace(/[^\/]+\/?$/g, '');})();

title

ページ タイトルを入力ダイアログで表示し、コピーを補助する。

title
javascript:(
  function(){window.prompt('page title', document.title);
})();
title (ブックマーク登録用)
javascript:(function(){window.prompt('page title', document.title);})();

(補足)

調べ物などをしていてWEBページをメモる時に
URLと一緒にタイトルも一緒に欲しくなることが多い。
firefoxなどではページのプロパティ画面があったのでchromeだと同様のものがなく、また元々手数も多かった。
ページを非破壊でコピーまですることは出来ないので、
入力ダイアログを代用している形。

picture size

画像の解像度を表示。

picture size
javascript:(function(){
  var img = new Image();
  img.onload = function () {
    Promise.resolve().then(function() {
      window.prompt('width x height', '' + img.width + 'x' + img.height + '');
    });
  };
  img.src = location.href;
})();
picture size (ブックマーク登録用)
javascript:(function(){var img = new Image(); img.onload = function () {Promise.resolve().then(function() { window.prompt('width x height', '' + img.width + 'x' + img.height + '');});}; img.src = location.href;})();

(補足)

一応chromeでもファイル名の末尾に解像度は出ているものの、
ファイル名が長くなる + 沢山タブを開いてると、すぐに見えなくなる。
結果的には再ダウンロードがかかってしまうので、トラフィックにはあまり優しくない。

user agent

そのまま。
javascriptで取得出来るUserAgentを表示。

useragent
javascript:(function(){
  window.prompt('user agent', window.navigator.userAgent);
})();
useragent (ブックマーク登録用)
javascript:(function(){window.prompt('user agent', window.navigator.userAgent);})();

amazondp

amazonの商品へのリンク
 ****/dp/****/
を抜き出して遷移。

amazondp
javascript:(function() {
  var p = window.location.pathname.match(/\/dp\/[^\/?#=&]+/g);
  if(p) {
    window.location.href = window.location.origin + p[0];
  };
})();
amazondp (ブックマーク登録用)
javascript:(function(){var p = window.location.pathname.match(/\/dp\/[^\/?#=&]+/g); if(p) {window.location.href = window.location.origin + p[0];};})();

(補足)

AmazonのURLは共有しようとすると○したくなるくらい長い。
~商品名とかURLに埋め込む必要あんの???

openpopup

今開いているページをポップアップで表示。

openpopup
javascript:(function() {
    window.open(window.location.href, undefined, 'menubar=no, toolbar=no');
})();
openpopup (ブックマーク登録用)
javascript:(function() { window.open(window.location.href, undefined, 'menubar=no, toolbar=no');})();

※スクリプトが誤っていたので修正しました。
❌ window.location.pathname
⭕ window.location.href

(補足)

漫画は縦長が多いので、どうしてもアドレスバーやタブバーなどの分の解像度がもったいなくなる。
ポップアップで開くことで高さを稼いだりできる。
ただし、ポップアップ ブロッカーなどで起動の確実性は保証できない。
また、あくまでURLで開き直しているだけなので、POST系などのページでは遷移出来ない。

余談

ブラウザ拡張のツールバー文化は完全廃れたけど。
ブックマークバーとブックマークレットの併用でも、
ブラウザを便利にできることは多いので、もっと活用していけたらなぁと思う、

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1