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.

ブックマークレットで外部スクリプトを実行するためのワンライナー

Last updated at Posted at 2023-04-19

結論

javascript:document.body.appendChild(Object.assign(document.createElement("script"),{src:"https://exam.pl/example.js"}))

https://exam.pl/example.js を自分のスクリプトのパスに置き換えてください。

何をしているの?

document.body.appendChild(
    Object.assign(
        document.createElement("script"),
        {src:"https://exam.pl/example.js"}
    )
)

htmlbodyscript タグを挿入しています。

Object.assign って?

const tag = Object.assign(
    document.createElement("script"),
    {src:"https://exam.pl/example.js"}
)

は以下と等価です。

const tag = document.createElement("script");
tag.src = "https://exam.pl/example.js";

もっと短くできたら教えてください!

もっと短くできたら教えてください!

0
0
1

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?