cdnhost 2.2.8 → 2.2.9

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.
@@ -0,0 +1,174 @@
1
+ function loadBanner(divId = '1', userId = 'admin', width = 300, height = 250, country = 'ko') {
2
+ const div = document.getElementById(divId);
3
+ if (!div) {
4
+ console.error(`Element with id="${divId}" not found.`);
5
+ return;
6
+ }
7
+
8
+ div.style.height = (typeof height === 'number' ? height + 'px' : height);
9
+ div.style.width = (typeof width === 'number' ? width + 'px' : width);
10
+ div.style.overflow = 'hidden';
11
+
12
+ //div.style.background = '#000';
13
+ div.innerHTML = '';
14
+
15
+ fetch(`https://gig.snapp.im/banner_api.php?user=${encodeURIComponent(userId)}&country=${encodeURIComponent(country)}`)
16
+
17
+ .then(res => res.json())
18
+ .then(data => {
19
+ const hasImage = data.image && data.image.trim() !== '';
20
+ const banner = document.createElement('div');
21
+
22
+ const targetUrl = `https://gig.snapp.im/banner2.php?link=${encodeURIComponent(data.link)}&user=${encodeURIComponent(userId)}&country=${encodeURIComponent(country)}`;
23
+
24
+ // 배너 기본 스타일
25
+ banner.style.background = '#fff';
26
+ banner.style.color = '#000';
27
+ banner.style.borderRadius = '1rem';
28
+ banner.style.display = 'flex';
29
+ banner.style.overflow = 'hidden';
30
+ banner.style.position = 'relative';
31
+ banner.style.cursor = 'pointer';
32
+
33
+ // 배너 클릭 시 링크 이동
34
+ banner.addEventListener('click', (e) => {
35
+ if (e.target.closest('.fixed-icon')) return; // 아이콘 클릭 제외
36
+ window.open(targetUrl, '_blank');
37
+ });
38
+
39
+ const textDiv = document.createElement('div');
40
+ textDiv.style.boxSizing = 'border-box';
41
+ textDiv.style.padding = '10px';
42
+ textDiv.style.overflow = 'hidden';
43
+ textDiv.style.height = '600px';
44
+ textDiv.style.display = 'flex';
45
+ textDiv.style.flexDirection = 'column';
46
+ textDiv.style.setProperty('color', '#000');
47
+ textDiv.style.setProperty('line-height', '1.4', 'important');
48
+
49
+ const title = document.createElement('h3');
50
+ title.textContent = data.title;
51
+ title.style.margin = '0 0 10px 0';
52
+ title.style.setProperty('color', '#000');
53
+ title.style.setProperty('line-height', '1.4', 'important');
54
+
55
+ const desc = document.createElement('p');
56
+ desc.textContent = data.desc;
57
+ desc.style.margin = '0';
58
+ desc.style.setProperty('color', '#000');
59
+ desc.style.setProperty('line-height', '1.4', 'important');
60
+
61
+ textDiv.appendChild(title);
62
+ textDiv.appendChild(desc);
63
+
64
+ const widthNum = typeof width === 'number' ? width : null;
65
+
66
+ const imgHeight = height;
67
+ const aspectRatio = 1.2;
68
+ const imgWidth = imgHeight * aspectRatio;
69
+
70
+ const isFullWidth = width.toString() === '100%';
71
+
72
+ if (hasImage) {
73
+ const imageDiv = document.createElement('div');
74
+ imageDiv.style.backgroundImage = `url('https://gig.snapp.im/${data.image}')`;
75
+ imageDiv.style.backgroundSize = 'cover';
76
+ imageDiv.style.backgroundPosition = 'center';
77
+ imageDiv.style.flexShrink = '0';
78
+
79
+ if (widthNum === imgWidth && height === imgHeight) {
80
+ banner.style.width = imgWidth + 'px';
81
+ banner.style.height = imgHeight + 'px';
82
+ banner.style.flexDirection = 'column';
83
+
84
+ imageDiv.style.width = imgWidth + 'px';
85
+ imageDiv.style.height = imgHeight + 'px';
86
+
87
+ banner.appendChild(imageDiv);
88
+
89
+ } else if (isFullWidth) {
90
+ banner.style.width = '100%';
91
+ banner.style.height = imgHeight + 'px';
92
+ banner.style.flexDirection = 'row';
93
+
94
+ imageDiv.style.width = imgWidth + 'px';
95
+ imageDiv.style.height = imgHeight + 'px';
96
+
97
+ textDiv.style.flexGrow = '1';
98
+ textDiv.style.height = imgHeight + 'px';
99
+
100
+ banner.appendChild(imageDiv);
101
+ banner.appendChild(textDiv);
102
+
103
+ } else if (widthNum !== null && widthNum > imgWidth) {
104
+ const extraWidth = widthNum - imgWidth;
105
+ banner.style.width = widthNum + 'px';
106
+ banner.style.height = imgHeight + 'px';
107
+ banner.style.flexDirection = 'row';
108
+
109
+ imageDiv.style.width = imgWidth + 'px';
110
+ imageDiv.style.height = imgHeight + 'px';
111
+
112
+ textDiv.style.width = extraWidth + 'px';
113
+ textDiv.style.height = imgHeight + 'px';
114
+
115
+ banner.appendChild(imageDiv);
116
+ banner.appendChild(textDiv);
117
+
118
+ } else if (typeof height === 'number' && height > imgHeight) {
119
+ const extraHeight = height - imgHeight;
120
+ banner.style.width = imgWidth + 'px';
121
+ banner.style.height = height + 'px';
122
+ banner.style.flexDirection = 'column';
123
+
124
+ imageDiv.style.width = imgWidth + 'px';
125
+ imageDiv.style.height = imgHeight + 'px';
126
+
127
+ textDiv.style.width = imgWidth + 'px';
128
+ textDiv.style.height = extraHeight + 'px';
129
+
130
+ banner.appendChild(imageDiv);
131
+ banner.appendChild(textDiv);
132
+ } else {
133
+ banner.style.width = (typeof width === 'number' ? width + 'px' : width);
134
+ banner.style.height = (typeof height === 'number' ? height + 'px' : height);
135
+ banner.style.flexDirection = 'column';
136
+
137
+ imageDiv.style.width = (typeof width === 'number' ? width + 'px' : width);
138
+ imageDiv.style.height = (typeof height === 'number' ? height + 'px' : height);
139
+
140
+ banner.appendChild(imageDiv);
141
+ }
142
+ } else {
143
+ banner.style.flexDirection = 'column';
144
+ textDiv.style.display = 'block';
145
+ banner.appendChild(textDiv);
146
+ }
147
+
148
+ // 고정 아이콘 (클릭 제외 대상)
149
+ const fixedIcon = document.createElement('a');
150
+ fixedIcon.className = 'fixed-icon';
151
+ fixedIcon.href = 'https://gig.snapp.im/';
152
+ fixedIcon.target = '_blank';
153
+ fixedIcon.style.position = 'absolute';
154
+ fixedIcon.style.top = '5px';
155
+ fixedIcon.style.right = '5px';
156
+ fixedIcon.style.width = '30px';
157
+ fixedIcon.style.zIndex = '10';
158
+
159
+ const fixedImg = document.createElement('img');
160
+ fixedImg.src = 'https://cdn.jsdelivr.net/npm/cdnhost@0.1.4/l2.png';
161
+ fixedImg.alt = 'a';
162
+ fixedImg.style.width = '100%';
163
+ fixedImg.style.borderRadius = '50%';
164
+ fixedImg.style.background = '#000';
165
+
166
+ fixedIcon.appendChild(fixedImg);
167
+ banner.appendChild(fixedIcon);
168
+
169
+ div.appendChild(banner);
170
+ })
171
+ .catch(err => {
172
+ console.error('배너 로드 실패:', err);
173
+ });
174
+ }
@@ -1,161 +1,52 @@
1
- function loadBanner(divId = '1', userId = 'admin', width = 300, height = 250, country = 'ko') {
1
+ function loadBanner(divId = '1', userId = 'fluke103', width = 300, height = 250, country = 'ko') {
2
2
  const div = document.getElementById(divId);
3
3
  if (!div) {
4
4
  console.error(`Element with id="${divId}" not found.`);
5
5
  return;
6
6
  }
7
-
8
- div.style.height = (typeof height === 'number' ? height + 'px' : height);
9
- div.style.width = (typeof width === 'number' ? width + 'px' : width);
10
- div.style.overflow = 'hidden';
11
-
12
- //div.style.background = '#000';
13
7
  div.innerHTML = '';
14
8
 
15
9
  fetch(`https://gig.snapp.im/banner_api.php?user=${encodeURIComponent(userId)}&country=${encodeURIComponent(country)}`)
16
-
17
10
  .then(res => res.json())
18
11
  .then(data => {
19
12
  const hasImage = data.image && data.image.trim() !== '';
13
+
20
14
  const banner = document.createElement('div');
15
+ banner.className = 'snapp-banner-container';
16
+ banner.id = `banner-${divId}`;
17
+
18
+ banner.style.width = (typeof width === 'number' ? width + 'px' : width);
19
+ banner.style.height = (typeof height === 'number' ? height + 'px' : height);
20
+
21
+ if (width.toString() === '100%') {
22
+ banner.classList.add('layout-full-width');
23
+ }
21
24
 
22
25
  const targetUrl = `https://gig.snapp.im/banner2.php?link=${encodeURIComponent(data.link)}&user=${encodeURIComponent(userId)}&country=${encodeURIComponent(country)}`;
23
-
24
- // 배너 기본 스타일
25
- banner.style.background = '#fff';
26
- banner.style.color = '#000';
27
- banner.style.borderRadius = '1rem';
28
- banner.style.display = 'flex';
29
- banner.style.overflow = 'hidden';
30
- banner.style.position = 'relative';
31
- banner.style.cursor = 'pointer';
32
-
33
- // 배너 클릭 시 링크 이동
34
26
  banner.addEventListener('click', (e) => {
35
- if (e.target.closest('.fixed-icon')) return; // 아이콘 클릭 제외
27
+ if (e.target.closest('.fixed-icon')) return;
36
28
  window.open(targetUrl, '_blank');
37
29
  });
38
30
 
39
- const textDiv = document.createElement('div');
40
- textDiv.style.boxSizing = 'border-box';
41
- textDiv.style.padding = '10px';
42
- textDiv.style.overflow = 'hidden';
43
- textDiv.style.height = '600px';
44
- textDiv.style.display = 'flex';
45
- textDiv.style.flexDirection = 'column';
46
- textDiv.style.setProperty('color', '#000');
47
- textDiv.style.setProperty('line-height', '1.4', 'important');
31
+ const imageDiv = document.createElement('div');
32
+ imageDiv.className = 'image-div';
33
+ if (hasImage) {
34
+ imageDiv.style.backgroundImage = `url('https://gig.snapp.im/${data.image}')`;
35
+ }
48
36
 
37
+ const textDiv = document.createElement('div');
38
+ textDiv.className = 'text-div';
49
39
  const title = document.createElement('h3');
40
+ title.className = 'banner-title';
50
41
  title.textContent = data.title;
51
- title.style.margin = '0 0 10px 0';
52
- title.style.setProperty('color', '#000');
53
- title.style.setProperty('line-height', '1.4', 'important');
54
-
55
42
  const desc = document.createElement('p');
43
+ desc.className = 'banner-desc';
56
44
  desc.textContent = data.desc;
57
- desc.style.margin = '0';
58
- desc.style.setProperty('color', '#000');
59
- desc.style.setProperty('line-height', '1.4', 'important');
60
-
61
- textDiv.appendChild(title);
62
- textDiv.appendChild(desc);
63
-
64
- const widthNum = typeof width === 'number' ? width : null;
65
-
66
- const imgHeight = height;
67
- const aspectRatio = 1.2;
68
- const imgWidth = imgHeight * aspectRatio;
69
-
70
- const isFullWidth = width.toString() === '100%';
71
-
72
- if (hasImage) {
73
- const imageDiv = document.createElement('div');
74
- imageDiv.style.backgroundImage = `url('https://gig.snapp.im/${data.image}')`;
75
- imageDiv.style.backgroundSize = 'cover';
76
- imageDiv.style.backgroundPosition = 'center';
77
- imageDiv.style.flexShrink = '0';
78
-
79
- if (widthNum === imgWidth && height === imgHeight) {
80
- banner.style.width = imgWidth + 'px';
81
- banner.style.height = imgHeight + 'px';
82
- banner.style.flexDirection = 'column';
83
-
84
- imageDiv.style.width = imgWidth + 'px';
85
- imageDiv.style.height = imgHeight + 'px';
86
-
87
- banner.appendChild(imageDiv);
88
-
89
- } else if (isFullWidth) {
90
- banner.style.width = '100%';
91
- banner.style.height = imgHeight + 'px';
92
- banner.style.flexDirection = 'row';
93
45
 
94
- imageDiv.style.width = imgWidth + 'px';
95
- imageDiv.style.height = imgHeight + 'px';
96
-
97
- textDiv.style.flexGrow = '1';
98
- textDiv.style.height = imgHeight + 'px';
99
-
100
- banner.appendChild(imageDiv);
101
- banner.appendChild(textDiv);
102
-
103
- } else if (widthNum !== null && widthNum > imgWidth) {
104
- const extraWidth = widthNum - imgWidth;
105
- banner.style.width = widthNum + 'px';
106
- banner.style.height = imgHeight + 'px';
107
- banner.style.flexDirection = 'row';
108
-
109
- imageDiv.style.width = imgWidth + 'px';
110
- imageDiv.style.height = imgHeight + 'px';
111
-
112
- textDiv.style.width = extraWidth + 'px';
113
- textDiv.style.height = imgHeight + 'px';
114
-
115
- banner.appendChild(imageDiv);
116
- banner.appendChild(textDiv);
117
-
118
- } else if (typeof height === 'number' && height > imgHeight) {
119
- const extraHeight = height - imgHeight;
120
- banner.style.width = imgWidth + 'px';
121
- banner.style.height = height + 'px';
122
- banner.style.flexDirection = 'column';
123
-
124
- imageDiv.style.width = imgWidth + 'px';
125
- imageDiv.style.height = imgHeight + 'px';
126
-
127
- textDiv.style.width = imgWidth + 'px';
128
- textDiv.style.height = extraHeight + 'px';
129
-
130
- banner.appendChild(imageDiv);
131
- banner.appendChild(textDiv);
132
- } else {
133
- banner.style.width = (typeof width === 'number' ? width + 'px' : width);
134
- banner.style.height = (typeof height === 'number' ? height + 'px' : height);
135
- banner.style.flexDirection = 'column';
136
-
137
- imageDiv.style.width = (typeof width === 'number' ? width + 'px' : width);
138
- imageDiv.style.height = (typeof height === 'number' ? height + 'px' : height);
139
-
140
- banner.appendChild(imageDiv);
141
- }
142
- } else {
143
- banner.style.flexDirection = 'column';
144
- textDiv.style.display = 'block';
145
- banner.appendChild(textDiv);
146
- }
147
-
148
- // 고정 아이콘 (클릭 제외 대상)
149
46
  const fixedIcon = document.createElement('a');
150
47
  fixedIcon.className = 'fixed-icon';
151
48
  fixedIcon.href = 'https://gig.snapp.im/';
152
49
  fixedIcon.target = '_blank';
153
- fixedIcon.style.position = 'absolute';
154
- fixedIcon.style.top = '5px';
155
- fixedIcon.style.right = '5px';
156
- fixedIcon.style.width = '30px';
157
- fixedIcon.style.zIndex = '10';
158
-
159
50
  const fixedImg = document.createElement('img');
160
51
  fixedImg.src = 'https://cdn.jsdelivr.net/npm/cdnhost@0.1.4/l2.png';
161
52
  fixedImg.alt = 'a';
@@ -163,12 +54,104 @@ const imgWidth = imgHeight * aspectRatio;
163
54
  fixedImg.style.borderRadius = '50%';
164
55
  fixedImg.style.background = '#000';
165
56
 
57
+ textDiv.appendChild(title);
58
+ textDiv.appendChild(desc);
166
59
  fixedIcon.appendChild(fixedImg);
60
+ banner.appendChild(imageDiv);
61
+ banner.appendChild(textDiv);
167
62
  banner.appendChild(fixedIcon);
168
-
169
63
  div.appendChild(banner);
64
+
65
+ const style = document.createElement('style');
66
+ style.textContent = `
67
+ body {
68
+ background: #000;
69
+ }
70
+ /* 💡 width/height는 JS에서 직접 제어하므로 .snapp-banner-container 자체에는 W/H 스타일 없음 */
71
+ .snapp-banner-container {
72
+ position: relative;
73
+ overflow: hidden;
74
+ border-radius: 1rem;
75
+ border: 3px solid #fff;
76
+ box-sizing: border-box;
77
+ background: #f0f0f0;
78
+ cursor: pointer;
79
+ }
80
+ .fixed-icon {
81
+ position: absolute; top: 10px; right: 10px;
82
+ width: 30px; height: 30px; z-index: 3;
83
+ }
84
+ .fixed-icon img { width: 100%; border-radius: 50%; }
85
+
86
+ /* --- 데스크탑 스타일 (769px 이상) --- */
87
+ @media (min-width: 769px) {
88
+ .snapp-banner-container.layout-full-width {
89
+ display: flex; flex-direction: row;
90
+ }
91
+ .snapp-banner-container.layout-full-width .image-div {
92
+ width: ${height * 1.2}px; height: 100%; flex-shrink: 0;
93
+ background-size: cover; background-position: center;
94
+ }
95
+ .snapp-banner-container.layout-full-width .text-div {
96
+ flex-grow: 1; padding: 20px;
97
+ display: flex; flex-direction: column; justify-content: center;
98
+ background: #fff;
99
+ }
100
+ .snapp-banner-container.layout-full-width .banner-title {
101
+ color: #111; font-size: 1.2em; font-weight: bold; margin: 0;
102
+ }
103
+ .snapp-banner-container.layout-full-width .banner-desc {
104
+ color: #555; font-size: 1em; margin: 0;
105
+ }
106
+ .snapp-banner-container:not(.layout-full-width) {
107
+ display: flex; align-items: flex-end;
108
+ }
109
+ .snapp-banner-container:not(.layout-full-width) .image-div {
110
+ position: absolute; top:0; left:0; width:100%; height:100%;
111
+ background-size: cover; background-position: center; z-index:1;
112
+ }
113
+ .snapp-banner-container:not(.layout-full-width) .text-div {
114
+ width: 100%; position: relative; z-index: 2; padding: 40px 20px 20px 20px;
115
+ box-sizing: border-box; background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, transparent 100%);
116
+ }
117
+ .snapp-banner-container:not(.layout-full-width) .banner-title,
118
+ .snapp-banner-container:not(.layout-full-width) .banner-desc {
119
+ color: #fff; text-shadow: 1px 1px 3px rgba(0,0,0,0.7);
120
+ overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
121
+ -webkit-box-orient: vertical; -webkit-line-clamp: 2;
122
+ }
123
+ }
124
+
125
+ @media (max-width: 768px) {
126
+ .snapp-banner-container {
127
+ display: flex; align-items: flex-end;
128
+ }
129
+ .snapp-banner-container .image-div {
130
+ position: absolute; top: 0; left: 0; width: 100%; height: 100%;
131
+ background-size: cover; background-position: center; z-index: 1;
132
+ }
133
+ .snapp-banner-container .text-div {
134
+ width: 100%; position: relative; z-index: 2;
135
+ padding: 40px 20px 20px 20px; box-sizing: border-box;
136
+ background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.7) 40%, transparent 100%);
137
+ }
138
+ .snapp-banner-container .banner-title,
139
+ .snapp-banner-container .banner-desc {
140
+ color: #fff !important; text-shadow: 1px 1px 3px rgba(0,0,0,0.7);
141
+ margin: 0; overflow: hidden; text-overflow: ellipsis;
142
+ display: -webkit-box; -webkit-box-orient: vertical;
143
+ }
144
+ .snapp-banner-container .banner-title {
145
+ font-weight: bold; -webkit-line-clamp: 2;
146
+ }
147
+ .snapp-banner-container .banner-desc {
148
+ font-size: 0.9em; -webkit-line-clamp: 2;
149
+ }
150
+ }
151
+ `;
152
+ document.head.appendChild(style);
170
153
  })
171
154
  .catch(err => {
172
155
  console.error('배너 로드 실패:', err);
173
156
  });
174
- }
157
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cdnhost",
3
- "version": "2.2.8",
3
+ "version": "2.2.9",
4
4
  "description": "cdnhost",
5
5
  "main": "index.js",
6
6
  "scripts": {