0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

テキストURLをリンクにする_拡張機能

Posted at

テキスト形式のままのURLをクリックできるようにリンクをつけたいので、やってみました!

拡張機能

これを拡張機能で追加して、ブラウザから開くためには、カスタムURLスキーマというので開けるようにしました。
NativeMessagingといやり方もあるようですが、ローカルアプリとのメッセージのやり取りがよくわからなくて諦めました。。。

// 対象にする箇所
const qs = document.querySelectorAll(".Reference, .multiple-lines");
// URL対象を抽出する正規表現
const exp =
  /((\\\\)[^\<\>"\n\r]*)/gi;
for (let i = 0; i < qs.length; i++) {
  console.log(qs.item(i).textContent);
  // aタグを追加する
  const r = qs
    .item(i)
    .textContent.replace(exp, "<a href='cel:$1'>$1</a>");
  qs.item(i).innerHTML = r;
  console.log(qs.item(i).textContent);
}

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?