diff --git a/.gitmodules b/.gitmodules index b6ce27404..1a24ca665 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,3 +34,6 @@ [submodule "submodules/webextensions-lib-dom-updater"] path = submodules/webextensions-lib-dom-updater url = https://github.com/piroor/webextensions-lib-dom-updater.git +[submodule "submodules/webextensions-lib-placeholder-parser"] + path = submodules/webextensions-lib-placeholder-parser + url = https://github.com/piroor/webextensions-lib-placeholder-parser.git diff --git a/submodules/webextensions-lib-placeholder-parser b/submodules/webextensions-lib-placeholder-parser new file mode 160000 index 000000000..4230e82ad --- /dev/null +++ b/submodules/webextensions-lib-placeholder-parser @@ -0,0 +1 @@ +Subproject commit 4230e82ad5433479eedda9aa76d6822d76c42a04 diff --git a/webextensions/Makefile b/webextensions/Makefile index 57b9d0466..a72826383 100644 --- a/webextensions/Makefile +++ b/webextensions/Makefile @@ -43,6 +43,7 @@ install_extlib: install_dependency cp ../submodules/webextensions-lib-l10n/l10n.js $(EXTERNAL_LIB_DIR)/l10n-classic.js; echo 'window.l10n = l10n;' >> $(EXTERNAL_LIB_DIR)/l10n-classic.js cp ../submodules/webextensions-lib-dom-updater/src/diff.js $(EXTERNAL_LIB_DIR)/ cp ../submodules/webextensions-lib-dom-updater/src/dom-updater.js $(EXTERNAL_LIB_DIR)/ + cp ../submodules/webextensions-lib-placeholder-parser/src/placeholder-parser.js $(EXTERNAL_LIB_DIR)/ echo "/* CodeMirror version $$(cat node_modules/codemirror/package.json | jq -r .version) */" > $(EXTERNAL_LIB_DIR)/codemirror.js cp $(EXTERNAL_LIB_DIR)/codemirror.js $(EXTERNAL_LIB_DIR)/codemirror.css cp $(EXTERNAL_LIB_DIR)/codemirror.js $(EXTERNAL_LIB_DIR)/codemirror-mode-css.js diff --git a/webextensions/common/bookmark.js b/webextensions/common/bookmark.js index 2fa98ca49..f9bc9b200 100644 --- a/webextensions/common/bookmark.js +++ b/webextensions/common/bookmark.js @@ -6,6 +6,7 @@ 'use strict'; import MenuUI from '/extlib/MenuUI.js'; +import * as PlaceHolderParser from '/extlib/placeholder-parser.js'; import RichConfirm from '/extlib/RichConfirm.js'; import { @@ -239,13 +240,30 @@ export async function bookmarkTabs(tabs, { parentId, index, showDialog, title } const now = new Date(); const year = String(now.getFullYear()); if (!title) - title = configs.bookmarkTreeFolderName - .replace(/%TITLE%/gi, tabs[0].title) - .replace(/%URL%/gi, tabs[0].url) - .replace(/%SHORT_?YEAR%/gi, year.slice(-2)) - .replace(/%(FULL_?)?YEAR%/gi, year) - .replace(/%MONTH%/gi, String(now.getMonth() + 1).padStart(2, '0')) - .replace(/%DATE%/gi, String(now.getDate()).padStart(2, '0')); + title = PlaceHolderParser.process(configs.bookmarkTreeFolderName, (name, _rawArgs, ..._args) => { + switch (name.toLowerCase()) { + case 'title': + return tabs[0].title; + + case 'url': + return tabs[0].url; + + case 'short_year': + case 'shortyear': + return year.slice(-2); + + case 'full_year': + case 'fullyear': + case 'year': + return year; + + case 'month': + return String(now.getMonth() + 1).padStart(2, '0'); + + case 'date': + return String(now.getDate()).padStart(2, '0'); + } + }); const folderParams = { type: 'folder', title