hexo-theme-linen 1.0.28 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-theme-linen",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "A clean Hexo theme",
5
5
  "main": "index.js",
6
6
  "homepage": "https://github.com/lynanbreeze/hexo-theme-linen",
@@ -19,9 +19,11 @@ module.exports = function (hexo) {
19
19
  ...(hexo?.config?.theme_config?.lazyload || {}),
20
20
  };
21
21
 
22
- const placeholderImage = /^(https?:\/\/|\/|data:image)/i.test(loadingImage) || loadingImage?.startsWith('../img')
23
- ? `url(${loadingImage})`
24
- : loadingImage;
22
+ const placeholderImage =
23
+ /^(https?:\/\/|\/|data:image|\.\.\/)/i.test(loadingImage) ||
24
+ /\.(svg|png|jpg|jpeg|webp|gif)$/i.test(loadingImage)
25
+ ? `url(${loadingImage})`
26
+ : loadingImage;
25
27
 
26
28
  const injectedStyles = `.lazyload-outer-wrap .caption{
27
29
  width: 100%;
@@ -52,7 +52,7 @@ function switchHDR() {
52
52
  } else {
53
53
  var hrefAttr = link.getAttribute("href");
54
54
  if (hrefAttr && hrefAttr.includes(SDRPath)) {
55
- link.setAttribute("href", HDRPath);
55
+ link.setAttribute("href", hrefAttr.replace(SDRPath, HDRPath));
56
56
  }
57
57
  }
58
58
  } else {
@@ -61,7 +61,7 @@ function switchHDR() {
61
61
  } else {
62
62
  var hrefAttr = link.getAttribute("href");
63
63
  if (hrefAttr && hrefAttr.includes(HDRPath)) {
64
- link.setAttribute("href", SDRPath);
64
+ link.setAttribute("href", hrefAttr.replace(HDRPath, SDRPath));
65
65
  }
66
66
  }
67
67
  }
@@ -147,30 +147,27 @@ function isElementInViewport(el) {
147
147
  }
148
148
 
149
149
  function copyToClipboard(text) {
150
- if (navigator.clipboard) {
151
- copyToClipboard = function () {
152
- navigator.clipboard
153
- .writeText(text)
154
- .then(() => {})
155
- .catch((err) => {
156
- console.error("复制失败:", err);
157
- });
158
- };
159
- } else {
160
- copyToClipboard = function () {
161
- const textArea = document.createElement("textarea");
162
- textArea.value = text;
163
- document.body.appendChild(textArea);
164
- textArea.select();
165
- try {
166
- document.execCommand("copy");
167
- } catch (err) {
150
+ if (navigator.clipboard && window.isSecureContext) {
151
+ navigator.clipboard
152
+ .writeText(text)
153
+ .then(() => {})
154
+ .catch((err) => {
168
155
  console.error("复制失败:", err);
169
- }
170
- document.body.removeChild(textArea);
171
- };
156
+ });
157
+ } else {
158
+ const textArea = document.createElement("textarea");
159
+ textArea.value = text;
160
+ textArea.style.position = "fixed";
161
+ textArea.style.opacity = "0";
162
+ document.body.appendChild(textArea);
163
+ textArea.select();
164
+ try {
165
+ document.execCommand("copy");
166
+ } catch (err) {
167
+ console.error("复制失败:", err);
168
+ }
169
+ document.body.removeChild(textArea);
172
170
  }
173
- copyToClipboard(text);
174
171
  }
175
172
 
176
173
  function highlightAnchor(hash, highlightClass = "anchor-highlight") {
@@ -548,24 +545,27 @@ function handleClick(e) {
548
545
  }
549
546
  }
550
547
 
548
+ var isClickHandlerBound = false;
551
549
  function bindClickHandler() {
550
+ if (isClickHandlerBound) return;
552
551
  document.addEventListener("click", handleClick, true);
552
+ isClickHandlerBound = true;
553
553
  }
554
554
 
555
555
  window.addEventListener("load", bindClickHandler);
556
- window.addEventListener("pageshow", (e) => {
557
- requestAnimationFrame(() => {
558
- bindClickHandler();
559
- });
556
+ window.addEventListener("pageshow", () => {
557
+ bindClickHandler();
560
558
  });
561
559
 
562
560
  function initAgeWarning() {
563
561
  const ageWarningElement = document.getElementById("post-age-warning");
564
562
  if (!ageWarningElement) return;
565
- const dateStr = document
566
- .querySelector("#post .post-meta .date")
567
- .getAttribute("datetime");
563
+ const dateElement = document.querySelector("#post .post-meta .date");
564
+ const dateStr = dateElement ? dateElement.getAttribute("datetime") : null;
565
+ if (!dateStr) return;
566
+
568
567
  const postDate = new Date(dateStr);
568
+ if (isNaN(postDate.getTime())) return;
569
569
  const now = new Date();
570
570
 
571
571
  const diffTime = now - postDate;
@@ -578,7 +578,7 @@ function initAgeWarning() {
578
578
  }
579
579
  } else {
580
580
  if (ageWarningElement) {
581
- ageWarningElement.style = "display: none";
581
+ ageWarningElement.style.display = "none";
582
582
  }
583
583
  }
584
584
  return diffDays;
@@ -1,4 +1,5 @@
1
1
  function replaceEmojis() {
2
+ if (!document.body) return;
2
3
  const replacements = [{ emoji: "✅", className: "custom-checked-checkbox" }];
3
4
 
4
5
  replacements.forEach(({ emoji, className }) => {
@@ -7,9 +8,16 @@ function replaceEmojis() {
7
8
  NodeFilter.SHOW_TEXT,
8
9
  {
9
10
  acceptNode(node) {
10
- return node.nodeValue.includes(emoji)
11
- ? NodeFilter.FILTER_ACCEPT
12
- : NodeFilter.FILTER_REJECT;
11
+ if (!node.nodeValue || !node.nodeValue.includes(emoji)) {
12
+ return NodeFilter.FILTER_REJECT;
13
+ }
14
+ if (
15
+ node.parentElement &&
16
+ node.parentElement.closest("pre, code, textarea, script, style")
17
+ ) {
18
+ return NodeFilter.FILTER_REJECT;
19
+ }
20
+ return NodeFilter.FILTER_ACCEPT;
13
21
  },
14
22
  },
15
23
  );