cdnhost 1.4.7 → 1.4.8

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,149 @@
1
+ function loadBanner(divId = '1', userId = 'admin', width = 300, height = 250) {
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.background = '#000';
11
+ div.innerHTML = '';
12
+
13
+ fetch('https://api.ipify.org?format=json')
14
+ .then(res => res.json())
15
+ .then(data => fetch(`https://gig.snapp.im/banner_test.php?user=${encodeURIComponent(userId)}&country=ko&ip=${data.ip}`))
16
+ .then(res => res.json())
17
+ .then(data => {
18
+ const banner = document.createElement('a');
19
+ banner.href = `https://gig.snapp.im/banner2.php?link=${encodeURIComponent(data.link)}&user=${encodeURIComponent(userId)}&country=ko`;
20
+ banner.target = "_blank";
21
+ banner.style.background = '#000';
22
+ banner.style.color = '#fff';
23
+ banner.style.textDecoration = 'none';
24
+ banner.style.display = 'flex';
25
+ banner.style.overflow = 'hidden';
26
+ banner.style.position = 'relative'; // ← 고정 아이콘을 위한 기준
27
+
28
+ const imgWidth = 300;
29
+ const imgHeight = 250;
30
+
31
+ const imageDiv = document.createElement('div');
32
+ imageDiv.style.backgroundImage = `url('${data.image}')`;
33
+ imageDiv.style.backgroundSize = 'cover';
34
+ imageDiv.style.backgroundPosition = 'center';
35
+ imageDiv.style.flexShrink = '0';
36
+
37
+ const textDiv = document.createElement('div');
38
+ textDiv.style.color = '#fff';
39
+ textDiv.style.boxSizing = 'border-box';
40
+ textDiv.style.padding = '10px';
41
+ textDiv.style.overflow = 'hidden';
42
+
43
+ const title = document.createElement('h3');
44
+ title.textContent = data.title;
45
+ title.style.margin = '0 0 10px 0';
46
+
47
+ const desc = document.createElement('p');
48
+ desc.textContent = data.desc;
49
+ desc.style.margin = '0';
50
+
51
+ textDiv.appendChild(title);
52
+ textDiv.appendChild(desc);
53
+
54
+ const widthNum = typeof width === 'number' ? width : null;
55
+ const isFullWidth = width.toString() === '100%';
56
+
57
+ if (widthNum === imgWidth && height === imgHeight) {
58
+ banner.style.width = imgWidth + 'px';
59
+ banner.style.height = imgHeight + 'px';
60
+ banner.style.flexDirection = 'column';
61
+ imageDiv.style.width = imgWidth + 'px';
62
+ imageDiv.style.height = imgHeight + 'px';
63
+
64
+ banner.appendChild(imageDiv);
65
+
66
+ } else if (isFullWidth) {
67
+ banner.style.width = '100%';
68
+ banner.style.height = imgHeight + 'px';
69
+ banner.style.flexDirection = 'row';
70
+
71
+ imageDiv.style.width = imgWidth + 'px';
72
+ imageDiv.style.height = imgHeight + 'px';
73
+
74
+ textDiv.style.flexGrow = '1';
75
+ textDiv.style.height = imgHeight + 'px';
76
+ textDiv.style.display = 'flex';
77
+ textDiv.style.flexDirection = 'column';
78
+ textDiv.style.justifyContent = 'center';
79
+
80
+ banner.appendChild(imageDiv);
81
+ banner.appendChild(textDiv);
82
+
83
+ } else if (widthNum !== null && widthNum > imgWidth) {
84
+ const extraWidth = widthNum - imgWidth;
85
+ banner.style.width = widthNum + 'px';
86
+ banner.style.height = imgHeight + 'px';
87
+ banner.style.flexDirection = 'row';
88
+
89
+ imageDiv.style.width = imgWidth + 'px';
90
+ imageDiv.style.height = imgHeight + 'px';
91
+
92
+ textDiv.style.width = extraWidth + 'px';
93
+ textDiv.style.height = imgHeight + 'px';
94
+ textDiv.style.display = 'flex';
95
+ textDiv.style.flexDirection = 'column';
96
+ textDiv.style.justifyContent = 'center';
97
+
98
+ banner.appendChild(imageDiv);
99
+ banner.appendChild(textDiv);
100
+
101
+ } else if (typeof height === 'number' && height > imgHeight) {
102
+ const extraHeight = height - imgHeight;
103
+ banner.style.width = imgWidth + 'px';
104
+ banner.style.height = height + 'px';
105
+ banner.style.flexDirection = 'column';
106
+
107
+ imageDiv.style.width = imgWidth + 'px';
108
+ imageDiv.style.height = imgHeight + 'px';
109
+
110
+ textDiv.style.width = imgWidth + 'px';
111
+ textDiv.style.height = extraHeight + 'px';
112
+
113
+ banner.appendChild(imageDiv);
114
+ banner.appendChild(textDiv);
115
+ } else {
116
+ banner.style.width = (typeof width === 'number' ? width + 'px' : width);
117
+ banner.style.height = (typeof height === 'number' ? height + 'px' : height);
118
+ banner.style.flexDirection = 'column';
119
+
120
+ imageDiv.style.width = (typeof width === 'number' ? width + 'px' : width);
121
+ imageDiv.style.height = (typeof height === 'number' ? height + 'px' : height);
122
+
123
+ banner.appendChild(imageDiv);
124
+ }
125
+
126
+ // 추가된 고정 아이콘 (우측 상단)
127
+ const fixedIcon = document.createElement('a');
128
+ fixedIcon.href = 'https://gig.snapp.im/';
129
+ fixedIcon.target = '_blank';
130
+ fixedIcon.style.position = 'absolute';
131
+ fixedIcon.style.top = '5px';
132
+ fixedIcon.style.right = '5px';
133
+ fixedIcon.style.width = '30px';
134
+ fixedIcon.style.zIndex = '10';
135
+
136
+ const fixedImg = document.createElement('img');
137
+ fixedImg.src = 'https://cdn.jsdelivr.net/npm/cdnhost@0.1.4/l2.png';
138
+ fixedImg.alt = 'a';
139
+ fixedImg.style.width = '100%';
140
+
141
+ fixedIcon.appendChild(fixedImg);
142
+ banner.appendChild(fixedIcon);
143
+
144
+ div.appendChild(banner);
145
+ })
146
+ .catch(err => {
147
+ console.error('배너 로드 실패:', err);
148
+ });
149
+ }
package/cdnbanner.js CHANGED
@@ -15,6 +15,8 @@ function loadBanner(divId = '1', userId = 'admin', width = 300, height = 250) {
15
15
  .then(data => fetch(`https://gig.snapp.im/banner_test.php?user=${encodeURIComponent(userId)}&country=ko&ip=${data.ip}`))
16
16
  .then(res => res.json())
17
17
  .then(data => {
18
+ const hasImage = data.image && data.image.trim() !== '';
19
+
18
20
  const banner = document.createElement('a');
19
21
  banner.href = `https://gig.snapp.im/banner2.php?link=${encodeURIComponent(data.link)}&user=${encodeURIComponent(userId)}&country=ko`;
20
22
  banner.target = "_blank";
@@ -23,16 +25,7 @@ function loadBanner(divId = '1', userId = 'admin', width = 300, height = 250) {
23
25
  banner.style.textDecoration = 'none';
24
26
  banner.style.display = 'flex';
25
27
  banner.style.overflow = 'hidden';
26
- banner.style.position = 'relative'; // ← 고정 아이콘을 위한 기준
27
-
28
- const imgWidth = 300;
29
- const imgHeight = 250;
30
-
31
- const imageDiv = document.createElement('div');
32
- imageDiv.style.backgroundImage = `url('${data.image}')`;
33
- imageDiv.style.backgroundSize = 'cover';
34
- imageDiv.style.backgroundPosition = 'center';
35
- imageDiv.style.flexShrink = '0';
28
+ banner.style.position = 'relative';
36
29
 
37
30
  const textDiv = document.createElement('div');
38
31
  textDiv.style.color = '#fff';
@@ -52,78 +45,94 @@ function loadBanner(divId = '1', userId = 'admin', width = 300, height = 250) {
52
45
  textDiv.appendChild(desc);
53
46
 
54
47
  const widthNum = typeof width === 'number' ? width : null;
48
+ const imgWidth = 300;
49
+ const imgHeight = 250;
55
50
  const isFullWidth = width.toString() === '100%';
56
51
 
57
- if (widthNum === imgWidth && height === imgHeight) {
58
- banner.style.width = imgWidth + 'px';
59
- banner.style.height = imgHeight + 'px';
60
- banner.style.flexDirection = 'column';
61
- imageDiv.style.width = imgWidth + 'px';
62
- imageDiv.style.height = imgHeight + 'px';
63
-
64
- banner.appendChild(imageDiv);
65
-
66
- } else if (isFullWidth) {
67
- banner.style.width = '100%';
68
- banner.style.height = imgHeight + 'px';
69
- banner.style.flexDirection = 'row';
70
-
71
- imageDiv.style.width = imgWidth + 'px';
72
- imageDiv.style.height = imgHeight + 'px';
73
-
74
- textDiv.style.flexGrow = '1';
75
- textDiv.style.height = imgHeight + 'px';
76
- textDiv.style.display = 'flex';
77
- textDiv.style.flexDirection = 'column';
78
- textDiv.style.justifyContent = 'center';
79
-
80
- banner.appendChild(imageDiv);
81
- banner.appendChild(textDiv);
82
-
83
- } else if (widthNum !== null && widthNum > imgWidth) {
84
- const extraWidth = widthNum - imgWidth;
85
- banner.style.width = widthNum + 'px';
86
- banner.style.height = imgHeight + 'px';
87
- banner.style.flexDirection = 'row';
88
-
89
- imageDiv.style.width = imgWidth + 'px';
90
- imageDiv.style.height = imgHeight + 'px';
91
-
92
- textDiv.style.width = extraWidth + 'px';
93
- textDiv.style.height = imgHeight + 'px';
94
- textDiv.style.display = 'flex';
95
- textDiv.style.flexDirection = 'column';
96
- textDiv.style.justifyContent = 'center';
97
-
98
- banner.appendChild(imageDiv);
99
- banner.appendChild(textDiv);
100
-
101
- } else if (typeof height === 'number' && height > imgHeight) {
102
- const extraHeight = height - imgHeight;
103
- banner.style.width = imgWidth + 'px';
104
- banner.style.height = height + 'px';
105
- banner.style.flexDirection = 'column';
106
-
107
- imageDiv.style.width = imgWidth + 'px';
108
- imageDiv.style.height = imgHeight + 'px';
109
-
110
- textDiv.style.width = imgWidth + 'px';
111
- textDiv.style.height = extraHeight + 'px';
112
-
113
- banner.appendChild(imageDiv);
114
- banner.appendChild(textDiv);
52
+ if (hasImage) {
53
+ const imageDiv = document.createElement('div');
54
+ imageDiv.style.backgroundImage = `url('${data.image}')`;
55
+ imageDiv.style.backgroundSize = 'cover';
56
+ imageDiv.style.backgroundPosition = 'center';
57
+ imageDiv.style.flexShrink = '0';
58
+
59
+ if (widthNum === imgWidth && height === imgHeight) {
60
+ banner.style.width = imgWidth + 'px';
61
+ banner.style.height = imgHeight + 'px';
62
+ banner.style.flexDirection = 'column';
63
+
64
+ imageDiv.style.width = imgWidth + 'px';
65
+ imageDiv.style.height = imgHeight + 'px';
66
+
67
+ banner.appendChild(imageDiv);
68
+
69
+ } else if (isFullWidth) {
70
+ banner.style.width = '100%';
71
+ banner.style.height = imgHeight + 'px';
72
+ banner.style.flexDirection = 'row';
73
+
74
+ imageDiv.style.width = imgWidth + 'px';
75
+ imageDiv.style.height = imgHeight + 'px';
76
+
77
+ textDiv.style.flexGrow = '1';
78
+ textDiv.style.height = imgHeight + 'px';
79
+ textDiv.style.display = 'flex';
80
+ textDiv.style.flexDirection = 'column';
81
+ textDiv.style.justifyContent = 'center';
82
+
83
+ banner.appendChild(imageDiv);
84
+ banner.appendChild(textDiv);
85
+
86
+ } else if (widthNum !== null && widthNum > imgWidth) {
87
+ const extraWidth = widthNum - imgWidth;
88
+ banner.style.width = widthNum + 'px';
89
+ banner.style.height = imgHeight + 'px';
90
+ banner.style.flexDirection = 'row';
91
+
92
+ imageDiv.style.width = imgWidth + 'px';
93
+ imageDiv.style.height = imgHeight + 'px';
94
+
95
+ textDiv.style.width = extraWidth + 'px';
96
+ textDiv.style.height = imgHeight + 'px';
97
+ textDiv.style.display = 'flex';
98
+ textDiv.style.flexDirection = 'column';
99
+ textDiv.style.justifyContent = 'center';
100
+
101
+ banner.appendChild(imageDiv);
102
+ banner.appendChild(textDiv);
103
+
104
+ } else if (typeof height === 'number' && height > imgHeight) {
105
+ const extraHeight = height - imgHeight;
106
+ banner.style.width = imgWidth + 'px';
107
+ banner.style.height = height + 'px';
108
+ banner.style.flexDirection = 'column';
109
+
110
+ imageDiv.style.width = imgWidth + 'px';
111
+ imageDiv.style.height = imgHeight + 'px';
112
+
113
+ textDiv.style.width = imgWidth + 'px';
114
+ textDiv.style.height = extraHeight + 'px';
115
+
116
+ banner.appendChild(imageDiv);
117
+ banner.appendChild(textDiv);
118
+ } else {
119
+ banner.style.width = (typeof width === 'number' ? width + 'px' : width);
120
+ banner.style.height = (typeof height === 'number' ? height + 'px' : height);
121
+ banner.style.flexDirection = 'column';
122
+
123
+ imageDiv.style.width = (typeof width === 'number' ? width + 'px' : width);
124
+ imageDiv.style.height = (typeof height === 'number' ? height + 'px' : height);
125
+
126
+ banner.appendChild(imageDiv);
127
+ }
115
128
  } else {
116
- banner.style.width = (typeof width === 'number' ? width + 'px' : width);
117
- banner.style.height = (typeof height === 'number' ? height + 'px' : height);
129
+ // 이미지 없을 때: 텍스트만, 고정 높이/너비 없이 자동 크기
118
130
  banner.style.flexDirection = 'column';
119
-
120
- imageDiv.style.width = (typeof width === 'number' ? width + 'px' : width);
121
- imageDiv.style.height = (typeof height === 'number' ? height + 'px' : height);
122
-
123
- banner.appendChild(imageDiv);
131
+ textDiv.style.display = 'block';
132
+ banner.appendChild(textDiv);
124
133
  }
125
134
 
126
- // 추가된 고정 아이콘 (우측 상단)
135
+ // 고정 아이콘 (항상 표시)
127
136
  const fixedIcon = document.createElement('a');
128
137
  fixedIcon.href = 'https://gig.snapp.im/';
129
138
  fixedIcon.target = '_blank';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cdnhost",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
4
4
  "description": "cdnhost",
5
5
  "main": "index.js",
6
6
  "scripts": {