實用瀏覽器腳本

原文鏈接:https://emlog.icedog.top/?post=28

瀏覽器打開空白頁

在瀏覽器的地址欄輸入如下代碼即可

about:blank

在瀏覽器打開空白頁作爲臨時內容存放區

有時候我們想找個地方存一些文本數據,但是又不一定有自己熟悉好用的工具,這時,瀏覽器就是一個不錯的工具,按 F12 打開開發者工具,輸入如下命令即可。

源碼:

(function(){
var nw =window.open("about:blank","臨時編輯頁");
nw.document.title="臨時編輯頁";
nw.document.body.contentEditable=true;
nw.document.body.innerText="現在你可以直接在頁面輸入內容了";
})();

標籤欄書籤模式,打開開發者工具比較繁瑣,安裝瀏覽器插件又比較麻煩,直接創建個瀏覽器書籤反而最簡單,如下圖填入內容即可

打開臨時編輯頁

名稱:打開臨時編輯頁
網址:

javascript:(function(){var nw =window.open("about:blank","臨時編輯頁");nw.document.title="臨時編輯頁";nw.document.body.contentEditable=true;nw.document.body.innerText="現在你可以直接在頁面輸入內容了";})()

複製網頁標題和url的腳本

在生活中,我們經常會訪問各種網頁查資料,做筆記,同時會存儲這些網頁地址,用於下次遇到類似的問題,好做參考,但是時間一久,只看鏈接就忘了之前存的是啥了,
所以一般會把網頁標題和鏈接一起存下來,如下格式:

Chrome 文件選擇延遲 Bug - 知乎
https://zhuanlan.zhihu.com/p/27946188

一行標題,一行內容,但是手動操作太過於繁瑣,不如用瀏覽器書籤腳本實現

名稱:複製網頁標題和鏈接
網址:

javascript:(function(f){var info =document.createElement('textarea');info.setAttribute('style','position:fixed;z-index:9999;width:400px;height:100px;user-select:text;');info.value=f;document.body.insertBefore(info,document.body.firstChild);var first=document.body.firstChild;first.select();document.execCommand('copy');document.body.firstElementChild.remove();
})(`${document.title}\r\n${document.URL}`)

複製網頁標題和 url 爲 markdown 超鏈接格式的腳本

現在做筆記基本上都使用 markdown 格式做筆記,因此鏈接存爲 markdown 鏈接格式會更方便,腳本和上面一樣,只是替換了傳參字符串模板

名稱:(md)複製網頁標題和鏈接
網址:

javascript:(function(f){var info =document.createElement('textarea');info.setAttribute('style','position:fixed;z-index:9999;width:400px;height:100px;user-select:text;');info.value=f;document.body.insertBefore(info,document.body.firstChild);var first=document.body.firstChild;first.select();document.execCommand('copy');document.body.firstElementChild.remove();
})(`[${document.title}](${document.URL} \"${document.title}\")`)

效果:

[Chrome 文件選擇延遲 Bug - 知乎](https://zhuanlan.zhihu.com/p/27946188 "Chrome 文件選擇延遲 Bug - 知乎")

Chrome 文件選擇延遲 Bug - 知乎

注意

有的網站是不允許通過書籤這樣執行腳本的(如 github),這種就沒辦法,只能按F12打開開發者工具執行。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章