Skip to content

Commit

Permalink
Support $&$TITLE, $TITLE$&, and analogously with $NAME and $URL
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeth committed Apr 5, 2020
2 parents 31f657d + 523e976 commit 4c1dc85
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 16 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
Martin Väth <martin at mvath.de>:
- Remove support for stripping descriptions

*bookmarkdupes-6.4:
Martin Väth <mvath at mvath.de>:
- Support $&$TITLE, $TITLE$&, and analogously with $NAME and $URL:
https://github.com/vaeth/bookmarkdupes/issues/94

*bookmarkdupes-6.3:
Martin Väth <mvath at mvath.de>:
- Fix strip bookmarks and moving to "Dupes" folder: Regression from 6.1
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ several rules to work around that limitation if necessary.)
5. `$TITLE` is the bookmark's title without the path; for instance, for the
bookmark name “Bookmark Menu | Collection | Example” it is “Example”.

Cases 3-5 can be preceeded or followed by `$$&` to prepend or append the match.

## Examples for special tasks which can be done in Expert Mode

### Task
Expand Down
2 changes: 1 addition & 1 deletion _locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"description": "Input field for the replacement text for the regular expression matches. The text should be short"
},
"titleRuleReplace": {
"message": "Der Ersetzungstext für den passenden Teil des regulären Ausdrucks. Symbole wie $$& oder $$1 können benutzt werden, um auf Treffer oder Klammern zu verweisen. Die speziellen Texte \\L$$& und \\U$$& bedeuten eine klein- bzw. großgeschriebene Version der Treffer. Die speziellen Texte $URL, $NAME und $TITLE bedeuten die ursprüngliche (unmodifizierte) URL bzw. den Lesezeichennamen/-Titel (mit bzw. ohne vollen Pfad).",
"message": "Der Ersetzungstext für den passenden Teil des regulären Ausdrucks. Symbole wie $$& oder $$1 können benutzt werden, um auf Treffer oder Klammern zu verweisen. Die speziellen Texte \\L$$& und \\U$$& bedeuten eine klein- bzw. großgeschriebene Version der Treffer. Die speziellen Texte $$URL, $$NAME und $$TITLE bedeuten die ursprüngliche (unmodifizierte) URL bzw. den Lesezeichennamen/-Titel (mit bzw. ohne vollen Pfad). Den letzten drei kann ein $$& vor- oder nachgestellt sein, um den Treffer vorne oder hinten anzuhängen.", // new
"description": "Explain that the text will be used as replacement text for the regular expression matches"
},
"buttonRuleUp": {
Expand Down
2 changes: 1 addition & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"description": "Input field for the replacement text for the regular expression matches. The text should be short"
},
"titleRuleReplace": {
"message": "The replacement text for the regular expresssion matches. Symbols like $$& or $$1 can be used to refer to the match or a brace content. The special texts \\L$$& and \\U$$& mean a lower and upper case version of the matches, respectively. The special texts $URL, $NAME, and $TITLE mean the original (unmodified) URL and the bookmark full name/title (with/without path), respectively.",
"message": "The replacement text for the regular expresssion matches. Symbols like $$& or $$1 can be used to refer to the match or a brace content. The special texts \\L$$& and \\U$$& mean a lower and upper case version of the matches, respectively. The special texts $$URL, $$NAME, and $$TITLE mean the original (unmodified) URL and the bookmark full name/title (with/without path), respectively. The latter three can be preceeded or followed by $$& to prepend or append the original match",
"description": "Explain that the text will be used as replacement text for the regular expression matches"
},
"buttonRuleUp": {
Expand Down
2 changes: 1 addition & 1 deletion _locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"description": "Input field for the replacement text for the regular expression matches. The text should be short"
},
"titleRuleReplace": {
"message": "El texto de reemplazo para la expresión regular coincide. Se pueden usar símbolos como $$& o $$1 para referirse a la coincidencia o un contenido de corchete. Los textos especiales \\L$$& y \\U$$& significan una versión en mayúsculas y minúsculas de las coincidencias, respectivamente. Los textos especiales $URL, $NAME y $TITLE significan la URL original (sin modificar) y el nombre completo / título del marcador (con / sin ruta), respectivamente.",
"message": "El texto de reemplazo para la expresión regular coincide. Se pueden usar símbolos como $$& o $$1 para referirse a la coincidencia o un contenido de corchete. Los textos especiales \\L$$& y \\U$$& significan una versión en mayúsculas y minúsculas de las coincidencias, respectivamente. Los textos especiales $$URL, $$NAME y $$TITLE significan la URL original (sin modificar) y el nombre completo / título del marcador (con / sin ruta), respectivamente. The latter three can be preceeded or followed by $$& to prepend or append the original match", // new
"description": "Explain that the text will be used as replacement text for the regular expression matches"
},
"buttonRuleUp": {
Expand Down
2 changes: 1 addition & 1 deletion _locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"description": "Input field for the replacement text for the regular expression matches. The text should be short"
},
"titleRuleReplace": {
"message": "Текст замены по соответствию регулярному выражению. Символы типа $$& или $$1 могут использоваться для обозначения соответствий или содержимого скобок (). Специальные тексты \\L$$& и \\U$$& означают нижний и верхний регистр соответствий. Специальные тексты $URL, $NAME, $TITLE означают начальные (немодифицированные) URL-ы и полные названия/заголовки закладок (с/без пути) соответственно.",
"message": "Текст замены по соответствию регулярному выражению. Символы типа $$& или $$1 могут использоваться для обозначения соответствий или содержимого скобок (). Специальные тексты \\L$$& и \\U$$& означают нижний и верхний регистр соответствий. Специальные тексты $$URL, $$NAME, $$TITLE означают начальные (немодифицированные) URL-ы и полные названия/заголовки закладок (с/без пути) соответственно. The latter three can be preceeded or followed by $$& to prepend or append the original match", // new
"description": "Explain that the text will be used as replacement text for the regular expression matches"
},
"buttonRuleUp": {
Expand Down
2 changes: 1 addition & 1 deletion _locales/uk/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"description": "Input field for the replacement text for the regular expression matches. The text should be short"
},
"titleRuleReplace": {
"message": "Текст заміни по відповідності регулярному виразу. Символи типу $$& чи $$1 можуть використовуватися для позначення відповідностей чи вмісту дужок (). Спеціальні тексти \\L$$& та \\U$$& означають нижній та верхній регістр відповідно. Спеціальні тексти $URL, $NAME, $TITLE означають початкові (немодифіковані) URL-и і повні назви/заголовки закладок (з/без шляху) відповідно.",
"message": "Текст заміни по відповідності регулярному виразу. Символи типу $$& чи $$1 можуть використовуватися для позначення відповідностей чи вмісту дужок (). Спеціальні тексти \\L$$& та \\U$$& означають нижній та верхній регістр відповідно. Спеціальні тексти $$URL, $$NAME, $$TITLE означають початкові (немодифіковані) URL-и і повні назви/заголовки закладок (з/без шляху) відповідно. The latter three can be preceeded or followed by $$& to prepend or append the original match", // new
"description": "Explain that the text will be used as replacement text for the regular expression matches"
},
"buttonRuleUp": {
Expand Down
2 changes: 1 addition & 1 deletion _locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"description": "Input field for the replacement text for the regular expression matches. The text should be short"
},
"titleRuleReplace": {
"message": "The replacement text for the regular expresssion matches. Symbols like $$& or $$1 can be used to refer to the match or a brace content. The special texts \\L$$& and \\U$$& mean a lower and upper case version of the matches, respectively. The special texts $URL, $NAME, and $TITLE mean the original (unmodified) URL and the bookmark full name/title (with/without path), respectively.", // new
"message": "The replacement text for the regular expresssion matches. Symbols like $$& or $$1 can be used to refer to the match or a brace content. The special texts \\L$$& and \\U$$& mean a lower and upper case version of the matches, respectively. The special texts $$URL, $$NAME, and $$TITLE mean the original (unmodified) URL and the bookmark full name/title (with/without path), respectively. The latter three can be preceeded or followed by $$& to prepend or append the original match", // new
"description": "Explain that the text will be used as replacement text for the regular expression matches"
},
"buttonRuleUp": {
Expand Down
52 changes: 42 additions & 10 deletions data/tab/dupes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1565,12 +1565,36 @@ function compileRules(mode) {
compiledRule.replace = 0;
compiledRules.needSpecials = true;
break;
case "\$NAME":
case "\$\&\$URL":
compiledRule.replace = 1;
compiledRules.needSpecials = true;
break;
case "\$URL\$\&":
compiledRule.replace = 2;
compiledRules.needSpecials = true;
break;
case "\$NAME":
compiledRule.replace = 3;
compiledRules.needSpecials = compiledRules.needName = true;
break;
case "\$\&\$NAME":
compiledRule.replace = 4;
compiledRules.needSpecials = compiledRules.needName = true;
break;
case "\$NAME\$\&":
compiledRule.replace = 5;
compiledRules.needSpecials = compiledRules.needName = true;
break;
case "\$TITLE":
compiledRule.replace = 2;
compiledRule.replace = 6;
compiledRules.needSpecials = true;
break;
case "\$\&\$TITLE":
compiledRule.replace = 7;
compiledRules.needSpecials = true;
break;
case "\$TITLE\$\&":
compiledRule.replace = 8;
compiledRules.needSpecials = true;
break;
default:
Expand Down Expand Up @@ -1611,8 +1635,14 @@ function rulesFilter(compiledRules, folders, parent, title, url, processed) {
const originalUrl = url;
specials = [
function () { return originalUrl; },
function (found) { return found.concat(originalUrl); },
function (found) { return originalUrl.concat(found); },
function () { return name; },
function () { return title; }
function (found) { return found.concat(name); },
function (found) { return name.concat(found); },
function () { return title; },
function (found) { return found.concat(title); },
function (found) { return title.concat(found); }
];
}
let extra;
Expand Down Expand Up @@ -2244,17 +2274,19 @@ function initMain() {
let state = {};
let rules;
const rulesDefault = [
{ radio: "url", search: "^\\w+://[^\/]*/", replace: "\\L$&" },
{ radio: "url", search: "^\\w\+://\[\^\/\]*/", replace: "\\L\$\&" },
{ radio: "filter", name:
"^[^\\0]+\\0" + compatible.getMessage("regExpTrashFolder") + "\\0" },
"^[^\\0]\+\\0" + compatible.getMessage("regExpTrashFolder") + "\\0" },
{ radio: "off", nameNegation: "\\0.*\\0" },
{ radio: "off", urlNegation: "\\b(e?mail|bugs|youtube|translat)\\b",
{ radio: "off", urlNegation: "\\b\(e?mail|bugs|youtube|translat\)\\b",
search: "\\?.*" },
{ radio: "off", search: "/[^/]*$" },
{ radio: "url", search: "/+(index\\.html)?$" },
{ radio: "off", search: "/[^/]*\$" },
{ radio: "url", search: "/\+\(index\\.html\)?\$" },
{ radio: "url", search: "^http:", replace: "https:" },
{ radio: "url", search: "^([^:]*://)www?\\d*\\.", replace: "$1" },
{ radio: "url", search: "\\.htm$", replace: ".html" }
{ radio: "url", search: "^([^:]*://)www?\\d*\\.", replace: "\$1" },
{ radio: "url", search: "\\.htm\$", replace: ".html" },
{ radio: "off", search: ".\+", replace: "\$\&\$TITLE" },
{ radio: "off", search: ".\+", replace: "DEBUG: \$\&" }
];
let mutationObserver;

Expand Down

0 comments on commit 4c1dc85

Please sign in to comment.