ისწავლე / მეტი / რაც / არიცი
/
Person 1 Person 2 Person 3

მიმდინარეობს / ჩატვირთვა...


სურათის ატვირთვა პირად შეტყობინებაში
კატეგორია: სკრიპტები/
ატვირთა: ianoiano242424
დამატების დრო: 15.05.2025 / 13:45
ნანახია: 1
Code
<!-- ✅ ატვირთვის ღილაკი -->
<div id="uploadWrapper" style="display: none;">
<button id="uploadBtn" title="აირჩიე სურათი ასატვირთად" type="button" style="

  margin-top: -17px;
  background: #000;
  color: #fff;
  border: 2px solid red;
  font-size: 14px;
  cursor: pointer;
  font-weight: bold;
  position: relative;
right: -749px;
  top: -29px;
">
  ატვირთე ფოტო შეტყობინებაში!
</button>

<!-- ✅ ფაილის არჩევა (დამალულია) -->
<input type="file" id="uploadToImgur" accept="image/*" style="display: none;">

<!-- ✅ სტატუსის გამოჩენა -->
<div id="uploadStatus"></div>

<!-- ✅ სკრიპტი -->
<script>
document.getElementById("uploadBtn").addEventListener("click", function () {
  document.getElementById("uploadToImgur").click();
});

document.getElementById("uploadToImgur").addEventListener("change", function () {
  var file = this.files[0];
  if (!file || !file.type.startsWith("image/")) {
  alert("გთხოვ აირჩიო მხოლოდ სურათი!");
  return;
  }

  var formData = new FormData();
  formData.append("image", file);

  // ✅ Imgur Client-ID (უნდა იმუშაოს ნებისმიერ შემთხვევაში)
const clientId = "a4512aae58a0d49";

  document.getElementById("uploadStatus").textContent = "⏳ სურათი იტვირთება... გთხოვ დაელოდე.";

  fetch("https://api.imgur.com/3/image", {
  method: "POST",
  headers: {
  Authorization: "Client-ID " + clientId
  },
  body: formData
  })
  .then(res => res.json())
  .then(data => {
  if (data.success) {
  var imageUrl = data.data.link;
  var textarea = document.getElementById("message");
  textarea.value += `[img]` + imageUrl + `[/img]\n`;
  document.getElementById("uploadStatus").textContent = "✔ ატვირთულია და ჩასმულია შეტყობინებაში!";
  } else {
  document.getElementById("uploadStatus").textContent = "‼ ატვირთვის შეცდომა.";
  }
  })
  .catch(() => {
  document.getElementById("uploadStatus").textContent = "‼ სერვერთან კავშირის პრობლემა.";
  });
});
</script>
<script>
setInterval(function () {
  var textarea = document.getElementById("message");
  var uploadWrapper = document.getElementById("uploadWrapper");

  if (textarea && textarea.offsetParent !== null) {
  uploadWrapper.style.display = "block";
  } else {
  uploadWrapper.style.display = "none";
  }
}, 200);

</script>
<style>
#uploadStatus {
  color: #ff0000;
  font-weight: bold;
  font-family: 'BPG Arial Caps', sans-serif;
  left: 554px;
  margin: -52px 476px 4px;
  position: absolute;
  font-size: 14px;
}

</style>
© 2011 - 2025 «ISWAVLEMETI.COM» - გაკვეთილები სკრიპტები ... uCoz