Skip to content

Commit

Permalink
add 'open all links' to notes
Browse files Browse the repository at this point in the history
  • Loading branch information
mi2ebi committed Dec 13, 2023
1 parent dafda05 commit 4cacf9a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
35 changes: 24 additions & 11 deletions helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function convertJSONToHTMLElement(json) {
createHTMLElement("p", null, [
createHTMLElement("a", {
"href": "?q=" + json.word,
"target": config["rhyme"] || config["regex"] ? "_blank" : "_self"
}, [
createHTMLElement("b", null, [json.word])
]),
Expand All @@ -35,31 +34,45 @@ function convertJSONToHTMLElement(json) {
"\u{a0}β†—"
])
]),
createHTMLElement("p", null, replaceLinks(json.definition)),
createHTMLElement("p", null, replaceLinks(json.definition).els),
json.notes ? createHTMLElement("details", null, [
createHTMLElement("summary", null, ["more info"]),
createHTMLElement("p", null, replaceLinks(json.notes))
createHTMLElement("summary", null, [
"more info",
createHTMLElement("span", null, [
" β€’ ",
createHTMLElement("a", {
"href": "?q=" + encodeURIComponent(replaceLinks(json.notes).text)
}, ["open all links"])
])
]),
createHTMLElement("p", null, replaceLinks(json.notes).els)
]) : null
]);
console.log(encodeURIComponent(replaceLinks(json.definition).text));
return entry;
}
function replaceLinks(str) {
var bits = str.replace(/\$/g, "πŸ’΅$").split("πŸ’΅");
var text = "";
for (var i = 0; i < bits.length; i++) {
if (i % 2 == 0 || i == bits.length - 1) {
if (i) {
bits[i] = bits[i].slice(1);
bits[i - 1] = bits[i - 1] + "$";
}
bits[i] = bits[i].replace(/\{/g, "πŸ“¦{").replace(/\}/g, "}πŸ“¦").split("πŸ“¦").map((item) =>
/\{[a-g'i-pr-vx-z., ]+\}/i.test(item) ? createHTMLElement("a", {
"href": "?q=" + item.slice(1, -1) + "&fromwordlink",
"target": config["rhyme"] || config["regex"] ? "_blank" : "_self"
}, item.slice(1, -1)) : item
);
bits[i] = bits[i].replace(/\{/g, "πŸ“¦{").replace(/\}/g, "}πŸ“¦").split("πŸ“¦").map((item) => {
if (/\{[a-g'i-pr-vx-z., ]+\}/i.test(item)) {
text += " " + item.slice(1, -1);
return createHTMLElement("a", {
"href": "?q=" + item.slice(1, -1) + "&fromwordlink",
}, item.slice(1, -1))
} else {
return item;
}
});
}
}
return bits.flat();
return {"els": bits.flat(), "text": text.trim()};
}
function load(res, page) {
const start = page * 100;
Expand Down
3 changes: 3 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ summary {
font-weight: bold;
cursor: pointer;
}
:not([open]) > summary span {
display: none;
}
.entry .glosswords {
font-style: italic;
}
Expand Down

0 comments on commit 4cacf9a

Please sign in to comment.