Workflowyの自作ショートカットキーを常駐させる自作アドオン
Workflowyをリロードするたびにブックマークレットを発動指せ直すのが面倒だったので、Firefoxのアドオンを使って自動的に設定されるようにしてみる。
Firefoxのアドオンを自作する
code:test.js
console.log("スクリプトが読み込まれました")
const scriptText = `
(function(){document.body.addEventListener('keydown',event => {if (event.metaKey){
if(event.key==='ArrowRight'){
event.preventDefault();
var s = WF.focusedItem();
var t = s.getParent();
WF.editItemName(t);
WF.collapseItem(t);
if(t.getParent().getParent()==null){
WF.zoomOut();
}}}});})();
`
const scriptbody = document.createElement("script")
scriptbody.innerHTML = scriptText
document.body.appendChild(scriptbody);
console.log("ショートカットキーを追加しました")
command+→ で親項目を閉じる
普通にショートカットを設定しようとすると、オブジェクトWFが参照できないので、scriptタグを作り、そこにコードを書いてそれをbodyに追加する形をとっている。
2024/4/5
コマンドの中身はもう少し改善できそう
WorkFlowyのWFオブジェクト
WorkFlowyの項目オブジェクト
以下のように動作を変更
その要素が開いている子要素があればそれを閉じ
開いている子要素を持たないなら親要素を閉じる
https://gyazo.com/460a7c358ccddddb160650430fd32c1a
code:script.js
console.log("スクリプトが読み込まれました")
const scriptText = `
(function(){document.body.addEventListener('keydown',event => {if (event.metaKey){
if(event.key==='ArrowRight'){
event.preventDefault();
var s = WF.focusedItem();
if (s.isExpanded()){
WF.collapseItem(s);
}else{
var t = s.getParent();
WF.editItemName(t);
WF.collapseItem(t);
if(t.getParent().getParent()==null){
WF.zoomOut();
}
}
}}});})();
`
const scriptbody = document.createElement("script")
scriptbody.innerHTML = scriptText
document.body.appendChild(scriptbody);
console.log("ショートカットキーを追加しました")
Chromeでもやる
参考
Chrome 拡張機能  |  Chrome Extensions  |  Chrome for Developers
拡張機能 / スタートガイド  |  Get started  |  Chrome for Developers
カスタムの Chrome アプリと拡張機能を作成して公開する - Chrome Enterprise and Education ヘルプ
Chrome拡張の作り方 (超概要) #JavaScript - Qiita
Chrome 拡張機能のマニフェストファイルの書き方 #Chrome - Qiita
とほほのChrome拡張機能開発入門 - とほほのWWW入門
Chromeだとセキュリティが厳しくて上のような雑な書き方ではだめだった
以下を参考
Chrome拡張でページ内のwindowオブジェクトを取得してpopupやbackgroundに送信する方法
code:main.js
console.log("スクリプトが読み込まれました")
const head = document.head
const script = document.createElement('script')
script.src = chrome.runtime.getURL('embed.js')
head.appendChild(script)
console.log("ショートカットキーを追加しました")
code:embed.js
(function(){document.body.addEventListener('keydown',event => {if (event.metaKey){
if(event.key==='ArrowRight'){
event.preventDefault();
var s = WF.focusedItem();
if (s.isExpanded()){
WF.collapseItem(s);
}else{
var t = s.getParent();
WF.editItemName(t);
WF.collapseItem(t);
if(t.getParent().getParent()==null){
WF.zoomOut();
}
}
}}});})();
code:manifest.json
{
"manifest_version": 3,
"name": "workflowy-extention",
"description": "Add useful functions to your Workflowy",
"version": "1.0",
"action": {
"default_icon": "icons/border-48.png"
},
"web_accessible_resources": [
{
"resources": "embed.js",
"matches": "*://*.workflowy.com/*"
}
],
"content_scripts": [
{
"matches": "*://*.workflowy.com/*",
"js": "workflowy-extention.js"
}
],
"content_security_policy":{
"extension_pages": "script-src 'self' 'wasm-unsafe-eval' ; object-src 'self';"
}
}
これでいけた。
2024/8/26
機能追加
WorkFlowyで選択項目をトップに移動するブックマークレット