Hanaz Writers

Free AI Book Cover Creator

Maximum 300 characters are accepted for the back cover summary.
0 / 300 characters
Romantic Drama Comedy Educational Historical
(function(){ /* ========================================= PREVENT DUPLICATE LOADING ========================================= */ if(window.freeCoverLoaded) return; window.freeCoverLoaded = true; /* ========================================= API ========================================= */ const API = "https://ai.hanazwriters.org/free/cover-creator"; /* ========================================= STORAGE KEY ========================================= */ const STORAGE_KEY = "hanaz_cover_creator_used"; /* ========================================= GET ELEMENTS ========================================= */ const titleInput = document.getElementById("titleInput"); const authorInput = document.getElementById("authorInput"); const synopsisInput = document.getElementById("synopsisInput"); const genreInput = document.getElementById("genreInput"); const generateBtn = document.getElementById("generateBtn"); const loadingMessage = document.getElementById("loadingMessage"); const resultBox = document.getElementById("resultBox"); const synopsisInfo = document.getElementById("synopsisInfo"); const characterCount = document.getElementById("characterCount"); /* ========================================= BROWSER FINGERPRINT ========================================= */ function getFingerprint(){ return btoa( navigator.userAgent + screen.width + screen.height + navigator.language + Intl.DateTimeFormat() .resolvedOptions() .timeZone ); } const browserFingerprint = getFingerprint(); /* ========================================= CHECK LOCAL STORAGE ========================================= */ let usedOnce = localStorage.getItem(STORAGE_KEY) === "used"; /* ========================================= PREMIUM MESSAGE ========================================= */ function showPremiumBox(){ resultBox.innerHTML = `

Unlock Premium Version

The free version allows only one cover generation.

Go Premium
`; generateBtn.disabled = true; generateBtn.style.opacity = "0.5"; generateBtn.style.cursor = "not-allowed"; } /* ========================================= CHECK SYNOPSIS LENGTH ========================================= */ function checkSynopsisLength(){ const length = synopsisInput.value.length; /* ========================================= UPDATE COUNTER ========================================= */ characterCount.innerText = length + " / 300 characters"; /* ========================================= TOO LONG ========================================= */ if(length > 300){ characterCount.style.color = "red"; synopsisInfo.innerText = "Your back cover summary is too long. Maximum 300 characters are allowed."; synopsisInfo.style.color = "red"; generateBtn.disabled = true; generateBtn.style.opacity = "0.5"; generateBtn.style.cursor = "not-allowed"; return false; } /* ========================================= VALID LENGTH ========================================= */ characterCount.style.color = "#777"; synopsisInfo.innerText = "Maximum 300 characters are accepted for the back cover summary."; synopsisInfo.style.color = "#555"; generateBtn.disabled = false; generateBtn.style.opacity = "1"; generateBtn.style.cursor = "pointer"; return true; } /* ========================================= CHECK WHILE TYPING / PASTING ========================================= */ synopsisInput.addEventListener( "input", function(){ checkSynopsisLength(); } ); /* ========================================= SHOW PREMIUM MESSAGE IF ALREADY USED ========================================= */ if(usedOnce){ showPremiumBox(); } /* ========================================= GENERATE BUTTON ========================================= */ generateBtn.addEventListener( "click", generateCover ); /* ========================================= GENERATE COVER ========================================= */ async function generateCover(){ /* ========================================= BLOCK SECOND USE ========================================= */ if(usedOnce){ showPremiumBox(); return; } /* ========================================= GET VALUES ========================================= */ const title = titleInput.value.trim(); const author = authorInput.value.trim(); const synopsis = synopsisInput.value.trim(); const genre = genreInput.value; /* ========================================= IMPORTANT: NEVER GENERATE ABOVE 300 CHARACTERS ========================================= */ if(synopsis.length > 300){ resultBox.innerHTML = `

Your back cover summary is too long.

You entered ${synopsis.length} characters. The maximum allowed is 300 characters. Please shorten your summary before generating the cover.

`; checkSynopsisLength(); return; } /* ========================================= TITLE VALIDATION ========================================= */ if(!title){ resultBox.innerHTML = "

Please enter your book title.

"; return; } /* ========================================= AUTHOR VALIDATION ========================================= */ if(!author){ resultBox.innerHTML = "

Please enter the author name.

"; return; } /* ========================================= SYNOPSIS VALIDATION ========================================= */ if(!synopsis){ resultBox.innerHTML = "

Please enter your back cover summary.

"; return; } /* ========================================= FINAL LENGTH CHECK ========================================= */ if(!checkSynopsisLength()){ return; } /* ========================================= SHOW LOADING ========================================= */ resultBox.innerHTML = ""; loadingMessage.style.display = "block"; generateBtn.disabled = true; generateBtn.style.opacity = "0.5"; /* ========================================= API REQUEST ========================================= */ try{ const res = await fetch(API,{ method:"POST", headers:{ "Content-Type":"application/json" }, body:JSON.stringify({ title:title, author:author, synopsis:synopsis, genre:genre, fingerprint:browserFingerprint }) }); /* ========================================= FREE LIMIT REACHED ========================================= */ if(res.status === 403){ usedOnce = true; localStorage.setItem( STORAGE_KEY, "used" ); showPremiumBox(); return; } /* ========================================= READ RESPONSE ========================================= */ const data = await res.json(); /* ========================================= SERVER ERROR ========================================= */ if(!res.ok){ throw new Error( data.error || "Something went wrong. Please try again." ); } /* ========================================= CHECK IMAGE DATA ========================================= */ if(!data.frontCover){ throw new Error( "Front cover was not generated." ); } if(!data.backCover){ throw new Error( "Back cover was not generated." ); } /* ========================================= DISPLAY COVERS ========================================= */ resultBox.innerHTML = ` `; /* ========================================= SUCCESSFUL USE ========================================= */ usedOnce = true; localStorage.setItem( STORAGE_KEY, "used" ); }catch(err){ console.error(err); resultBox.innerHTML = `

${err.message}

`; } /* ========================================= FINISH ========================================= */ loadingMessage.style.display = "none"; generateBtn.disabled = false; generateBtn.style.opacity = "1"; generateBtn.style.cursor = "pointer"; /* ========================================= RECHECK LENGTH ========================================= */ checkSynopsisLength(); } })();