Skip to content

Commit

Permalink
Use placeholder parser
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Oct 6, 2022
1 parent db6ee17 commit a3620eb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions submodules/webextensions-lib-placeholder-parser
1 change: 1 addition & 0 deletions webextensions/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 25 additions & 7 deletions webextensions/common/bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a3620eb

Please sign in to comment.