nodebb-plugin-pdf-secure 1.1.4 → 1.1.5

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/package.json +1 -1
  2. package/static/lib/main.js +45 -70
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-pdf-secure",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Secure PDF viewer plugin for NodeBB - prevents downloading, enables canvas-only rendering with Premium group support",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -31,31 +31,61 @@ console.log('[PDF-Secure] main.js loaded');
31
31
  var filename = parts[parts.length - 1];
32
32
  console.log('[PDF-Secure] Embedding:', filename);
33
33
 
34
- // Create inline viewer container
34
+ // Create inline viewer container with INLINE STYLES to ensure they work
35
35
  var container = document.createElement('div');
36
36
  container.className = 'pdf-secure-embed';
37
+ container.style.cssText = 'margin:16px 0;border-radius:12px;overflow:hidden;background:#1f1f1f;border:1px solid rgba(255,255,255,0.1);box-shadow:0 4px 20px rgba(0,0,0,0.25);';
37
38
 
38
- // Header with filename
39
+ // Header with filename - ALL INLINE STYLES
39
40
  var header = document.createElement('div');
40
41
  header.className = 'pdf-secure-embed-header';
41
- header.innerHTML =
42
- '<div class="pdf-secure-embed-title">' +
43
- '<svg viewBox="0 0 24 24"><path d="M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm4 18H6V4h7v5h5v11z" fill="currentColor"/></svg>' +
44
- '<span>' + escapeHtml(decodeURIComponent(link.textContent || filename)) + '</span>' +
45
- '</div>' +
46
- '<div class="pdf-secure-embed-actions">' +
47
- '<button class="pdf-secure-fullscreen-btn" title="Tam Ekran">' +
48
- '<svg viewBox="0 0 24 24"><path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z" fill="currentColor"/></svg>' +
49
- '</button>' +
50
- '</div>';
42
+ header.style.cssText = 'display:flex;align-items:center;justify-content:space-between;padding:10px 16px;background:linear-gradient(135deg,#2d2d2d 0%,#252525 100%);border-bottom:1px solid rgba(255,255,255,0.08);';
43
+
44
+ var title = document.createElement('div');
45
+ title.className = 'pdf-secure-embed-title';
46
+ title.style.cssText = 'display:flex;align-items:center;gap:10px;color:#fff;font-size:14px;font-weight:500;';
47
+
48
+ // PDF icon with INLINE SIZE
49
+ var icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
50
+ icon.setAttribute('viewBox', '0 0 24 24');
51
+ icon.style.cssText = 'width:20px;height:20px;min-width:20px;max-width:20px;fill:#e81224;flex-shrink:0;';
52
+ icon.innerHTML = '<path d="M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm4 18H6V4h7v5h5v11z"/>';
53
+
54
+ var nameSpan = document.createElement('span');
55
+ nameSpan.style.cssText = 'white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:400px;';
56
+ nameSpan.textContent = decodeURIComponent(link.textContent || filename);
57
+
58
+ title.appendChild(icon);
59
+ title.appendChild(nameSpan);
60
+
61
+ // Actions (fullscreen button)
62
+ var actions = document.createElement('div');
63
+ actions.style.cssText = 'display:flex;gap:8px;';
64
+
65
+ var fullscreenBtn = document.createElement('button');
66
+ fullscreenBtn.className = 'pdf-secure-fullscreen-btn';
67
+ fullscreenBtn.title = 'Tam Ekran';
68
+ fullscreenBtn.style.cssText = 'display:flex;align-items:center;justify-content:center;width:32px;height:32px;background:rgba(255,255,255,0.08);border:none;border-radius:6px;cursor:pointer;';
69
+
70
+ var fullscreenIcon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
71
+ fullscreenIcon.setAttribute('viewBox', '0 0 24 24');
72
+ fullscreenIcon.style.cssText = 'width:18px;height:18px;min-width:18px;max-width:18px;fill:#fff;';
73
+ fullscreenIcon.innerHTML = '<path d="M7 14H5v5h5v-2H7v-3zm-2-4h2V7h3V5H5v5zm12 7h-3v2h5v-5h-2v3zM14 5v2h3v3h2V5h-5z"/>';
74
+ fullscreenBtn.appendChild(fullscreenIcon);
75
+ actions.appendChild(fullscreenBtn);
76
+
77
+ header.appendChild(title);
78
+ header.appendChild(actions);
51
79
  container.appendChild(header);
