Update script.js
Browse files
script.js
CHANGED
@@ -1,3 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
async function loadTwitterImage() {
|
2 |
const username = document.getElementById('username-input').value.trim();
|
3 |
if (!username) {
|
@@ -7,26 +15,26 @@ async function loadTwitterImage() {
|
|
7 |
|
8 |
const loading = document.getElementById('loading');
|
9 |
const successMessage = document.getElementById('success-message');
|
10 |
-
const exportBtn = document.getElementById('export-btn');
|
11 |
|
12 |
loading.style.display = 'block';
|
13 |
successMessage.style.display = 'none';
|
14 |
-
exportBtn.disabled = true;
|
15 |
|
16 |
try {
|
17 |
-
const
|
|
|
18 |
const imageUrl = `https://unavatar.io/x/${username}`;
|
19 |
-
|
20 |
-
|
|
|
|
|
21 |
|
22 |
-
|
23 |
loading.style.display = 'none';
|
24 |
successMessage.style.display = 'block';
|
25 |
-
exportBtn.disabled = false;
|
26 |
console.log("تم تحميل الصورة بنجاح");
|
27 |
};
|
28 |
|
29 |
-
|
30 |
loading.style.display = 'none';
|
31 |
alert("حدث خطأ أثناء تحميل الصورة.");
|
32 |
};
|
@@ -47,25 +55,24 @@ function handleImageUpload(event) {
|
|
47 |
|
48 |
const loading = document.getElementById('loading');
|
49 |
const successMessage = document.getElementById('success-message');
|
50 |
-
const exportBtn = document.getElementById('export-btn');
|
51 |
|
52 |
loading.style.display = 'block';
|
53 |
successMessage.style.display = 'none';
|
54 |
-
exportBtn.disabled = true;
|
55 |
|
56 |
const reader = new FileReader();
|
57 |
reader.onload = function(e) {
|
58 |
-
const
|
59 |
-
|
|
|
|
|
60 |
|
61 |
-
|
62 |
loading.style.display = 'none';
|
63 |
successMessage.style.display = 'block';
|
64 |
-
exportBtn.disabled = false;
|
65 |
console.log("تم تحميل الصورة بنجاح");
|
66 |
};
|
67 |
|
68 |
-
|
69 |
loading.style.display = 'none';
|
70 |
alert("حدث خطأ أثناء تحميل الصورة.");
|
71 |
};
|
@@ -74,9 +81,9 @@ function handleImageUpload(event) {
|
|
74 |
}
|
75 |
}
|
76 |
|
77 |
-
|
78 |
-
const profileImg = document.getElementById('profile-
|
79 |
-
const overlayImg = document.getElementById('overlay-
|
80 |
|
81 |
if (!profileImg.src || profileImg.src === window.location.href) {
|
82 |
alert("الرجاء تحميل صورة أولاً.");
|
@@ -84,62 +91,45 @@ async function exportImage() {
|
|
84 |
}
|
85 |
|
86 |
try {
|
87 |
-
// إنشاء نسخة من الصورة العلوية باستخدام `new Image()`
|
88 |
-
const overlay = new Image();
|
89 |
-
overlay.src = overlayImg.src;
|
90 |
-
overlay.crossOrigin = "anonymous";
|
91 |
-
|
92 |
-
// الانتظار حتى يتم تحميل الصور
|
93 |
-
await Promise.all([
|
94 |
-
new Promise((resolve, reject) => {
|
95 |
-
if (profileImg.complete) resolve();
|
96 |
-
else {
|
97 |
-
profileImg.onload = resolve;
|
98 |
-
profileImg.onerror = reject;
|
99 |
-
}
|
100 |
-
}),
|
101 |
-
new Promise((resolve, reject) => {
|
102 |
-
if (overlay.complete) resolve();
|
103 |
-
else {
|
104 |
-
overlay.onload = resolve;
|
105 |
-
overlay.onerror = reject;
|
106 |
-
}
|
107 |
-
})
|
108 |
-
]);
|
109 |
-
|
110 |
const canvas = document.createElement('canvas');
|
111 |
const ctx = canvas.getContext('2d');
|
112 |
-
canvas.width =
|
113 |
-
canvas.height =
|
114 |
-
|
115 |
-
// رسم
|
116 |
-
ctx.
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
ctx.globalAlpha = 1;
|
126 |
|
127 |
-
// إضافة الهاشتاج
|
128 |
ctx.font = "16px Arial";
|
129 |
ctx.fillStyle = "white";
|
130 |
ctx.textAlign = "center";
|
131 |
-
ctx.fillText(
|
132 |
|
133 |
// تصدير الصورة
|
134 |
const link = document.createElement('a');
|
135 |
-
link.download = '
|
136 |
link.href = canvas.toDataURL('image/png');
|
137 |
link.click();
|
138 |
} catch (error) {
|
139 |
console.error("خطأ أثناء التصدير:", error);
|
140 |
alert("حدث خطأ أثناء تصدير الصورة. الرجاء المحاولة مرة أخرى.");
|
141 |
}
|
142 |
-
}
|
143 |
-
|
144 |
-
// تفعيل زر التصدير عند النقر عليه
|
145 |
-
document.getElementById('export-btn').addEventListener('click', exportImage);
|
|
|
1 |
+
let selectedHashtag = "#StandWithPalestine"; // الهاشتاج الافتراضي
|
2 |
+
|
3 |
+
function updateHashtag() {
|
4 |
+
selectedHashtag = document.getElementById('hashtag-select').value;
|
5 |
+
document.getElementById('hashtag1').textContent = selectedHashtag;
|
6 |
+
document.getElementById('hashtag2').textContent = selectedHashtag;
|
7 |
+
}
|
8 |
+
|
9 |
async function loadTwitterImage() {
|
10 |
const username = document.getElementById('username-input').value.trim();
|
11 |
if (!username) {
|
|
|
15 |
|
16 |
const loading = document.getElementById('loading');
|
17 |
const successMessage = document.getElementById('success-message');
|
|
|
18 |
|
19 |
loading.style.display = 'block';
|
20 |
successMessage.style.display = 'none';
|
|
|
21 |
|
22 |
try {
|
23 |
+
const img1 = document.getElementById('profile-image1');
|
24 |
+
const img2 = document.getElementById('profile-image2');
|
25 |
const imageUrl = `https://unavatar.io/x/${username}`;
|
26 |
+
img1.crossOrigin = 'anonymous';
|
27 |
+
img2.crossOrigin = 'anonymous';
|
28 |
+
img1.src = `${imageUrl}?t=${new Date().getTime()}`;
|
29 |
+
img2.src = `${imageUrl}?t=${new Date().getTime()}`;
|
30 |
|
31 |
+
img1.onload = img2.onload = () => {
|
32 |
loading.style.display = 'none';
|
33 |
successMessage.style.display = 'block';
|
|
|
34 |
console.log("تم تحميل الصورة بنجاح");
|
35 |
};
|
36 |
|
37 |
+
img1.onerror = img2.onerror = () => {
|
38 |
loading.style.display = 'none';
|
39 |
alert("حدث خطأ أثناء تحميل الصورة.");
|
40 |
};
|
|
|
55 |
|
56 |
const loading = document.getElementById('loading');
|
57 |
const successMessage = document.getElementById('success-message');
|
|
|
58 |
|
59 |
loading.style.display = 'block';
|
60 |
successMessage.style.display = 'none';
|
|
|
61 |
|
62 |
const reader = new FileReader();
|
63 |
reader.onload = function(e) {
|
64 |
+
const img1 = document.getElementById('profile-image1');
|
65 |
+
const img2 = document.getElementById('profile-image2');
|
66 |
+
img1.src = e.target.result;
|
67 |
+
img2.src = e.target.result;
|
68 |
|
69 |
+
img1.onload = img2.onload = () => {
|
70 |
loading.style.display = 'none';
|
71 |
successMessage.style.display = 'block';
|
|
|
72 |
console.log("تم تحميل الصورة بنجاح");
|
73 |
};
|
74 |
|
75 |
+
img1.onerror = img2.onerror = () => {
|
76 |
loading.style.display = 'none';
|
77 |
alert("حدث خطأ أثناء تحميل الصورة.");
|
78 |
};
|
|
|
81 |
}
|
82 |
}
|
83 |
|
84 |
+
function downloadImage(type) {
|
85 |
+
const profileImg = document.getElementById(type === 'transparent' ? 'profile-image1' : 'profile-image2');
|
86 |
+
const overlayImg = document.getElementById(type === 'transparent' ? 'overlay-image1' : 'overlay-image2');
|
87 |
|
88 |
if (!profileImg.src || profileImg.src === window.location.href) {
|
89 |
alert("الرجاء تحميل صورة أولاً.");
|
|
|
91 |
}
|
92 |
|
93 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
const canvas = document.createElement('canvas');
|
95 |
const ctx = canvas.getContext('2d');
|
96 |
+
canvas.width = 300;
|
97 |
+
canvas.height = 300;
|
98 |
+
|
99 |
+
// رسم صورة ps.png
|
100 |
+
ctx.drawImage(overlayImg, 0, 0, canvas.width, canvas.height);
|
101 |
+
|
102 |
+
// تفعيل الشفافية إذا كانت الصورة الشفافة
|
103 |
+
if (type === 'transparent') {
|
104 |
+
ctx.globalAlpha = 0.5;
|
105 |
+
}
|
106 |
+
|
107 |
+
// رسم الصورة المستوردة
|
108 |
+
if (type === 'circle') {
|
109 |
+
ctx.beginPath();
|
110 |
+
ctx.arc(canvas.width / 2, canvas.height / 2, canvas.width / 2 * 0.8, 0, Math.PI * 2);
|
111 |
+
ctx.closePath();
|
112 |
+
ctx.clip();
|
113 |
+
ctx.drawImage(profileImg, canvas.width * 0.1, canvas.height * 0.1, canvas.width * 0.8, canvas.height * 0.8);
|
114 |
+
} else {
|
115 |
+
ctx.drawImage(profileImg, 0, 0, canvas.width, canvas.height);
|
116 |
+
}
|
117 |
+
|
118 |
ctx.globalAlpha = 1;
|
119 |
|
120 |
+
// إضافة الهاشتاج
|
121 |
ctx.font = "16px Arial";
|
122 |
ctx.fillStyle = "white";
|
123 |
ctx.textAlign = "center";
|
124 |
+
ctx.fillText(selectedHashtag, canvas.width / 2, canvas.height - 15);
|
125 |
|
126 |
// تصدير الصورة
|
127 |
const link = document.createElement('a');
|
128 |
+
link.download = type === 'transparent' ? 'transparent-image.png' : 'circle-image.png';
|
129 |
link.href = canvas.toDataURL('image/png');
|
130 |
link.click();
|
131 |
} catch (error) {
|
132 |
console.error("خطأ أثناء التصدير:", error);
|
133 |
alert("حدث خطأ أثناء تصدير الصورة. الرجاء المحاولة مرة أخرى.");
|
134 |
}
|
135 |
+
}
|
|
|
|
|
|