Hello,
I want to make a addon on short url working in xenforo. Please, help for this. I am using JS. I am writing a code for this.
<script>
// Function to generate a random alphanumeric string
function generateRandomString(length) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
}
// Function to create a short URL
function createShortUrl() {
const longUrl = document.getElementById("longUrl").value;
// Replace this with your own domain
const domain = "https://mozodeals.com/";
// Generate a random 6-character string
const randomString = generateRandomString(5);
// Concatenate the domain with the random string
const shortUrl = domain + randomString;
// Display the short URL as a clickable link
const shortUrlElement = document.getElementById("shortUrl");
shortUrlElement.innerHTML = "Short URL: <a href='#' onclick='openUrl(\"" + longUrl + "\")'>" + shortUrl + "</a>";
// Store the mapping between short URL and long URL in a database or data structure
// For demonstration purposes, let's just log it
console.log("Mapping:", shortUrl, "->", longUrl);
}
// Function to open the full URL in a new tab
function openUrl(url) {
window.open(url, '_blank');
}
</script>
Result is https://mozodeals.com/SQa65 something like that
I want to make a addon on short url working in xenforo. Please, help for this. I am using JS. I am writing a code for this.
<script>
// Function to generate a random alphanumeric string
function generateRandomString(length) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
}
// Function to create a short URL
function createShortUrl() {
const longUrl = document.getElementById("longUrl").value;
// Replace this with your own domain
const domain = "https://mozodeals.com/";
// Generate a random 6-character string
const randomString = generateRandomString(5);
// Concatenate the domain with the random string
const shortUrl = domain + randomString;
// Display the short URL as a clickable link
const shortUrlElement = document.getElementById("shortUrl");
shortUrlElement.innerHTML = "Short URL: <a href='#' onclick='openUrl(\"" + longUrl + "\")'>" + shortUrl + "</a>";
// Store the mapping between short URL and long URL in a database or data structure
// For demonstration purposes, let's just log it
console.log("Mapping:", shortUrl, "->", longUrl);
}
// Function to open the full URL in a new tab
function openUrl(url) {
window.open(url, '_blank');
}
</script>
Result is https://mozodeals.com/SQa65 something like that