|
4 | 4 | * Compatible with plain JavaScript use (no bundler required). |
5 | 5 | */ |
6 | 6 |
|
7 | | -class SafeLearnPlugin extends Plugin { |
| 7 | +module.exports = class SafeLearnPlugin extends Plugin { |
8 | 8 | async onload() { |
9 | | - this.addStyles(); |
10 | | - this.registerDomEvent(document, "DOMContentLoaded", () => { |
11 | | - this.processAll(); |
12 | | - }); |
13 | | - this.registerEvent( |
14 | | - this.app.workspace.on("layout-change", () => this.processAll()) |
15 | | - ); |
| 9 | + console.log("✅ SafeLearn Plugin loaded"); |
| 10 | + this.registerEvent(this.app.workspace.on("layout-change", () => this.processAll())); |
16 | 11 | } |
17 | 12 |
|
18 | 13 | onunload() { |
| 14 | + console.log("❎ SafeLearn Plugin unloaded"); |
19 | 15 | document.querySelectorAll(".fragment-highlight, .permission-block, .side-by-side").forEach(el => { |
20 | 16 | el.classList.remove("fragment-highlight", "permission-block", "side-by-side"); |
21 | 17 | }); |
22 | 18 | } |
23 | 19 |
|
24 | | - addStyles() { |
25 | | - const style = document.createElement("style"); |
26 | | - style.id = "safelearn-style"; |
27 | | - style.textContent = ` |
28 | | - .fragment-highlight { |
29 | | - background-color: var(--fragment-bg); |
30 | | - color: var(--fragment-fg); |
31 | | - border: 2px solid var(--fragment-border); |
32 | | - border-radius: 8px; |
33 | | - padding: 2px 6px; |
34 | | - margin: 1px; |
35 | | - display: inline-block; |
36 | | - font-weight: 500; |
37 | | - } |
38 | | - .fragment-highlight::before { |
39 | | - content: "🔀 "; |
40 | | - opacity: 0.6; |
41 | | - } |
42 | | - .permission-block { |
43 | | - background-color: var(--permission-bg, #eef7ff); |
44 | | - border-left: 4px solid var(--permission-border, #3399ff); |
45 | | - padding: 4px 8px; |
46 | | - margin: 8px 0; |
47 | | - } |
48 | | - .permission-block .perm-label, |
49 | | - .permission-block .perm-end { |
50 | | - font-family: monospace; |
51 | | - font-size: 0.8em; |
52 | | - background: #ddeeff; |
53 | | - color: #225577; |
54 | | - padding: 2px 4px; |
55 | | - border-radius: 4px; |
56 | | - display: inline-block; |
57 | | - margin-bottom: 4px; |
58 | | - } |
59 | | - .side-by-side { |
60 | | - display: flex; |
61 | | - gap: 20px; |
62 | | - margin: 1em 0; |
63 | | - border: 1px dashed #bbb; |
64 | | - padding: 8px; |
65 | | - } |
66 | | - .side-by-side > div { |
67 | | - flex: 1; |
68 | | - padding: 0 10px; |
69 | | - border-left: 2px dashed #ccc; |
70 | | - } |
71 | | - `; |
72 | | - document.head.appendChild(style); |
73 | | - } |
74 | | - |
75 | 20 | processAll() { |
76 | 21 | const leaves = this.app.workspace.getLeavesOfType("markdown"); |
77 | 22 | for (const leaf of leaves) { |
@@ -135,6 +80,4 @@ class SafeLearnPlugin extends Plugin { |
135 | 80 | return `<div class="side-by-side">${columns}</div>`; |
136 | 81 | }); |
137 | 82 | } |
138 | | -} |
139 | | - |
140 | | -module.exports = SafeLearnPlugin; |
| 83 | +}; |
0 commit comments