52
80
 
53
- // Iframe for viewer
81
+ // Iframe wrapper
54
82
  var iframeWrapper = document.createElement('div');
55
83
  iframeWrapper.className = 'pdf-secure-embed-body';
84
+ iframeWrapper.style.cssText = 'position:relative;width:100%;height:600px;background:#525659;';
56
85
 
57
86
  var iframe = document.createElement('iframe');
58
87
  iframe.className = 'pdf-secure-iframe';
88
+ iframe.style.cssText = 'width:100%;height:100%;border:none;display:block;';
59
89
  iframe.src = config.relative_path + '/plugins/pdf-secure/viewer?file=' + encodeURIComponent(filename);
60
90
  iframe.setAttribute('frameborder', '0');
61
91
  iframe.setAttribute('allowfullscreen', 'true');
@@ -65,7 +95,7 @@ console.log('[PDF-Secure] main.js loaded');
65
95
  container.appendChild(iframeWrapper);
66
96
 
67
97
  // Fullscreen button handler
68
- header.querySelector('.pdf-secure-fullscreen-btn').addEventListener('click', function () {
98
+ fullscreenBtn.addEventListener('click', function () {
69
99
  if (iframe.requestFullscreen) {
70
100
  iframe.requestFullscreen();
71
101
  } else if (iframe.webkitRequestFullscreen) {
@@ -75,63 +105,8 @@ console.log('[PDF-Secure] main.js loaded');
75
105
  }
76
106
  });
77
107
 
78
- // Check for NodeBB upload container and replace it instead of just the link
79
- var uploadContainer = link.closest('.upload-container, .uploaded-file, .attachment, [data-upload], .img-responsive');
80
- var nodebbPreview = link.closest('p, div');
81
-
82
- // Also look for sibling image/icon that NodeBB might show
83
- var prevSibling = link.previousElementSibling;
84
- var parentParagraph = link.parentElement;
85
-
86
- // If the link is inside a paragraph with just the link and maybe an icon, replace the whole paragraph
87
- if (parentParagraph && parentParagraph.tagName === 'P') {
88
- var textContent = parentParagraph.textContent.trim();
89
- var linkText = link.textContent.trim();
90
- // If paragraph only contains the link text (maybe with some whitespace), replace the whole paragraph
91
- if (textContent === linkText || textContent === filename || textContent === decodeURIComponent(filename)) {
92
- parentParagraph.replaceWith(container);
93
- return;
94
- }
95
- }
96
-
97
- // Hide any preceding SVG or image that looks like a file icon
98
- if (prevSibling && (prevSibling.tagName === 'SVG' || prevSibling.tagName === 'IMG' || prevSibling.classList.contains('file-icon'))) {
99
- prevSibling.style.display = 'none';
100
- }
101
-
102
- // If there's an upload container, replace it entirely
103
- if (uploadContainer) {
104
- uploadContainer.replaceWith(container);
105
- } else {
106
- link.replaceWith(container);
107
- }
108
- });
109
- });
110
-
111
- // Also hide any remaining large file preview icons that NodeBB might render
112
- postContents.forEach(function (content) {
113
- // Hide default NodeBB file preview containers for PDFs
114
- var fileIcons = content.querySelectorAll('img[src*=".pdf"], svg.file-icon, .file-preview');
115
- fileIcons.forEach(function (icon) {
116
- // Check if this is near a pdf-secure-embed
117
- var nearEmbed = icon.closest('.pdf-secure-embed');
118
- if (!nearEmbed) {
119
- // Check if there's a pdf-secure-embed nearby
120
- var parent = icon.parentElement;
121
- if (parent) {
122
- var siblingEmbed = parent.querySelector('.pdf-secure-embed');
123
- if (siblingEmbed) {
124
- icon.style.display = 'none';
125
- }
126
- }
127
- }
108
+ link.replaceWith(container);
128
109
  });
129
110
  });
130
111
  }
131
-
132
- function escapeHtml(str) {
133
- var d = document.createElement('div');
134
- d.textContent = str;
135
- return d.innerHTML;
136
- }
137
112
  })();