convert this javascript code to typescript:

/* eslint-disable no-fallthrough */
"use strict";
// window.addEventListener("error", (e) => {
// fetch(
// `/components/head.php?error=${encodeURIComponent(
// `JS: ${e.message} | AT ${e.lineno}:${e.colno} IN ${e.target.location.href}`
// )}`
// );
// });
function log(s) {
// eslint-disable-next-line no-console
console.log(s);
}
const doc = document;
const ar = $('html[lang="ar"]');
function add(el, ...r) {
const ele = $$(el);
for (let i = 0; i < ele.length; i++) {
ele[i].classList.add(r);
}
}
function remove(el, ...removes) {
const ele = $$(el);
for (let i = 0; i < ele.length; i++) {
ele[i].classList.remove(removes);
}
}
function toggle(el, value) {
const ele = $$(el);
for (let i = 0; i < ele.length; i++) {
ele[i].classList.toggle(value);
}
}
function text(el, value) {
const ele = $$(el);
for (let i = 0; i < ele.length; i++) {
T(ele[i], value);
}
}
function $(el) {
return doc.querySelector(el);
}
function $$(el) {
return doc.querySelectorAll(el);
}
function abort(cond, func) {
document.onclick = () => {
// if (eval(cond)) {
//   eval(func);
// }
};
}
function I(ele, value) {
return (ele.innerHTML = value);
}
function T(ele, value) {
return (ele.textContent = value);
}
function TX(ele) {
return ele.textContent.trim();
}
const tagsLoad = $$("[data-src]");
// Load the element by setting the appropriate attributes
const loadElement = (element) => {
// For images, set the src attribute from data-src
const src = element.dataset.src;
if (src) {
element.src = src;
}
// Remove data attributes once loaded to avoid re-loading
element.removeAttribute("data-src");
};
// Function to lazily load tagsLoad with 'data-src' attribute
const lazyLoad = (target) => {
// Set up the observer
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
// Load the element and stop observing it
loadElement(entry.target);
observer.unobserve(entry.target);
}
});
},
{
root: null, // Use the viewport as the root
rootMargin: "0px", // No margins
threshold: 0, // Trigger when 0% of the element is visible
}
);
// Observe each target element
const d = tagsLoad.length;
for (let i = 0; i < d; i++) {
observer.observe(tagsLoad[i]);
}
};
// Polyfill for older browsers (optional)
if ("IntersectionObserver" in window) {
// Initialize lazy loading
lazyLoad();
} else {
const d = tagsLoad.length;
for (let i = 0; i < d; i++) {
loadElement(tagsLoad[i]);
}
}
add("#loader", "none");
for (let i of $$("a")) {
if (i.hostname !== location.hostname && i.hostname !== "") {
i.target = "_blank";
}
}
const urls = {
// Puplic
Exxeer: "أمازون",
Close: "إغلاق",

bathroomIn: {
"shower room - tub": "غرفة الاستحمام - حوض الاستحمام",
},
};
let types = [];
let branch = [];
let brands = [];
function allSubCategories(subCategory: string) {
switch (replaceChar(subCategory)) {
case "apartments-for-sale":
case "apartments-for-rent":
types = allUrls("apartments", 0, 1);
brands = [];
branch = [];
break;
case "villas-for-sale":
case "villas-for-rent":
types = allUrls("villas", 0, 1);
brands = [];
branch = [];
break;
case "vacation-homes-for-sale":
case "vacation-homes-for-rent":
types = allUrls("vacation", 0, 1);
brands = [];
branch = [];
break;
case "commercial-for-sale":
case "commercial-for-rent":
branch = [];
brands = [];
types = allUrls("commercial-for", 0, 1);
break;
case "buildings-lands":
branch = [];
brands = [];
types = allUrls("buildings", 0, 1);
break;
case "tires-batteries-oils-accessories":
branch = [];
brands = [];
types = allUrls("tires", 0, 1);
break;
case "cars-spare-parts":
types = allUrls("cars-spare", 0, 1);
branch = [];
brands = allUrls("carsBrands", 0, 1);
break;
case "cars-for-rent":
case "cars-for-sale":
brands = allUrls("carsBrands", 0, 1);
types = [];
branch = [];
break;
case "motorcycles-accessories":
brands = allUrls("motorCyclesB", 0, 1);
types = [];
branch = [];
break;
case "boats-watercraft":
brands = [];
types = allUrls("boats", 0, 1);
branch = [];
break;
case "heavy-trucks-buses-other-vehicles":
brands = [];
types = allUrls("heavy", 0, 1);
branch = [];
break;
case "mobile-phones":
case "tablets":
brands = allUrls("tabletsB", 0, 1);
types = [];
branch = [];
break;
case "mobile-numbers":
brands = allUrls("mobileNumberB", 0, 1);
types = [];
branch = [];
break;
case "mobile-tablet-accessories":
branch = [];
brands = [];
types = allUrls("mobile", 0, 1);
break;
case "tv-audio-video":
brands = allUrls("tvBrands", 0, 1);
types = allUrls("tv", 0, 1);
branch = [];
break;
case "home-appliances":
types = allUrls("appliances", 0, 1);
brands = allUrls("tvBrands", 0, 1);
branch = [];
break;
case "computers-accessories":
brands = allUrls("computersB", 0, 1);
types = [];
branch = allUrls("desktop-br", 0, 1);
break;
case "video-games-consoles":
branch = allUrls("video-br", 0, 1);
brands = allUrls("videoGamesB", 0, 1);
types = [];
break;
case "cameras-photography":
types = allUrls("cameras", 0, 1);
brands = [];
branch = [];
break;
case "furniture-decor":
types = allUrls("furniture", 0, 1);
brands = [];
branch = [];
break;
case "bathroom":
types = allUrls("bathroomIn", 0, 1);
brands = [];
branch = [];
break;
case "accounting-finance-banking":
types = allUrls("accounting", 0, 1);
branch = [];
brands = [];
break;
case "engineering":
types = allUrls("engineeringIn", 0, 1);
brands = [];
branch = [];
break;
case "designers":
types = allUrls("designersIn", 0, 1);
branch = [];
brands = [];
break;
case "hr":
types = allUrls("hrIn", 0, 1);
branch = [];
brands = [];
break;
case "tourism-travel-hospitality":
types = allUrls("tourism", 0, 1);
branch = [];
brands = [];
break;
case "medical-healthcare-nursing":
types = allUrls("medicalIN", 0, 1);
branch = [];
brands = [];
break;
case "sales":
types = allUrls("salesIn", 0, 1);
branch = [];
brands = [];
break;
case "bedroom":
types = allUrls("bedroomIn", 0, 1);
branch = [];
brands = [];
break;
case "dining-room":
types = allUrls("dining", 0, 1);
branch = [];
brands = [];
break;
case "fabrics-curtains-carpets":
types = allUrls("fabrics", 0, 1);
branch = [];
brands = [];
break;
case "garden-outdoor":
types = allUrls("garden", 0, 1);
branch = [];
brands = [];
break;
case "home-decoration":
types = allUrls("decoration", 0, 1);
branch = [];
brands = [];
break;
case "kitchen-kitchenware":
types = allUrls("kitchen", 0, 1);
brands = [];
branch = [];
break;
case "lightings":
types = allUrls("lightingsIN", 0, 1);
branch = [];
brands = [];
break;
case "living-room":
types = allUrls("living", 0, 1);
branch = [];
brands = [];
break;
case "other-items":
case "luggage":
case "books":
case "board-card-games":
case "events":
case "other-services":
case "other-baby-items":
case "birds-pigeons":
case "dogs":
case "cats":
case "workers-technicians":
case "marketing-and-public-relations":
case "management-consulting":
case "legal-lawyers":
case "it-telecom":
case "guarding-security":
case "drivers-delivery":
case "customer-service-call-center":
case "other-business-industrial-agriculture":
case "whole-business-for-sale":
case "medical-equipment":
case "other-furniture":
types = [];
branch = [];
brands = [];
break;
case "women-clothing":
types = allUrls("women", 0, 1);
brands = [];
branch = [];
break;
case "men-clothing":
types = allUrls("men", 0, 1);
brands = [];
branch = [];
break;
case "women-accessories-cosmetics-personal-care":
types = allUrls("women-acc", 0, 1);
brands = [];
branch = [];
break;
case "men-accessories-personal-care":
types = allUrls("men-acc", 0, 1);
branch = [];
brands = [];
break;
case "other-pets-animals":
types = allUrls("other-pets", 0, 1);
branch = [];
brands = [];
break;
case "accessories-pet-care-products":
types = allUrls("accessories-pet", 0, 1);
branch = [];
brands = [];
break;
case "baby-mom-healthcare":
types = allUrls("baby-mom", 0, 1);
branch = [];
brands = [];
break;
case "baby-clothing":
types = allUrls("baby-clothingIn", 0, 1);
branch = [];
brands = [];
break;
case "baby-feeding-tools":
types = allUrls("baby-feeding", 0, 1);
branch = [];
brands = [];
break;
case "cribs-strollers-carriers":
types = allUrls("cribs", 0, 1);
branch = [];
brands = [];
break;
case "toys":
types = allUrls("toysIn", 0, 1);
brands = [];
branch = [];
break;
case "antiques-collectibles":
types = allUrls("antiques", 0, 1);
branch = [];
brands = [];
break;
case "bicycles":
types = allUrls("bicyclesIn", 0, 1);
branch = [];
brands = [];
break;
case "movies-audios":
types = allUrls("movies", 0, 1);
branch = [];
brands = [];
break;
case "sports-equipment":
types = allUrls("sports", 0, 1);
branch = [];
brands = [];
break;
case "study-tools":
types = allUrls("study", 0, 1);
branch = [];
brands = [];
break;
case "tickets-vouchers":
types = allUrls("tickets", 0, 1);
branch = [];
brands = [];
break;
case "agriculture":
branch = [];
types = allUrls("agricultureIn", 0, 1);
brands = [];
break;
case "construction":
types = allUrls("constructionIn", 0, 1);
brands = [];
branch = [];
break;
case "industrial-equipment":
types = allUrls("industrial", 0, 1);
brands = [];
branch = [];
break;
case "office-furniture-equipment":
types = allUrls("office", 0, 1);
brands = [];
branch = [];
break;
case "restaurants-equipment":
types = allUrls("restaurants", 0, 1);
brands = [];
branch = [];
break;
case "business":
types = allUrls("businessIn", 0, 1);
brands = [];
branch = [];
break;
case "cars":
types = allUrls("carsIn", 0, 1);
brands = [];
branch = [];
break;
case "health-beauty":
types = allUrls("health", 0, 1);
brands = [];
branch = [];
break;
case "home-services-maintenance":
types = allUrls("home-services", 0, 1);
brands = [];
branch = [];
break;
case "medical":
types = allUrls("medicalIn", 0, 1);
brands = [];
branch = [];
break;
case "movers":
types = allUrls("moversIn", 0, 1);
brands = [];
branch = [];
break;
case "pets":
types = allUrls("petsIn", 0, 1);
brands = [];
branch = [];
break;
case "education":
branch = [];
brands = [];
types = allUrls("educationIn", 0, 1);
break;
}
}
function allBranches(branch) {
switch (replaceChar(branch)) {
case "desktop-computers":
case "laptop-computers":
types = [];
break;
case "video-game-consoles":
types = allUrls("video-game", 0, 1);
break;
case "video-games-accessories":
types = allUrls("video-games", 0, 1);
break;
case "computer-accessories-spare-parts":
types = allUrls("computer-acc", 0, 1);
break;
}
}
function replaceChar(ele) {
if (ele) {
return ele
.trim()
.replace(/(all in |»|❭|\n +)/gi, "")
.replace(/ *( |\(|\)|\/|,|&|%20|%2C|%26|'s +|’s +) */gi, "-")
.replace(/(--|---|----)/gi, "-")
.replace(/--/gi, "-")
.toLowerCase();
}
}
function allUrls(search, lang, node) {
let url = [];
if (node) {
for (const i in urls[search]) {
url.push(i);
}
} else {
if (lang) {
for (const i in urls) {
if (typeof urls[i] === "object") {
for (const e in urls[i]) {
if (replaceChar(e) === replaceChar(search)) {
url = urls[i][e];
}
}
} else {
if (replaceChar(i) === replaceChar(search)) {
url = urls[i];
}
}
}
} else {
for (const i in urls) {
if (typeof urls[i] === "object") {
for (const e in urls[i]) {
url.push(e);
}
} else {
url.push(i);
}
}
url = url.flat().find((r) => replaceChar(r) === replaceChar(search));
}
}
return url || search;
}
function trans(ifTrue, ifFalse = ifTrue) {
return ar ? allUrls(ifTrue, 1) : allUrls(ifFalse);
}
const locSearch = location.search;
const pathname = location.pathname;
const currentUrl = location.href;
// function capitalize(el) {
// const r = el.split(' ');
// const s = [];
// for (const a of r) {
// s.push(a[0].toUpperCase() + a.slice(1));
// }
// return s.join(' ');
// }
const checkLog = $(".hamburger-menu .btn");
const search = $(".search-header");
const selectCategory = $(".selectCategory");
const results = $(".search-result");
const categoryIn = $$(
"#nav:not(#sell #nav) .parent-click div a:not(:first-of-type), .nav-links div div > a:not(:first-of-type)"
);
const parentClick = $$(".parent-click:not(:first-of-type), .nav-links > div");
const clickShow = $$(
".click-show:not(.parent .click-show), .nav-links div div"
);
const submit = $$('.sign-in-form input[type="submit"]');
const url = new URLSearchParams(locSearch);
const g = $(".my-chat span");
const footer = $("footer");
function checkLength(input, from, to) {
const inputText = $(`#${input}`);
const errorRes = $(`#${input} ~ .inv`);
inputText.onchange = () => {
if (inputText.value.length < from) {
T(
errorRes,
ar
? `يجب أن يحتوي على أحرف ${from} على الأقل`
: `Must contain at least ${from} characters`
);
} else if (inputText.value.length >= to) {
T(
errorRes,
ar
? `يجب ألا يحتوي على أكثر من ${to} حرفًا`
: `It must not contain more than ${to} characters`
);
} else {
T(errorRes, "");
}
};
}
function valNewPass(newpa, retpa) {
const newPass = $(`#${newpa}`);
const retPass = $(`#${retpa}`);
const g = $(`#${retpa} ~ .inv`);
for (let i = 0; i < submit.length; i++) {
if (newPass.value !== retPass.value) {
T(
g,
ar ? "كلمتا المرور غير متطابقتان" : "The two passwords do not match"
);
submit[i].setAttribute("type", "button");
checkLength(newpa, 6);
} else {
submit[i].setAttribute("type", "submit");
T(g, "");
checkLength(newpa, 6);
}
}
retPass.oninput = () => {
valNewPass(newpa, retpa);
newPass.oninput = () => {
valNewPass(newpa, retpa);
};
};
}
if (g || footer) {
for (let i = 0; i < parentClick.length; i++) {
parentClick[i].onclick = () => {
clickShow[i].classList.add("block");
parentClick[i].onmouseleave = () => {
clickShow[i].classList.remove("block");
};
};
}
}
if (!checkLog) {
add(".sign-in-header", "none");
}
if (g) {
const lang = $("#lang");
const urlLoc = new URLSearchParams(locSearch);
urlLoc.set("lang", replaceChar(TX(lang)));
lang.href = urlLoc.toString().includes("?") ? urlLoc : "?" + urlLoc;
const hrefS = $$(
'.header > a, .hamburger-menu a:not(#lang, [onclick], [href="/help"])'
);
if (checkLog) {
for (const i of hrefS) {
i.href = "#";
i.onclick = () => {
toggle(".log", "flex");
};
}
}
if (!parseInt(TX(g))) {
g.remove();
}
const liTag = (value) => {
url.set("search", value);
return `<a href="/ads/?${url}">${value}</a>`;
};
const searches = (keyWord = "all") => {
if (keyWord === "all" || !keyWord) {
results.classList.add("trend-result");
} else {
results.classList.remove("trend-result");
}
let list = [];
fetch("https://exxeer.com/components/head.php?query=" + (keyWord || "all"))
.then((rs) => rs.json())
.then((result) => {
list = result.map((data) => (data = liTag(data)));
I(results, list.join("") || liTag(search.value));
});
};
// searches()
search.onfocus = () => {
results.classList.add("block");
};
abort(
"!e.target.classList.contains('search-result') && !e.target.classList.contains('search-header')",
"remove('.search-result', 'block');add('.search-result', 'none')"
);
let a = 0;
search.onkeyup = (r) => {
const t = r.target.value;
const f = r.key === "ArrowDown";
const c = r.key === "ArrowUp";
const e = r.key === "Enter";
if (f || c || e) {
if (f) {
a++;
} else if (c) {
a--;
}
const g = $$(".search-result a").length;
a = a <= 1 ? g : a;
a = a >= g ? 1 : a;
remove(".search-result a", "active");
const s = $(`.search-result a:nth-child(${a})`);
s.classList.add("active");
search.value = f || c ? s.textContent : search.value;
if (e) {
url.set("search", t);
location.href = `/ads/?${url}`;
}
} else {
searches(t);
}
};
selectCategory.oninput = () => {
const t = selectCategory.value;
url.delete("type[]");
url.delete("branch");
url.delete("subcategory");
url.delete("brand[]");
if (t === "all") {
url.delete("category");
} else {
url.set("category", t);
}
st(t);
};
const st = (r = selectCategory.value) => {
selectCategory.style.width = `${r.length * 16}px`;
};
if (url.has("category")) {
const rs = selectCategory.querySelector(`[value='${url.get("category")}']`);
for (let i = 0; i < selectCategory.querySelectorAll("option").length; i++) {
if (url.has("category") && rs) {
selectCategory.style.width = `${TX(rs).length * 14}px`;
rs.selected = true;
st();
}
}
}
$("#search").onclick = () => {
if (!search.value) {
url.delete("search");
} else {
url.set("search", search.value);
}
location.href = `/ads/?${url}`;
};
if (url.has("location") || url.has("area")) {
for (const i of $$("#nav a[href]")) {
i.href += url.has("area")
? `&area=${url.get("area")}`
: `&location=${url.get("location")}`;
}
}
if (screen.availWidth < 1152) {
const navLinks = $$("nav > div > a, .nav-links > div > a");
for (let i = 0; i < navLinks.length; i++) {
navLinks[i].setAttribute("href", "#");
}
}
if (screen.availWidth < 768) {
let prevScroll = window.scrollY;
window.onscroll = () => {
const currentScroll = window.scrollY;
if (prevScroll > currentScroll) {
$("header").style.top = "0";
} else {
$("header").style.top = "-48px";
}
prevScroll = currentScroll;
};
}
if (screen.availWidth > 768) {
let prevScroll = window.scrollY;
window.onscroll = () => {
const currentScroll = window.scrollY;
if (prevScroll < currentScroll) {
$("#nav").style.top = "0";
} else {
$("#nav").style.top = "65px";
}
prevScroll = currentScroll;
};
}
const t = $("#welName");
T(t, TX(t) ? `, ${TX(t).split(" ")[0]}` : "");
}
function isMobile() {
const toMatch = [
/Android/i,
/webOS/i,
/iPhone/i,
/iPad/i,
/iPod/i,
/BlackBerry/i,
/Windows Phone/i,
/mobile/i,
];
return toMatch.some((toMatchItem) => navigator.userAgent.match(toMatchItem));
}
function duplicate(array) {
return array.filter((key, index) => array.indexOf(key) === index);
}
const cardFavorite = $$(".card-fav");
const cardFavoriteFill = $$(".card-fav-fill");
cardFavorite.forEach((element) => {
element.onclick = (ele) => {
if ($(".sign-in")) {
$(".sign-in-form").classList.toggle("flex");
}
ele.target.classList.toggle("card-fav-fill");
};
});
cardFavoriteFill.forEach((element) => {
element.onclick = (ele) => {
ele.target.classList.toggle("card-fav-fill");
ele.target.classList.toggle("card-fav");
};
});
const scrollingElement = doc.scrollingElement || doc.body;
const toBottom = (ele = scrollingElement) => {
ele.scrollTop = ele.scrollHeight;
};
// eslint-disable-next-line no-unused-vars
const backTop = (ele = scrollingElement) => {
ele.scrollTop = 0;
};
function radInput(type, array, ele, lang, name = ele) {
const el = $$(`.${ele} label:not(.checked)`);
for (let i = 0; i < el.length; i++) {
I(
el[i],
`<input type='${type}' name='${name + array}' value='${
lang ? el[i].id : replaceChar(TX(el[i]))
}'>${TX(el[i])}`
);
}
}
const removeMessage = $$("[class*='alert'],[id*='alert'], .thanks");
for (let i = 0; i < removeMessage.length; i++) {
removeMessage[i].onclick = () => {
removeMessage[i].style.display = "none";
};
}
const alertLocation = $("#alert-location");
function getLocation(fun) {
if (!navigator.geolocation.getCurrentPosition) {
I(
alertLocation,
ar
? "متصفحك لا يدعم تحديد الموقع!"
: "Your browser doesn't support location identification!"
);
} else {
navigator.geolocation.getCurrentPosition(fun, errHand);
}
}
function errHand(err) {
alertLocation.style.display = "flex";
switch (err.code) {
case err.PERMISSION_DENIED:
T(
alertLocation,
ar
? "التطبيق ليس لديه إذن تحديد الموقع."
: "The app does not have location permission."
);
break;
case err.POSITION_UNAVAILABLE:
T(
alertLocation,
ar ? "موقع الجهاز غير مؤكد." : "Device location is uncertain."
);
break;
case err.TIMEOUT:
T(
alertLocation,
ar
? "انتهت المهلة للحصول على موقع المستخدم."
: "Timed out to get the user's location."
);
break;
case err.UNKNOWN_ERROR:
T(
alertLocation,
ar ? "حدث خطأ ما حاول مرة أخرى." : "Something went wrong!, Try again."
);
break;
}
}
const locationUrl = new URLSearchParams(locSearch);
let locations = $$(".filter-location-in > div > a, .header-map a");
locationUrl.delete("page");
locationUrl.delete("ad");
locationUrl.delete("area");
for (let i = 0; i < locations.length; i++) {
locationUrl.set("location", locations[i].id);
locations[i].setAttribute("href", `/ads/?${locationUrl}`);
}
// / ///////////// START home.js
const cards = $$(".cards-row, .listen-cards");
for (const i of cards) {
if (TX(i).length <= 20) {
if (!i.classList.contains("listen-cards")) {
i.parentElement.remove();
}
} else {
const t = JSON.parse(TX(i));
let s = "";
for (const e of t) {
s += `<article class='listen-card'><a><img alt="" data-src='${
e.photos
}'><div class='card-info'><span class='price'>${
e.price
}</span><h4 class='listen-title'>${
e.title
}</h4><div><div class='listen-location'>${trans(e.area)}, ${trans(
e.location
)}.</div><div class='date'>${
e.created
}</div></div></div></div></a><input ${e.class} value='${
e.id
}'></article>`;
}
I(i, s);
}
}
function price(num) {
if (num.indexOf("allowance") >= 0) {
return trans("for allowance");
}
return new Intl.NumberFormat(ar ? "ar" : undefined, {
maximumSignificantDigits: 21,
style: "currency",
currency: "egp",
}).format(num);
}
function home() {
// const listen = $$(".listen-title");
// const listenImg = $$(".listen-card a");
// for (let i = 0; i < listen.length; i++) {
//   if (listenImg[i]) {
//     listenImg[i].setAttribute(
//       "href",
//       `/ad/?ad=${encodeURIComponent(TX(listen[i]))}`
//     );
//   }
//   T(listen[i], TX(listen[i]).replace(/-[0-9]{0,}$/, ""));
// }
// date($$(".date"));
// const listenImgDir = $$(".listen-card a > img, .ad-img");
// for (let i = 0; i < listenImgDir.length; i++) {
//   const gt = listenImgDir[i].getAttribute("src");
//   const tg = gt.split(" -^- ");
//   listenImgDir[i].setAttribute("src", `/uploads/${tg[parseInt(tg[0]) + 1]}`);
// }
// for (const i of $$(".price:not(#sell .price)")) {
//   T(i, price(TX(i)));
// }
// // console.clear();
}
const formatter = new Intl.RelativeTimeFormat(ar ? "ar" : undefined, {
numeric: "auto",
});
const DIVISIONS = [
{ amount: 60, name: "seconds" },
{ amount: 60, name: "minutes" },
{ amount: 24, name: "hours" },
{ amount: 7, name: "days" },
{ amount: 4.34524, name: "weeks" },
{ amount: 12, name: "months" },
{ amount: Number.POSITIVE_INFINITY, name: "years" },
];
function formatTimeAgo(date) {
let duration = (new Date(date) - new Date()) / 1000;
for (let i = 0; i < DIVISIONS.length; i++) {
const division = DIVISIONS[i];
if (Math.abs(duration) < division.amount) {
return formatter.format(Math.round(duration), division.name);
}
duration /= division.amount;
}
}
function date(listenDate) {
for (let i = 0; i < listenDate.length; i++) {
T(listenDate[i], formatTimeAgo(TX(listenDate[i])) + ".");
}
}
// //////////////// END home.js
// //////////////// START save.js
if (currentUrl.search(/\/myads\//gi) !== -1) {
const r = $("#dash-cards");
const st = $("#new-chats");
let chatsRes = 0;
if (TX(r).length > 10) {
const t = JSON.parse(TX(r));
let s = "";
for (const e of t) {
s += `
<article class='listen-card'><a><img alt="" data-src='${e.photos}'>
<div class='card-info'>
<div>
<span class='price'>${e.price}</span>
<div class='delete' id='${e.id}'>
</div>
</div>
<h4 class='listen-title'>${e.title}</h4>
<ul class='my-card-info'>
<li title='${
ar ? "محادثات" : "chats"
}'><img src='/icons/chat-square-dots.svg' alt='${
ar ? "محادثات" : "chats"
}'>${e.chats}</li>
<li title='${
ar ? "إظهار الرقم" : "Show Number"
}'><img src='/icons/telephone.svg' alt='${
ar ? "إظهار الرقم" : "Show Number"
}'>${e.display_number}</li>
<li title='${ar ? "المشاهدات" : "Views"}'><img src='/icons/eye.svg' alt='${
ar ? "المشاهدات" : "Views"
}'>${e.views}</li>
<li title='${ar ? "المفضلة" : "Favorites"}'><img src='/icons/heart.svg' alt='${
ar ? "المفضلة" : "Favorites"
}'>${e.favorites}</li></ul><div class='date'>${e.created}</div>
</div>
</div>
</a>
<input></article>
`;
}
I(r, s);
const deleteIn = $$(".delete");
const deleteAd = $("#delete-ad");
const chats = $$(".my-card-info li:nth-child(1)");
const showNumber = $$(".my-card-info li:nth-child(2)");
const views = $$(".my-card-info li:nth-child(3)");
const favorites = $$(".my-card-info li:nth-child(4)");
const cardInput = $$(".listen-card> input");
let favoritesRes = 0;
let showNumberRes = 0;
let viewsRes = 0;
for (let i = 0; i < deleteIn.length; i++) {
I(
deleteIn[i],
`<span title='${
ar ? "حذف" : "delete"
}'><img src='/icons/trash.svg' alt='${ar ? "حذف" : "delete"}'></span>`
);
$$(".card-info .delete")[i].onclick = (r) => {
r.preventDefault();
toggle(".delete-ad", "block");
deleteAd.value = deleteIn[i].id;
};
cardInput[i].type = "submit";
cardInput[i].title = ar ? "تعديل" : "edit";
cardInput[i].alt = ar ? "تعديل" : "edit";
cardInput[i].name = "id";
cardInput[i].value = deleteIn[i].id;
viewsRes += parseInt(TX(views[i]));
favoritesRes += parseInt(TX(favorites[i]));
showNumberRes += parseInt(TX(showNumber[i]));
chatsRes += parseInt(TX(chats[i]));
}
T($("#views"), viewsRes);
T($("#show-number"), showNumberRes);
T($("#favorites"), favoritesRes);
const sorts = $$(".sort-by a");
for (let i = 0; i < sorts.length; i++) {
sorts[i].setAttribute("href", `/myads/?sort=${sorts[i].className}`);
}
} else {
T(r, "");
$(".no-result").style.display = "flex";
}
if (parseInt(TX(g))) {
T(st, TX(g));
} else {
const gi = $(".dash-over-view a");
gi.href = "#";
I(
gi,
`<img alt="" src="/icons/chat-square-dots.svg">${
ar ? "الدردشات" : "chats"
}<span id="new-chats">${chatsRes}</span>`
);
}
}
if (currentUrl.search(/\/myfavorites\//gi) !== -1) {
const i = $(".saved-searches");
let s = "";
if (TX(i).length > 10) {
const t = JSON.parse(TX(i));
for (const e of t) {
s += `<article class='listen-card'><a><img alt="" data-src='${
e.photos
}'><div class='card-info'><span class='price'>${
e.price
}</span><h4 class='listen-title'>${
e.title
}</h4><div><div class='listen-location'>${trans(e.area)}, ${trans(
e.location
)}.</div><div class='date'>${
e.created
}</div></div></div></div></a><input class='card-fav-fill' type='submit' name='remove' value='${
e.id
}'></article>`;
}
} else {
$(".no-result").style.display = "flex";
}
I(i, s);
}
const notSub = $$(
'.listen-card form, #delete-ad, .delete, button[name="logOut"], .sign-in-form'
);
for (let i = 0; i < notSub.length; i++) {
notSub[i].onsubmit = () => {};
}
// //////////////// END save.js
// //////////////// START chat.js
if (currentUrl.search(/\/chat\//gi) !== -1 && !checkLog) {
const adId = url.get("ad-id");
const adChat = $("#listen-chat");
const listenView = $(".listen-chat-view");
fetch(`https://exxeer.com/chat/chat.php/?ad-id=${adId}`)
.then((value) => value.json())
.then((res) => {
const t = res.values;
$("#userId").href = `/user/?user-id=${t.userId}`;
$("#tel").href = `tel:${t.phone}`;
T($("#name"), t.name);
$(".listen-chat-header").href = `/ad/?ad=${t.title}`;
T($(".listen-title"), t.title);
$(".img").src = t.photos;
$(".img").classList.add("ad-img");
T($(".price"), t.price);
$("input[name='sales']").value = t.buyer;
const r = res.right;
const c = res.chat;
let s = "";
for (const i of r) {
s += `<a href='/chat/?ad-id=${i.ad}' ${i.class}>
<p><img alt="" class='ad-img' data-src='${i.img}'>${i.title}</p>
${i.unread}
<p>${i.message}</p>
<span class='date'>${i.date}</span>
</a>`;
}
$(".chat-in").innerHTML += s;
const chatS = $$(".chat-in a");
const chat = $(".chat-in a");
if (!chat) {
add(".no-result:last-of-type", "flex");
}
if (!adId) {
$(".chat-top span").onclick = () => {
history.back();
};
add(".chat", "block");
add(".no-result:first-of-type", "flex");
add(".not, .listen-chat-bottom", "v-none");
}
let g = "";
for (const i of c) {
if (i.user === t.userId) {
g += `<div class='listen-message-from'><div class='messageIn'>${i.message}</div><span class='${i.seen} date'>${i.created}</span></div>`;
} else {
g += `<div class='listen-message-to'><div class='messageIn'>${i.message}</div><span class='${i.seen} date'>${i.created}</span></div>`;
}
}
adChat.innerHTML += g;
const emojis = $$(".emojis div span");
const textArea = $("#message");
for (let i = 0; i < emojis.length; i++) {
emojis[i].onclick = () => {
textArea.value += emojis[i].outerText;
};
}
// / ////////////////////////////////////
textArea.oninput = () => {
this.style.height = "39px";
this.style.height = `${this.scrollHeight}px`;
};
// / ///////////////////////////////////////////////
function activeImgMsg() {
const adImg = $$("#listen-chat img");
for (let i = 0; i < adImg.length; i++) {
adImg[i].onclick = (r) => {
r.target.classList.toggle("active");
};
}
}
activeImgMsg();
function showLoc(pos) {
const st = `https://www.google.com/maps/place/${pos.coords.latitude},${pos.coords.longitude}`;
adChat.innerHTML += `<div class="listen-message-to"><div class="messageIn listen-message-gallery"><a href="${st}" target="_blank"><img src="/icons/location-ico.svg" alt="${
ar ? "رابط الموقع" : "Location link"
}"></a></div>`;
const formData = new FormData();
formData.append("message", st);
uploadMultiple(formData);
messageDetails();
}
$("#send-location").onclick = () => {
getLocation(showLoc);
};
function messageDetails() {
const messages = $$("#listen-chat .listen-message-to:last-child");
for (let i = messages.length - 1; i < messages.length; i++) {
messages[
i
].innerHTML += `<span class="message-check now date">${new Date().toISOString()}</span>`;
}
date($$(".date.now"));
}
// / //////////////////////////////
function uploadMultiple(data) {
fetch(`https://exxeer.com/chat/chat.php/?ad-id=${adId}`, {
method: "POST",
body: data,
});
toBottom(listenView);
}
const submitChat = $("#submit-listen-chat");
function submitMessage(value) {
const t = doc.createElement("p");
t.classList.add("listen-message-to");
I(t, `${value}`);
adChat.appendChild(t);
messageDetails();
textArea.style.height = "35px";
}
submitChat.onclick = () => {
const formData = new FormData();
const r = textArea.value;
if (r) {
submitMessage(r);
formData.append("message", r);
uploadMultiple(formData);
textArea.value = "";
toBottom(listenView);
}
};
const imageInput = $("#send-image");
const videoInput = $("#send-video");
const audioInput = $("#send-audio");
const voiceInput = $("#send-voice");
const documentInput = $("#send-document");
function messageGallery(el, type, end) {
el.onchange = (event) => {
textArea.value = "";
const messageGallery = doc.createElement("div");
messageGallery.classList.add(
"listen-message-to",
"listen-message-gallery"
);
let s = "";
for (let i = 0; i < el.files.length; i++) {
if (event.target.files.length > 0) {
s += `<div><${type} data-src="${URL.createObjectURL(
event.target.files[i]
)}">${end}<span>${event.target.files[i].name} (${
Math.round((event.target.files[i].size / 1000000) * 100) / 100
}MB)</span></div>`;
}
}
I(messageGallery, `${s}`);
adChat.appendChild(messageGallery);
messageDetails();
activeImgMsg();
toBottom(listenView);
const formData = new FormData(listenView);
uploadMultiple(formData);
};
}
messageGallery(imageInput, "img", "");
messageGallery(videoInput, "video controls", "</video>");
messageGallery(audioInput, "audio controls", "</audio>");
messageGallery(voiceInput, "audio controls", "</audio>");
documentInput.onchange = (event) => {
const messageGallery = doc.createElement("div");
messageGallery.classList.add(
"listen-message-to",
"listen-message-gallery"
);
let s = "";
for (let i = 0; i < documentInput.files.length; i++) {
if (event.target.files.length > 0) {
s += `<a href='${URL.createObjectURL(
event.target.files[i]
)}'><img alt="" src='/icons/file-earmark.svg'><span>${
event.target.files[i].name
} (${
Math.round((event.target.files[i].size / 1000000) * 100) / 100
}MB)</span></a>`;
}
}
I(messageGallery, `${s}`);
adChat.appendChild(messageGallery);
messageDetails();
activeImgMsg();
};
const allMessages = $$(".messageIn");
for (let i = 0; i < allMessages.length; i++) {
if (
TX(allMessages[i]).search(/( -\^- |\.\w+\w+\w*\w*\w*\w*)+/gi) !== -1
) {
let messagesPaths = "";
const messages = TX(allMessages[i]).split(" -^- ");
allMessages[i].classList.add("listen-message-gallery");
for (let e = 0; e < messages.length; e++) {
const fileSrc = messages[e].slice(
0,
messages[e].search(/-\^-\(\w+\)+$/)
);
let fileSize = messages[e].search(/-\^-\(\w+\)+$/);
fileSize = messages[e].slice(fileSize + 4);
fileSize = `(${
Math.round((fileSize.replace(/\)/, "") / 1000000) * 100) / 100
}MB)`;
const fileName =
messages[e].replaceAll(/-\^-\(\w+\)+$/g, "") + fileSize;
if (
messages[e].search(
/(\.jpeg|\.jpg|\.png|\.tiff|\.bmp|\.gif|\.svg|\.bmp|\.svg|\.eps|\.ai)+/gi
) !== -1
) {
messagesPaths += `<div><img data-src='../uploads/${fileSrc}' alt='${fileName}'><p>${fileName}</p></div>`;
} else if (
messages[e].search(
/(\.mp4|\.avi|\.mpg|\.3gp|\.m4v|\.mgv|\.mov|\.mkv|\.ogv|\.qtm|\.amc|\.dvx|\.flv|\.evo|\.mpeg|\.mpg|\.wimp|\.m4v|\.swf|\.mod|\.dvr|\.dat|\.h264|\.avi|\.asx|\.asf|\.wmv|\.m2t|\.vob|\.rec|\.mts|\.rmvb|\.tp)+/gi
) !== -1
) {
messagesPaths += `<div><video controls data-src='../uploads/${fileSrc}' alt=' ${fileName}'></video><p>${fileName}</p></div>`;
} else if (
messages[e].search(
/(\.M4A|\.FLAC|\.MP3|\.WAV|\.WMA|\.AAC|\.ogg|\.m3u|\.acc|\.wma|\.midi|\.aif|\.m4a|\.mpa|\.pls)+/gi
) !== -1
) {
messagesPaths += `<div><audio controls data-src='../uploads/${fileSrc}' alt=' ${fileName}'></audio><p>${fileName}</p></div>`;
} else if (
messages[e].search(/Https:\/\/Www\.Google\.Com\/Maps/gi) !== -1
) {
messagesPaths += `<a href='${
messages[e]
}' target='_blank'><img src='/icons/location-ico.svg' alt='${
ar ? "رابط" : "Link"
}'></a>`;
} else if (messages[e].search(/(Https:\/\/|Http:\/\/)+/gi) !== -1) {
messagesPaths += `<a href='${
messages[e]
}' target='_blank'><img src='/icons/paper-clip.svg' alt='${
ar ? "رابط الموقع" : "Location Link"
}'><p>${messages[e]}</p></a>`;
} else {
messagesPaths += `<a href='../uploads/${fileSrc}' target='_blank'><img src='/icons/file-earmark.svg' alt=' ${fileName}'><p>${fileName}</p></a>`;
}
}
I(allMessages[i], messagesPaths);
}
}
const a = $("#unreadMes");
const q = $("#allR");
a.onclick = () => {
q.classList.remove("active");
a.classList.add("active");
add(".chat-in > a", "v-none");
for (const a of $$(".chat-in > a")) {
if (a.querySelector("span:nth-child(2)")) {
a.classList.remove("v-none");
a.classList.add("flex");
}
}
};
q.onclick = () => {
q.classList.add("active");
a.classList.remove("active");
remove(".chat-in > a", "v-none");
add(".chat-in > a", "flex");
};
const allS = $("#allS");
const buys = $("#buys");
const sales = $("#sales");
const sale = $("input[name='sales']").value.split(" ,");
const rUrl = "/chat/?ad-id=";
function checkChats(element, method, t, g) {
element.onclick = (r) => {
remove(".chat-type span", "active");
r.target.classList.add("active");
t(".chat-in a", "v-none");
for (let i = 0; i < sale.length - 1; i++) {
for (let e = 0; e < chatS.length; e++) {
if (
eval(
chatS[e].href.replace(`http://localhost${rUrl}`, "") +
method +
sale[i]
)
) {
g(`.chat-in a[href='${rUrl + sale[i]}']`, "v-none");
}
}
}
};
}
checkChats(buys, "===", add, remove);
checkChats(sales, "!==", remove, add);
allS.onclick = (r) => {
remove(".chat-type span", "active");
r.target.classList.add("active");
remove(".chat-in > a", "v-none");
};
for (const a of $$(
".chat-in > a p:nth-child(3), .chat-in > a p:nth-child(2)"
)) {
T(a, TX(a).replace(/(-\^-\(\d+\)|-\^-|-\d+$)/gi, ""));
}
$("#delete").onclick = () => {
const formData = new FormData();
formData.append("delete", "on");
uploadMultiple(formData);
};
const ac = $(".chat-ico-act");
if (!parseInt(TX(ac))) {
ac.remove();
}
toBottom(listenView);
home();
activeImgMsg();
});
}
// //////////////// END chat.js
// //////////////// START mysearches.js
if (currentUrl.search(/\/mysearches\//gi) !== -1) {
const savedSearches = $(".saved-searches");
const savedRes = TX(savedSearches).split(" -^-");
let priceSearch;
let categorySearch;
let locationSearch;
let savedResults = "";
if (savedRes.length - 1) {
for (let i = 0; i < savedRes.length - 1; i++) {
const savedUrl = new URLSearchParams(savedRes[i].trim());
const subcategorySe = trans(savedUrl.get("subcategory"));
const typeS = trans(savedUrl.get("type[]"));
const brandS = trans(savedUrl.get("brand[]"));
const categoryS = trans(savedUrl.get("category"));
const areaS = trans(savedUrl.get("area"));
const locS = trans(savedUrl.get("location"));
const fromS = savedUrl.get("from-price");
const toS = savedUrl.get("to-price");
const stS = trans(savedUrl.get("status[]"));
const soS = trans(savedUrl.get("sort"));
if (typeS) {
categorySearch = typeS;
} else if (subcategorySe) {
categorySearch = subcategorySe;
} else if (categoryS) {
categorySearch = categoryS;
}
if (areaS) {
locationSearch = areaS;
} else if (locS) {
locationSearch = locS;
}
if (fromS && toS) {
priceSearch = `${price(fromS) + " " + trans("to") + " " + price(toS)}`;
} else if (fromS) {
priceSearch = trans("from") + " " + price(fromS);
} else if (toS) {
priceSearch = trans("to") + " " + price(toS);
}
savedResults += `<article class="saved-search"><a href='/ads/?${savedUrl}'>
<div class="saved-search-top">
<span>${trans(categorySearch)} ${
locationSearch ? ` ${trans("in")} ${trans(locationSearch)}` : ""
}</span>
</div>
${
locationSearch
? `<div><span>${trans("location")}:</span><span>${trans(
locationSearch
)}</span></div>`
: ""
}
${
categorySearch
? `<div><span>${trans("category")}:</span><span>${trans(
categorySearch
)}</span></div>`
: ""
}
${
savedUrl.get("price")
? `<div><span>${trans("for allowance")}:</span><span>${trans(
"yes"
)}</span></div>`
: ""
}
${
savedUrl.get("installment")
? `<div><span>${trans("in installments")}:</span><span>${trans(
"yes"
)}</span></div>`
: ""
}
${
priceSearch
? `<div><span>${trans("price")}:</span><span>${priceSearch}</span></div>`
: ""
}
${
stS
? `<div><span>${trans("status")}:</span><span>${trans(stS)}</span></div>`
: ""
}
${soS ? `<div><span>${trans("sort by")}:</span><span>${soS}</span></div>` : ""}
${
brandS
? `<div><span>${trans("brand")}:</span><span>${brandS}</span></div>`
: ""
}
</a>
<input type='submit' class="card-fav-fill" name='remove-search' value='${encodeURIComponent(
savedRes[i]
)}'></input>
</article>`;
}
} else {
$(".no-result").classList.add("flex");
}
I(savedSearches, savedResults);
}
// //////////////// END mysearches.js
// //////////////// START ads.js
const adId = $(".sell-form > input");
function dataList() {
const dataHead = $$(".datalist-head");
const data = $$(".datalist");
const dataGro = $$(".datalist div");
const dataIn = $$(".datalist label");
for (let t = 0; t < dataGro.length; t++) {
dataGro[t].classList.add("v-none");
}
for (let i = 0; i < dataHead.length; i++) {
const st = data[i].querySelector("label:first-of-type");
if (adId.value && TX(dataHead[i])) {
const t = TX(dataHead[i]);
const headD = data[i].querySelector(`input[value='${t}']`);
if (headD) {
headD.checked = true;
T(dataHead[i], headD.value.replaceAll(/-/g, " "));
let headTi = "";
for (const i of dataIn) {
if (
TX(i) === trans(TX($(".locationH"))) ||
TX(i) === TX($(".locationH"))
) {
headTi = i.id;
}
}
const ast = headTi.toLowerCase().split("-");
for (let t = 0; t < dataGro.length; t++) {
dataGro[t].classList.add("v-none");
if (ast[0]) {
$(`.${ast[1] || ast[0]}`).classList.remove("v-none");
}
}
const r = $(`.${t}`);
if (r) {
r.classList.remove("v-none");
}
const s = trans(t);
if (s.length) {
T(dataHead[i], s);
}
}
} else if (st) {
T(dataHead[i], TX(st));
const t = data[i].querySelector("input:first-of-type");
if (t) {
t.checked = true;
}
}
dataHead[i].onclick = (r) => {
data[i].classList.toggle("flex");
for (let f = 0; f < dataIn.length; f++) {
dataIn[f].onclick = (u) => {
if (TX(u.target)) {
data[i].classList.remove("flex");
T(r.target, TX(u.target));
for (let t = 0; t < dataGro.length; t++) {
dataGro[t].classList.add("v-none");
}
const t = u.target.parentElement.classList;
if (t.contains("location")) {
const c = $(`.${u.target.id}`);
c.classList.remove("v-none");
const g = c.querySelector("input");
g.checked = true;
T($(".areaHead"), trans(g.value));
}
t.remove("v-none");
}
};
}
};
}
}
const state = $(".status");
const ship = $(".ship");
function allCategories(category) {
switch (replaceChar(category)) {
case "jobs":
text("#salary", ar ? "مرتب:" : "salary:");
text("#field", ar ? "مجال:" : "field:");
add("#allowance, .in-job", "none");
case "properties":
ship.classList.add("none");
case "pets-accessories":
state.classList.add("none");
break;
}
}
if (currentUrl.search(/\/ads\//gi) !== -1) {
const r = $("#searchIn");
if (r.value) {
search.value = r.value;
}
const filterUrl = new URLSearchParams(locSearch);
const categoryFil = filterUrl.get("category");
const subCategoryFil = filterUrl.get("subcategory");
const typeFil = filterUrl.get("type[]");
const branchFil = filterUrl.get("branch");
let subCategories = [];
if (categoryFil) {
const value = $(
`#nav a[href*="/ads/?category=${categoryFil}"]`
).parentNode.querySelectorAll("div a");
for (let e = 2; e < value.length; e++) {
let href = value[e].href;
const s = href.indexOf("subcategory");
href = href.slice(s + 12);
href = href.slice(0, href.indexOf("&") !== -1 ? href.indexOf("&") : "");
subCategories.push(href);
}
}
subCategories = duplicate(subCategories);
allCategories(categoryFil);
allSubCategories(subCategoryFil);
allBranches(branchFil);
const showMore = (ele) => {
const vr = $(`.${ele}`);
const st = $(`.${ele} + .textClick`);
vr.classList.add("show-more");
if (vr.children.length >= 5) {
st.onclick = () => {
if (TX(st) !== trans("show more")) {
vr.classList.add("show-more");
T(st, trans("show more"));
} else {
vr.classList.toggle("show-more");
T(st, trans("show less"));
}
};
st.classList.remove("none");
} else {
st.classList.add("none");
}
};
const addFil = (ele, array, type, checkbox = "") => {
const el = $(ele);
const clas = el.classList.toString().split(" ")[0];
if (!array.length) {
el.parentNode.classList.add("none");
} else {
el.parentNode.classList.remove("none");
}
let value = "";
for (const i in array) {
value += `<li><label><input type='${type}' name='${
clas + checkbox
}' value='${replaceChar(array[i])}'>${trans(array[i])}</label></li>`;
}
I(el, value);
showMore(clas);
};
addFil(".subcategory", subCategories, "radio");
addFil(".branch", branch, "radio");
addFil(".brand", brands, "checkbox", "[]");
addFil(".type", types, "checkbox", "[]");
const cards = $(".listen-cards");
const rs = doc.createElement("article");
const cardLen = $$(".listen-card").length;
const directory = $(".directory");
cards.insertBefore(rs, cards.children[Math.round(cardLen / 2)]);
rs.classList.add("add-things");
I(
cards.querySelector(".add-things"),
ar
? '<p>هل تريد رؤية الأشياء الخاصة بك هنا؟</p><p>اكسب المال عن طريق بيع الأشياء الخاصة بك،<b> مجانًا!</b></p><a href="/sell " class="outline-btn">بيع الآن<ri>»</ri></a>'
: '<p>do you want to see your things here?</p><p>earn mony by selling your things,<b> for free!</b></p><a href="/sell" class="outline-btn">sell now<ri>»</ri></a>'
);
if (categoryFil) {
directory.innerHTML += `<a href='/ads/?category=${categoryFil}'>${trans(
categoryFil
)}</a>`;
}
let ts;
if (subCategoryFil) {
let tr = "";
for (let e = 0; e < categoryIn.length; e++) {
let href = categoryIn[e].href;
const s = href.indexOf("subcategory");
href = href.slice(s + 12);
href = href.slice(0, href.indexOf("&") !== -1 ? href.indexOf("&") : "");
if (href === subCategoryFil) {
const ts = categoryIn[e].parentElement.querySelector("a").href;
const rs = ts.indexOf("category") + 9;
tr = `/ads/?category=${ts.slice(rs)}`;
break;
}
}
ts = `${tr}&subcategory=${subCategoryFil}`;
directory.innerHTML += `<a href='${ts}'>${trans(subCategoryFil)}</a>`;
}
if (branchFil) {
directory.innerHTML += `<a href='${ts}&branch=${branchFil}'>${trans(
branchFil
)}</a>`;
}
if (typeFil) {
directory.innerHTML += `<a href='${ts}${
branchFil ? `&branch=${branchFil}` : ""
}&type=${typeFil}'>${trans(typeFil)}</a>`;
}
if (!cardLen) {
directory.innerHTML += ar
? "<div class='no-result flex'><img alt=\"\" src='/icons/ban.svg'>يبدو أنه لا توجد نتيجة متاحة!<br>حاول مرة أخرى باستخدام مرشحات مختلفة.</div>"
: "<div class='no-result flex'><img alt=\"\" src='/icons/ban.svg'>There seems to be no result available!<br>Try again using different filters.</div>";
}
locations = $$(".filter-location-in div ul a");
for (let i = 0; i < locations.length; i++) {
locationUrl.delete("location");
locationUrl.set("area", locations[i].id);
locations[i].setAttribute("href", `/ads/?${locationUrl}`);
}
const sortUrl = new URLSearchParams(locSearch);
const sorts = $$(".sort-by a");
for (let i = 0; i < sorts.length; i++) {
sortUrl.set("sort", sorts[i].className);
sorts[i].setAttribute("href", `/ads/?${sortUrl}`);
}
const subSearch = new URLSearchParams(locSearch);
const addUrl = (param) => {
const parameters = $$(`input[name='${param}[]']`);
for (let i = 0; i < parameters.length; i++) {
parameters[i].onclick = () => {
subSearch.set(param, parameters[i].value);
};
}
};
addUrl("status");
addUrl("brand");
addUrl("subcategory");
let pageUrl = new URLSearchParams(locSearch);
const currentPage = parseInt(pageUrl.get("page")) || 1;
pageUrl.delete("page");
pageUrl = `?${pageUrl}&page=`;
const togglePages = $(".toggle-pages");
const lastPage = $(".toggle-pages a:last-of-type");
T($("#ads-results"), `${TX(lastPage)} ${trans("result")}`);
const pages = Math.floor(TX(lastPage) / 40);
if (pages <= 1) {
lastPage.classList.add("none");
} else if (currentPage >= pages - 4) {
I(
togglePages,
`<a href='${pageUrl + 1}'>1</a><a href='${
pageUrl + (currentPage - 1)
}'>❮</a><a href='${pageUrl + (pages - 4)}'>${pages - 4}</a><a href='${
pageUrl + (pages - 3)
}'>${pages - 3}</a><a href='${pageUrl + (pages - 2)}'>${
pages - 2
}</a><a href='${pageUrl + (pages - 1)}'>${pages - 1}</a><a href='${
pageUrl + pages
}'>${pages}</a>${
currentPage + 1 > pages
? ""
: `<a href=${pageUrl}${currentPage + 1}>❯</a>`
}`
);
} else if (currentPage >= 4) {
I(
togglePages,
`<a href='${pageUrl + 1}'>1</a><a href='${
pageUrl + (currentPage - 1)
}'>❮</a><a href='${pageUrl + currentPage}'>${currentPage}</a><a href='${
pageUrl + (currentPage + 1)
}'>${currentPage + 1}</a><a href='${pageUrl + (currentPage + 2)}'>${
currentPage + 2
}</a><a href='${pageUrl + (currentPage + 3)}'>${
currentPage + 3
}</a><a href='${pageUrl + (currentPage + 1)}'>❯</a><a href='${
pageUrl + pages
}'>${pages}</a>`
);
} else {
I(
togglePages,
`${
currentPage >= 1 ? "" : `<a href='${pageUrl + (currentPage - 1)}'>❮</a>`
}<a href='${pageUrl + 1}'>1</a><a href='${pageUrl + 2}'>2</a><a href='${
pageUrl + 3
}'>3</a><a href='${pageUrl + 4}'>4</a><a href='${
pageUrl + (currentPage + 1)
}'>❯</a><a href='${pageUrl + pages}'>${pages}</a>`
);
}
$(
`.toggle-pages a${
currentPage > 1 ? `[href*='&page=${currentPage}']` : ":first-of-type"
}`
).classList.add("active");
const negativePages = $$(
".toggle-pages a[href*='&page=-'],.toggle-pages a[href*='&page=0']"
);
if (negativePages) {
for (let i = 0; i < negativePages.length; i++) {
negativePages[i].classList.add("none");
}
}
const filters = $$(".filters input");
for (let i = 0; i < filters.length; i++) {
if (
filterUrl.has(filters[i].name.replace(/\[\]/gi, ""), filters[i].value) ||
filterUrl.has(filters[i].name, filters[i].value)
) {
const parent = filters[i].parentElement.parentElement.parentElement;
const labelVa = parent.querySelector("label");
const storeIn = filters[i].parentElement.innerHTML;
I(filters[i].parentElement, labelVa.innerHTML);
I(labelVa, storeIn);
const inputVa = parent.querySelector("input");
const store = inputVa.value;
inputVa.value = filters[i].value;
filters[i].value = store;
$(`.filters input[value*='${inputVa.value}']`).checked = true;
}
}
const filter = () => {
const radioFil = $$(".filters [type='radio']");
for (let i = 0; i < radioFil.length; i++) {
radioFil[i].oninput = (r) => {
const t = r.target.name === "branch";
if (r.target.name === "subcategory" || t) {
allSubCategories(r.target.value);
allBranches(r.target.value);
addFil(".branch", branch, "radio");
addFil(".brand", brands, "checkbox", "[]");
addFil(".type", types, "checkbox", "[]");
filterUrl.delete("brand[]");
filterUrl.delete("type[]");
filterUrl.delete("branch");
filter();
if (t) {
$(`.filters input[value='${r.target.value}']`).checked = true;
}
}
filterUrl.set(r.target.name, r.target.value);
};
}
const checkboxFil = $$(".filters [type='checkbox']");
for (let i = 0; i < checkboxFil.length; i++) {
checkboxFil[i].oninput = (r) => {
if (r.target.checked) {
filterUrl.append(checkboxFil[i].name, checkboxFil[i].value);
} else {
filterUrl.delete(checkboxFil[i].name, checkboxFil[i].value);
}
};
}
};
filter();
const price = $("[value='allowance']");
const toPrice = $("#to-price");
const fromPrice = $("#from-price");
fromPrice.oninput = () => {
filterUrl.set("from-price", fromPrice.value);
price.checked = false;
filterUrl.delete("price");
};
toPrice.oninput = () => {
filterUrl.set("to-price", toPrice.value);
price.checked = false;
filterUrl.delete("price");
};
price.onclick = () => {
toPrice.value = "";
fromPrice.value = "";
filterUrl.delete("to-price");
filterUrl.delete("from-price");
};
toPrice.value = filterUrl.get("to-price");
fromPrice.value = filterUrl.get("from-price");
$("#search-filter").onclick = () => {
location.href = `?${filterUrl}`;
};
const trendSearches = $(".trend-searches");
if (TX(trendSearches).length > 5) {
const trends = JSON.parse(TX(trendSearches));
let trendSearch = "";
for (const i in trends) {
url.set("search", trends[i]);
trendSearch += `<li><a href='/ads/?${url}'>${trends[i]}</a></li>`;
}
I(
trendSearches,
(ar ? "عمليات البحث الشائعة:" : "popular searches:") + trendSearch
);
} else {
trendSearches.classList.add("none");
}
$("#save-search").onclick = (r) => {
if (checkLog) {
toggle("log", "flex");
} else {
fetch(
`/components/head.php?${r.target.dataset.search}=${encodeURIComponent(
locSearch.slice(1)
)}`
);
if (r.target.innerHTML.includes("heart.svg")) {
r.target.dataset.search = "remove-search";
I(r.target, `<img alt="" src="/icons/heart-fill.svg">${trans("save")}`);
} else {
r.target.dataset.search = "search";
I(r.target, `<img alt="" src="/icons/heart.svg">${trans("save")}`);
}
}
};
const searchInput = $("#find-location");
const namesFromDOM = $$(".filter-location-in >div:not(:first-of-type) a");
searchInput.addEventListener("keyup", (event) => {
for (const nameElement of namesFromDOM) {
if (
TX(nameElement).toLowerCase().includes(event.target.value.toLowerCase())
) {
nameElement.style.display = "block";
nameElement.parentElement.classList.add("block");
} else {
nameElement.style.display = "none";
}
if (!searchInput.value) {
nameElement.parentElement.classList.remove("block");
}
}
});
}
// //////////////// END ads.js
// //////////////// START SELL.js
if (currentUrl.search(/\/sell\//gi) !== -1) {
const adDir = $("#directory");
const uploaded = $("#uploaded");
const brandHead = $("#brand");
const brand = $(".brand");
const ifBrand = () => {
if (brands.length) {
let t = "";
for (const i in brands) {
t += `<label><input type='radio' name='brand' value='${replaceChar(
brands[i]
)}'>${trans(brands[i])}</label>`;
}
I(brand, t);
brandHead.classList.remove("none");
} else {
brandHead.classList.add("none");
}
dataList();
};
if (adId.value) {
const valAdDir = TX(adDir).toLowerCase().split(" / ");
const saveC = $(".saveCategory");
let saveCat = "";
if (valAdDir[0]) {
saveCat += `<input type='checkbox' checked name='category' value='${valAdDir[0]}'>`;
}
if (valAdDir[1]) {
saveCat += `<input type='checkbox' checked name='subcategory' value='${valAdDir[1]}'>`;
}
if (valAdDir.length === 4) {
saveCat += `<input type='checkbox' checked name='branch' value='${valAdDir[2]}'><input type='checkbox' checked name='type' value='${valAdDir[3]}'>`;
} else {
if (valAdDir[2]) {
saveCat += `<input type='checkbox' checked name='type' value='${valAdDir[2]}'>`;
}
}
I(adDir, valAdDir.map((r) => (r = trans(r))).join(" / "));
I(saveC, saveCat);
allSubCategories(valAdDir[1]);
ifBrand();
const photos = $(".listen-images");
uploaded.value = TX(photos);
const photosS = TX(photos).split(" -^- ");
let s = "";
for (let i = 1; i < photosS.length; i++) {
s += `<label><input type='radio' name='ad-image' value='${i}'><img alt="" data-src='../uploads/${photosS[i]}'></label>`;
}
I(photos, s);
const photosIn = photos.querySelectorAll("input");
const t = photosIn[parseInt(photosS[0])];
if (t) {
t.checked = true;
}
if (photosIn.length) {
for (const i of photosIn) {
i.oninput = (r) => {
uploaded.value = `${r.target.value - 1} -^- ${photosS
.slice(1)
.join(" -^- ")}`;
};
}
}
const edTitle = $("#listen-title");
edTitle.value = edTitle.value.replace(/-\d+/g, "");
$$(".sell-top h3").forEach((r) => {
T(r, ar ? "تعديل إعلانك" : "edit your ad");
});
T($(".submit"), ar ? "عدل الآن" : "edit now");
T(
$(".sell-form div:last-of-type h3"),
ar ? "تعديل بعض المعلومات:" : "edit some information:"
);
}
const inputAdImages = $("#input-listen-images");
const contImages = $("#images-cont");
const messageGallery = doc.createElement("div");
messageGallery.classList.add("listen-images");
const imagesOut = $(".listen-images-out");
inputAdImages.onchange = (event) => {
imagesOut.classList.add("v-none");
uploaded.value = "";
let s = "";
for (let i = 0; i < inputAdImages.files.length; i++) {
if (i <= 20) {
const a = URL.createObjectURL(event.target.files[i]);
s += `<label><input type='radio' name='ad-image' value='${i}'><img alt="" data-src='${a}'></label>`;
}
}
I(messageGallery, s);
contImages.appendChild(messageGallery);
messageGallery.querySelector("input").checked = true;
};
checkLength("listen-title", 5, 70);
checkLength("listen-description", 20, 4200);
const categ = $$(".parent-click >a, .nav-links> div>a");
for (let i = 0; i < categ.length; i++) {
I(
categ[i],
`<label><input type='radio' name='category' value='${categ[i].id}'>${TX(
categ[i]
)}</label>`
);
}
const ca = $("[value='allowance']");
const ct = $("[name='installment']");
const cr = $("#listen-price");
cr.oninput = () => {
ca.checked = false;
};
ca.onclick = () => {
cr.removeAttribute("required");
cr.value = "";
ct.checked = false;
};
ct.onclick = () => {
cr.removeAttribute("required");
ca.checked = false;
};
const adType = $(".type");
const branchIn = $(".branch");
adType.onmouseleave = () => {
remove(".parent.none", "flex");
};
radInput("radio", "", "statusIn", 1, "status");
radInput("radio", "", "location", 1);
radInput("radio", "", "area", 1);
let categoryValue = "";
const c = $$(".parent-click a input,.nav-links > div > a input");
for (let i = 0; i < c.length; i++) {
c[i].onclick = () => {
categoryValue = c[i].value;
allCategories(categoryValue);
};
}
let subCategoryValue = "";
const categIn = $$(".parent-click .click-show a, .nav-links div div a");
const radios = $$(
".type input, .branch input, .brand input, .statusIn input"
);
const rem = () => {
for (const i of radios) {
i.checked = false;
}
};
const noneIN = () => {
$(".parent.none div").innerHTML +=
"<input type='radio' name='branch' value='' checked><input type='radio' checked name='type' value=''>";
};
const ti = () => {
add(".categ", "v-none");
remove(".sell-form", "v-none");
add(".sell-form", "block");
};
for (let i = 0; i < categIn.length; i++) {
categIn[i].onclick = () => {
rem();
subCategoryValue = categIn[i].id;
allSubCategories(subCategoryValue);
if (branch.length) {
add(".parent.none", "flex");
add(".branch", "block");
remove(".type", "block");
let s = "";
for (const i in branch) {
s += `<a><label><input type='radio' name='branch' value='${replaceChar(
branch[i]
)}'>${trans(branch[i])}</label></a>`;
}
I(branchIn, s);
const selectBranch = branchIn.querySelectorAll("label");
for (const i in branch) {
selectBranch[i].onclick = () => {
rem();
const branch = selectBranch[i].querySelector("input").value;
allBranches(branch);
let s = "";
if (types.length) {
for (const e in types) {
s += `<a><label><input type='radio' name='type' value='${replaceChar(
types[e]
)}'>${trans(types[e])}</label></a>`;
}
I(adType, s);
const selectType = $$(".type label");
for (const e of selectType) {
add(".type", "block");
e.onclick = () => {
ti();
T(
adDir,
`${trans(categoryValue)} / ${trans(
    subCategoryValue
)} / ${trans(branch)} / ${trans(
    e.querySelector("input").value
)} / `
);
};
}
} else {
noneIN();
ti();
T(
adDir,
`${trans(categoryValue)} / ${trans(subCategoryValue)} / ${trans(
branch
)} / `
);
}
};
}
} else {
noneIN();
if (types.length) {
add(".parent.none", "flex");
add(".type", "block");
remove(".branch", "block");
let s = "";
for (const i in types) {
s += `<a><label><input type='radio' name='type' value='${replaceChar(
types[i]
)}'>${trans(types[i])}</label></a>`;
}
I(adType, s);
const selectType = adType.querySelectorAll("input");
for (const i in types) {
selectType[i].onclick = () => {
ti();
T(
adDir,
`${trans(categoryValue)} / ${trans(subCategoryValue)} / ${trans(
selectType[i].value
)} /`
);
};
}
} else {
noneIN();
T(adDir, `${trans(categoryValue)} / ${trans(subCategoryValue)} / `);
ti();
}
}
ifBrand();
};
I(
categIn[i],
`<label><input type='radio' name='subcategory' value='${
categIn[i].id
}'>${TX(categIn[i])}</label>`
);
}
$$(".return").forEach((s) => {
s.onclick = () => {
toggle(".sell-form", "block");
toggle(".categ", "v-none");
types = [];
brands = [];
branch = [];
remove(".parent.none", "flex");
};
});
const clickShowS = $$(".click-show");
for (const i of clickShowS) {
i.onmouseleave = () => {
types = [];
brands = [];
branch = [];
i.classList.remove("block");
};
}
dataList();
}
// //////////////// END SELL.js
// //////////////// START ad.js
const listenSms = $("#listen-sms");
const adPage = currentUrl.search(/\/ad\//gi) !== -1;
if (adPage) {
// // Start ad gallery
const images = $(".listen-images-in");
const imagesText = TX(images).split(" -^- ");
let imagesRes = "";
for (let i = 0; i < imagesText.length; i++) {
if (i !== 0) {
imagesRes += `<img alt="" data-src='../uploads/${imagesText[i]}'>`;
}
}
I(images, imagesRes);
// / //////////////////////////////
const description = $("#description");
const vr = $("#description");
const st = $("#description + .textClick");
vr.classList.add("show-more");
if (TX(description).length >= 252) {
st.onclick = () => {
if (TX(st) !== trans("show more")) {
vr.classList.add("show-more");
T(st, trans("show more"));
} else {
vr.classList.toggle("show-more");
T(st, trans("show less"));
}
};
} else {
st.classList.add("none");
}
$$(".favorite-num span").forEach((s) => {
if (TX(s) <= 1) {
s.remove();
}
});
if (!$(".favorite-num span")) {
$(".favorite-num").remove();
}
const a = TX($("#ad-id"));
const chat = $$(".chatAd");
if (chat) {
chat.forEach((r) => {
r.href += a;
});
}
let as = 0;
const s = TX($("h1.listen-title"));
const fixTit = s.length > 40 ? s.slice(0, 40) + "..." : s;
const showPho = $("#show-PhNu");
if (showPho) {
const phone = $("#listen-call").href.slice(4);
listenSms.href = `sms:+20${phone}?body=${encodeURIComponent(
ar
? 'متاحًا؟ "' + fixTit + '" مرحبًا، هل لا يزال الإعلان '
: `Hello, is the ad "${fixTit}" still available?`
)}`;
showPho.onclick = (r) => {
T(r.target, phone);
if (as === 0) {
fetch(`/components/head.php?ad-id=${a}&show-number=on`);
}
as = 1;
};
}
}
if (adPage || pathname === "/") {
const s = $$(".listen-images-in img");
const galleryImages = Array.from(s);
const adSmallImages = $("#listen-small-image");
const imageNumbers = $("#listen-image-numbers");
const nextButton = $("#nextButton");
const prevButton = $("#prevButton");
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
let currentImg = 0;
if (adPage) {
let i = 0;
for (; i < galleryImages.length; ) {
adSmallImages.append(galleryImages[i].cloneNode());
i++;
}
}
const smallImages = Array.from($$("#listen-small-image img"));
// if (smallImages[0]) {
const checker = () => {
I(imageNumbers, `${currentImg + 1} / ${galleryImages.length}`);
for (let i = 0; i < galleryImages.length; i++) {
galleryImages[i].parentElement.classList.remove("active");
galleryImages[i].classList.remove("active");
if (adPage) {
smallImages[i].classList.remove("active");
}
const indexSmallImg = () => {
clearInterval(autoSlide);
currentImg = smallImages.indexOf(smallImages[i]);
checker();
};
if (adPage) {
smallImages[i].onclick = () => {
indexSmallImg();
};
}
}
if (adPage) {
smallImages[currentImg].classList.add("active");
}
galleryImages[currentImg].classList.add("active");
galleryImages[currentImg].parentElement.classList.add("active");
};
const next = () => {
if (currentImg === galleryImages.length - 1) {
currentImg = 0;
checker();
} else {
currentImg++;
checker();
}
};
const prev = () => {
if (currentImg === 0) {
currentImg = galleryImages.length - 1;
checker();
} else {
currentImg--;
checker();
}
};
const autoSlide = setInterval(next, 2500);
nextButton.onclick = () => {
next();
clearInterval(autoSlide);
};
prevButton.onclick = () => {
prev();
clearInterval(autoSlide);
};
checker();
if (s.length === 1) {
nextButton.style.display = "none";
prevButton.style.display = "none";
adSmallImages.style.display = "none";
}
// }
}
// //////////////// END ad.js
if (currentUrl.search(/\/user\//gi) !== -1 || adPage) {
const shareFB = $("#shareFB");
const shareTW = $("#shareTW");
const shareWA = $("#shareWA");
const shareMS = $("#shareMS");
shareTW.setAttribute(
"href",
`https://twitter.com/intent/tweet?url=${doc.URL}&via=${location.hostname}`
);
let shareFBMob = "";
if (isMobile()) {
// shareFBMob = 'https://m.facebook.com/sharer.php?u='
// shareFBMob = 'fb-share-link://share?link='
// shareFBMob = 'fb://faceweb/f?href='
shareFBMob = "fb://share?link=";
} else {
shareFBMob = "https://www.facebook.com/share_channel/?link=";
}
shareFB.setAttribute("href", shareFBMob + doc.URL);
let shareMSMob = "";
if (isMobile()) {
shareMSMob = "fb-messenger://share/?link=";
} else {
shareMSMob = "https://www.facebook.com/dialog/share?link=";
}
shareMS.setAttribute("href", shareMSMob + doc.URL);
let shareWAMob = "";
if (isMobile()) {
shareWAMob = "whatsapp://send?text=";
} else {
shareWAMob = "https://api.whatsapp.com/send/?text=";
}
shareWA.setAttribute("href", shareWAMob + doc.URL);
}
if (currentUrl.search(/\/user\//gi) !== -1) {
const phone = $(".listen-call").id;
$("#show-PhNu").onclick = () => {
T($("#show-PhNu-sh"), ` ${phone}`);
};
listenSms.href = `sms:+20${phone}?body=${encodeURIComponent(
`${ar ? "مرحباً" : "Hello"}, ${TX($("main .listen-seller b"))}`
)}`;
}
if (currentUrl.search(/\/mysettings\//gi) !== -1) {
valNewPass("editPass", "editPassTwo");
}
home();
const favorites = $$(".card-fav, .card-fav-fill");
for (const i of favorites) {
i.onclick = (r) => {
if (checkLog) {
toggle(".log", "flex");
r.preventDefault();
} else {
const s = r.target.baseURI.includes("/mysearches/");
fetch(`/components/head.php?${i.name}=${i.value}`);
if (i.classList.contains("card-fav")) {
if (s) {
i.name = "remove-search";
} else {
i.name = "remove";
}
i.classList.remove("card-fav");
i.classList.add("card-fav-fill");
} else {
if (s) {
i.name = "search";
} else {
i.name = "id";
}
i.classList.remove("card-fav-fill");
i.classList.add("card-fav");
}
}
};
}
if (
checkLog &&
currentUrl.search(
/(\/sell\/|\/mysettings\/|\/mysearches\/|\/myfavorites\/|\/myads\/|\/chat\/)/
) > 0
) {
toggle("form.sell, #settings .sell-form", "hidden");
toggle(".log", "flex");
}
if ($(".log")) {
const foot = ar
? '<p>من خلال تسجيل الدخول، فإنك توافق على <a href="/usecondetions/">شروط الاستخدام</a> و <a href="/privacy/">سياسة الخصوصية</a> الخاصة بأمازون.</p>'
: '<p>by logging in, you agree to exxeer\'s <a href="/usecondetions/">terms of use</a> and <a href="/privacy/">privacy policy</a>.</p>';
const signInF = (form) => {
const head = ar
? `<span onclick="toggle('${form}','flex')"><img src="/icons/x.svg" alt="${trans(
"Close"
)}"></span><img alt="${trans(
"Exxeer"
)}" data-src="/images/android-chrome-192x192.png" class="invert" width="100" height="100"><p>مرحبًا بك في أمازون</p>`
: `<span onclick="toggle('${form}','flex')"><img src="/icons/x.svg" alt="${trans(
"Close"
)}"></span><img alt="${trans(
"Exxeer"
)}" data-src="/images/android-chrome-192x192.png" class="invert" width="100" height="100"><p>hello, welcome to exxeer</p>`;
I($(form), `${head + $(form).innerHTML + foot}`);
};
signInF(".log");
signInF(".create-acc");
valNewPass("new-password", "retype-password");
}