ep_small_list 0.5.0 → 0.6.0

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.
Files changed (2) hide show
  1. package/index.js +43 -9
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -36,8 +36,26 @@ if (settings.ep_small_list) {
36
36
  }
37
37
  }
38
38
 
39
- exports.eejsBlock_indexWrapper = function(hook_name, args, cb) {
40
- args.content += '<div id="small_list"></div><script src="./static/js/jquery.js"></script><script>$(function () { $("#small_list").load("./small_list"); });</script>';
39
+ exports.eejsBlock_indexWrapper = function(hook_name, args) {
40
+ args.content += `
41
+ <div id="small_list"></div>
42
+ <script>
43
+ document.addEventListener('DOMContentLoaded', async function() {
44
+ const container = document.getElementById('small_list');
45
+ if (!container) return;
46
+
47
+ try {
48
+ const response = await fetch('./small_list');
49
+ if (!response.ok) {
50
+ throw new Error('HTTP ' + response.status);
51
+ }
52
+ container.innerHTML = await response.text();
53
+ } catch (error) {
54
+ console.error('ep_small_list:', error);
55
+ }
56
+ });
57
+ </script>
58
+ `;
41
59
  };
42
60
 
43
61
  exports.registerRoute = function(hook_name, args, cb) {
@@ -50,8 +68,19 @@ exports.registerRoute = function(hook_name, args, cb) {
50
68
  res.send("<div> Error:" + err + "</div>");
51
69
  });
52
70
  });
71
+ return cb();
53
72
  };
54
73
 
74
+ function escapeHtml(value) {
75
+ return String(value).replace(/[&<>"']/g, char => ({
76
+ '&': '&amp;',
77
+ '<': '&lt;',
78
+ '>': '&gt;',
79
+ '"': '&quot;',
80
+ "'": '&#39;'
81
+ })[char]);
82
+ }
83
+
55
84
  async function createList(data){
56
85
  let dataCache = [];
57
86
  if(data && data.padIDs){
@@ -66,15 +95,20 @@ async function createList(data){
66
95
  }
67
96
  const lastEdit = await pad.getLastEdit();
68
97
  padData.lastChange = lastEdit;
69
-
70
- // support for ep_set_title_on_pad
71
- db.get("title:"+padID, function(err, value){
72
- if(!err && value) {
73
- title = value;
98
+
99
+ // support custom titles from ep_set_title_on_pad.
100
+ try {
101
+ const storedTitle = await db.get("title:" + padID);
102
+ if (storedTitle) {
103
+ title = storedTitle;
74
104
  }
75
- });
105
+ } catch (err) {
106
+ console.error("ep_small_list: Could not read title for pad", padID, err);
107
+ }
76
108
 
77
- padData.html = '<li><a href="./p/' + padID + '">' + title + '</li>';
109
+ padData.html = '<li><a href="./p/' +
110
+ encodeURIComponent(padID) + '">' +
111
+ escapeHtml(title) + '</a></li>';
78
112
  padData.createIndex = i;
79
113
 
80
114
  dataCache.push(padData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ep_small_list",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Adds a list of all pads on the index-page",
5
5
  "main": "index.js",
6
6
  "scripts": {