Close
Currency
Language
Close
Menu
Search
Account
Cart
Close

Search results for: 'freez'

Sidebar
Here's a comprehensive JavaScript script that can automatically generate Schema.org JSON-LD from any web page: /** * Universal Schema.org JSON-LD Generator * Automatically extracts structured data from any webpage */class SchemaGenerator { constructor() { this.schema = { "@context": "https://schema.org", "@graph": [] }; this.detectedTypes = new Set(); } /** * Main function to generate schema */ generateSchema() { // Detect page type and generate appropriate schemas this.detectWebSite(); this.detectWebPage(); this.detectOrganization(); this.detectLocalBusiness(); this.detectArticle(); this.detectProduct(); this.detectBreadcrumbs(); this.detectFAQ(); this.detectAddress(); this.detectEvents(); this.detectVideos(); this.detectImages(); return this.schema; } /** * Utility function to clean text */ cleanText(text) { return text ? text.trim().replace(/\s+/g, ' ').replace(/[\n\r]/g, ' ') : ''; } /** * Extract meta tag content */ getMeta(name) { const meta = document.querySelector(`meta[name="${name}"], meta[property="${name}"]`); return meta ? this.cleanText(meta.content) : null; } /** * Detect WebSite schema */ detectWebSite() { const siteName = this.getMeta('og:site_name') || this.getMeta('application-name') || document.querySelector('title')?.textContent.split('|')[0].trim(); if (siteName) { const website = { "@type": "WebSite", "@id": `${window.location.origin}/#website`, "name": siteName, "url": window.location.origin }; // Add search action if search form exists const searchForm = document.querySelector('form[role="search"], form[action*="search"], input[type="search"]'); if (searchForm) { website.potentialAction = { "@type": "SearchAction", "target": { "@type": "EntryPoint", "urlTemplate": `${window.location.origin}/search?q={search_term_string}` }, "query-input": "required name=search_term_string" }; } this.schema["@graph"].push(website); } } /** * Detect WebPage schema */ detectWebPage() { const webpage = { "@type": "WebPage", "@id": window.location.href, "url": window.location.href, "name": document.title || this.getMeta('og:title'), "description": this.getMeta('description') || this.getMeta('og:description') }; // Add dates const datePublished = this.getMeta('article:published_time') || this.getMeta('datePublished'); const dateModified = this.getMeta('article:modified_time') || this.getMeta('dateModified'); if (datePublished) webpage.datePublished = datePublished; if (dateModified) webpage.dateModified = dateModified; // Add author const author = this.getMeta('author') || this.getMeta('article:author'); if (author) { webpage.author = { "@type": "Person", "name": author }; } // Add image const image = this.getMeta('og:image'); if (image) webpage.image = image; this.schema["@graph"].push(webpage); } /** * Detect Organization/LocalBusiness */ detectOrganization() { const indicators = { hotel: ['hotel', 'accommodation', 'resort', 'rooms', 'suites', 'check-in', 'check-out'], restaurant: ['restaurant', 'menu', 'cuisine', 'dining', 'food', 'chef', 'reservation'], store: ['shop', 'store', 'buy', 'purchase', 'cart', 'products', 'e-commerce'], service: ['service', 'consultation', 'appointment', 'booking', 'professional'] }; const bodyText = document.body.innerText.toLowerCase(); const title = document.title.toLowerCase(); const description = (this.getMeta('description') || '').toLowerCase(); const combinedText = `${title} ${description} ${bodyText}`; let detectedType = 'Organization'; let maxScore = 0; // Detect business type based on keywords for (const [type, keywords] of Object.entries(indicators)) { const score = keywords.filter(keyword => combinedText.includes(keyword)).length; if (score > maxScore) { maxScore = score; detectedType = this.getSchemaType(type); } } // Extract organization data const org = { "@type": detectedType, "@id": `${window.location.origin}/#organization`, "name": this.getMeta('og:site_name') || document.querySelector('h1')?.textContent || document.title.split('|')[0].trim(), "url": window.location.origin }; // Add logo const logo = document.querySelector('img[alt*="logo" i], img[src*="logo" i], .logo img, header img'); if (logo) { org.logo = { "@type": "ImageObject", "url": new URL(logo.src, window.location.origin).href }; } // Add contact information this.addContactInfo(org); // Hotel-specific properties if (detectedType === 'Hotel') { this.addHotelProperties(org); } this.schema["@graph"].push(org); this.detectedTypes.add(detectedType); } /** * Get appropriate schema type */ getSchemaType(type) { const typeMap = { 'hotel': 'Hotel', 'restaurant': 'Restaurant', 'store': 'Store', 'service': 'ProfessionalService' }; return typeMap[type] || 'LocalBusiness'; } /** * Add hotel-specific properties */ addHotelProperties(hotel) { // Extract number of rooms const roomsMatch = document.body.innerText.match(/(\d+)\s*(?:rooms?|suites?)/i); if (roomsMatch) { hotel.numberOfRooms = roomsMatch[1]; } // Extract star rating const starMatch = document.body.innerText.match(/(\d+)\s*star/i); if (starMatch) { hotel.starRating = { "@type": "Rating", "ratingValue": starMatch[1], "bestRating": "5" }; } // Extract amenities const amenities = this.extractAmenities(); if (amenities.length > 0) { hotel.amenityFeature = amenities; } } /** * Extract amenities */ extractAmenities() { const amenityKeywords = ['wifi', 'parking', 'pool', 'gym', 'restaurant', 'bar', 'spa', 'meeting room', 'conference']; const amenities = []; const bodyText = document.body.innerText.toLowerCase(); amenityKeywords.forEach(keyword => { if (bodyText.includes(keyword)) { amenities.push({ "@type": "LocationFeatureSpecification", "name": keyword.charAt(0).toUpperCase() + keyword.slice(1), "value": true }); } }); return amenities; } /** * Add contact information */ addContactInfo(org) { // Phone const phoneRegex = /(\+?[\d\s\-\(\)]+)/g; const phoneLink = document.querySelector('a[href^="tel:"]'); if (phoneLink) { org.telephone = phoneLink.href.replace('tel:', ''); } else { const phoneMatch = document.body.innerText.match(phoneRegex); if (phoneMatch && phoneMatch[0].length > 7) { org.telephone = this.cleanText(phoneMatch[0]); } } // Email const emailLink = document.querySelector('a[href^="mailto:"]'); if (emailLink) { org.email = emailLink.href.replace('mailto:', ''); } // Social Media const socialLinks = []; const socialSelectors = { 'facebook.com': 'Facebook', 'twitter.com': 'Twitter', 'instagram.com': 'Instagram', 'linkedin.com': 'LinkedIn', 'youtube.com': 'YouTube' }; Object.entries(socialSelectors).forEach(([domain, name]) => { const link = document.querySelector(`a[href*="${domain}"]`); if (link) socialLinks.push(link.href); }); if (socialLinks.length > 0) { org.sameAs = socialLinks; } } /** * Detect Address/Location */ detectAddress() { const addressPatterns = [ /\d+\s+[\w\s]+(?:street|st|road|rd|avenue|ave|boulevard|blvd|lane|ln|drive|dr)/i, /(?:Jalan|Jln)\s+[\w\s]+/i, // Malaysian addresses /\d{5}(?:-\d{4})?/ // Postal codes ]; let address = null; // Check structured data const addressElement = document.querySelector('[itemtype*="PostalAddress"], .address, [class*="address"]'); if (addressElement) { address = { "@type": "PostalAddress", "addressLocality": addressElement.querySelector('[itemprop="addressLocality"]')?.textContent || this.extractLocation(), "addressRegion": addressElement.querySelector('[itemprop="addressRegion"]')?.textContent, "addressCountry": addressElement.querySelector('[itemprop="addressCountry"]')?.textContent || "MY" }; } // Try to extract from text if (!address) { const bodyText = document.body.innerText; addressPatterns.forEach(pattern => { const match = bodyText.match(pattern); if (match && !address) { address = { "@type": "PostalAddress", "streetAddress": match[0] }; } }); } // Add geo coordinates if available const geoMeta = { lat: this.getMeta('geo.position')?.split(';')[0] || this.getMeta('ICBM')?.split(',')[0], lng: this.getMeta('geo.position')?.split(';')[1] || this.getMeta('ICBM')?.split(',')[1] }; if (geoMeta.lat && geoMeta.lng) { const geo = { "@type": "GeoCoordinates", "latitude": geoMeta.lat.trim(), "longitude": geoMeta.lng.trim() }; if (this.detectedTypes.has('Hotel') || this.detectedTypes.has('LocalBusiness')) { const org = this.schema["@graph"].find(item => item["@type"] === "Hotel" || item["@type"] === "LocalBusiness" ); if (org) org.geo = geo; } } return address; } /** * Extract location from text */ extractLocation() { const locations = ['Johor Bahru', 'Kuala Lumpur', 'Penang', 'Singapore']; const bodyText = document.body.innerText; for (const location of locations) { if (bodyText.includes(location)) return location; } return null; } /** * Detect Breadcrumbs */ detectBreadcrumbs() { const breadcrumbSelectors = [ 'nav[aria-label*="breadcrumb"]', '.breadcrumb', '[itemtype*="BreadcrumbList"]', 'ol[class*="breadcrumb"]' ]; for (const selector of breadcrumbSelectors) { const breadcrumbNav = document.querySelector(selector); if (breadcrumbNav) { const items = breadcrumbNav.querySelectorAll('li, a'); if (items.length > 0) { const breadcrumbList = { "@type": "BreadcrumbList", "itemListElement": [] }; items.forEach((item, index) => { const text = item.textContent.trim(); const link = item.querySelector('a') || item; if (text && text !== '>' && text !== '/') { breadcrumbList.itemListElement.push({ "@type": "ListItem", "position": index + 1, "name": text, "item": link.href || window.location.href }); } }); if (breadcrumbList.itemListElement.length > 0) { this.schema["@graph"].push(breadcrumbList); } } break; } } } /** * Detect FAQ */ detectFAQ() { const faqSelectors = [ '[itemtype*="FAQPage"]', '.faq', '#faq', '[class*="faq"]', 'dl' ]; for (const selector of faqSelectors) { const faqSection = document.querySelector(selector); if (faqSection) { const questions = faqSection.querySelectorAll('dt, .question, h3, h4'); const answers = faqSection.querySelectorAll('dd, .answer, p'); if (questions.length > 0 && questions.length === answers.length) { const faqPage = { "@type": "FAQPage", "mainEntity": [] }; questions.forEach((q, index) => { if (index < answers.length) { faqPage.mainEntity.push({ "@type": "Question", "name": this.cleanText(q.textContent), "acceptedAnswer": { "@type": "Answer", "text": this.cleanText(answers[index].textContent) } }); } }); if (faqPage.mainEntity.length > 0) { this.schema["@graph"].push(faqPage); } } break; } } } /** * Detect Article */ detectArticle() { const article = document.querySelector('article, [itemtype*="Article"], .post, .blog-post'); if (article) { const articleSchema = { "@type": "Article", "headline": document.querySelector('h1')?.textContent || document.title, "description": this.getMeta('description') }; // Add dates const publishDate = this.getMeta('article:published_time') || article.querySelector('time[datetime]')?.getAttribute('datetime'); if (publishDate) articleSchema.datePublished = publishDate; // Add author const author = this.getMeta('article:author') || article.querySelector('.author, .by-line, [rel="author"]')?.textContent; if