1let responseBRMStruct = { 2 0: '', 3 1: 'Email nije valjan.', 4 2: 'VaÅ¡e korisniÄko ime i/ili lozinka su netoÄni.', 5 3: 'Lozinka mora sadržavati 8 znakova.', 6 4: 'Lozinka mora sadržavati barem jedan broj.', 7 5: 'Lozinka mora sadržavati barem jedno veliko slovo.', 8 6: 'Lozinka mora sadržavati barem jedno malo slovo.', 9 7: 'Lozinka mora sadržavati barem jedan poseban znak.', 10 8: 'Lozinke se ne podudaraju.', 11 9: 'Korisnik nije aktivan, kliknite <b onclick="sendNewActivationCode()">ovdje</b> kako biste ponovno poslali aktivacijski mail.', 12 10: 'E-mail adresa ili nadimak je veÄ zauzet', 13 11: 'Kriva lozinka', 14 12: 'Morate prihvatit uvjete koriÅ¡tenja i pravila privatnosti', 15 13: 'VaÅ¡e korisniÄko ime ne smije biti prazno', 16 99: 'DoÅ¡lo je do pogreÅ¡ke...', 17 forgotPass: 'Na vaÅ¡u email adresu poslana je poveznica za promjenu lozinke', 18 userNoExist: 'Korisnik ne postoji', 19 resetPass: 'Lozinka je uspjeÅ¡no promijenjena.' 20} 21var comments = null; 22function generateBRM(brmCode, target = null, offset = 0, removeCond = true) { 23 if (removeCond) { 24 removeBRM() 25 } 26 var container = target === null ? document.getElementById('se-sso') : target 27 let badResponseMessage = document.createElement('div') 28 badResponseMessage.classList.add('se-sso-brm') 29 badResponseMessage.innerHTML = responseBRMStruct[brmCode] 30 container.insertBefore(badResponseMessage, container.children[container.children.length - 1 - offset]) 31} 32 33function userLogin() { 34 35 submitForm('sso_form_login') 36 .then(result => { 37 if (result.success) { 38 console.log('Form submitted successfully:', result.data); 39 if (result.data.status == 200) { 40 sessionStorage.setItem('loginSuccess', 1); 41 showPopup('Prijava uspjeÅ¡na!'); 42 var now = new Date(); 43 var time = now.getTime(); 44 var expireTime = time + 3600000 * 24 * 30; 45 now.setTime(expireTime); 46 document.cookie = "SE_SSO_token=" + result.data.token + ";expires=" + now.toUTCString() + ";domain=net.hr;path=/"; 47 document.cookie = "SE_SSO_username=" + result.data.userData.username + ";expires=" + now.toUTCString() + ";domain=net.hr;path=/"; 48 setTimeout(() => { 49 //location.reload(); 50 }, 2000); 51 document.getElementById('se_header_default').checked = true; 52 } else if (result.data.status == 400) { 53 54 generateBRM(2, document.getElementById('sso_form_login'), 4) 55 } else if (result.data.status == 401) { 56 generateBRM(9, document.getElementById('sso_form_login'), 4) 57 } 58 } else { 59 console.error('Form submission failed:', result.error); 60 } 61 }); 62} 63 64function deleteUser() { 65 66 submitForm('user_delete_form') 67 .then(result => { 68 if (result.success) { 69 console.log('Form submitted successfully:', result.data); 70 if (result.data.status == 200) { 71 72 var now = new Date(); 73 document.cookie = "SE_SSO_token=;expires=" + now.toUTCString() + ";domain=net.hr;path=/"; 74 document.cookie = "SE_SSO_username=;expires=" + now.toUTCString() + ";domain=net.hr;path=/"; 75 window.location.replace('/'); 76 } else if (result.data.status == 400) { 77 generateBRM(2) 78 } 79 } else { 80 console.error('Form submission failed:', result.error); 81 } 82 }); 83} 84 85function userRegister() { 86 removeBRM() 87 const emailInput = document.getElementById('sso_register_email') 88 const usernameInput = document.getElementById('sso_register_username') 89 const passwordInput = document.getElementById('sso_register_password') 90 const passwordReInput = document.getElementById('sso_register_password_repeat') 91 const termsCheckbox = document.getElementById('sso_register_terms') 92 93 const validators = { 94 email: email => /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email), 95 username: username => username.length > 0, 96 length: (password) => password.length >= 8, 97 number: (password) => /\d/.test(password), 98 capital: (password) => /[A-Z]/.test(password), 99 lowercase: (password) => /[a-z]/.test(password), 100 special: (password) => /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~`]/.test(password), 101 match: (password, passwordRe) => passwordRe === password, 102 terms: () => termsCheckbox.checked 103 }; 104 105 // Function to check if all validators pass 106 function allValidatorsPassed() { 107 const email = emailInput.value; 108 const username = usernameInput.value; 109 const password = passwordInput.value; 110 const passwordRe = passwordReInput.value; 111
112 return Object.keys(validators).every(requirement => { 113 switch (requirement) { 114 case 'email': 115 return validators.email(email); 116 case 'username': 117 return validators.username(username); 118 case 'length': 119 case 'number': 120 case 'capital': 121 case 'lowercase': 122 case 'special': 123 return validators[requirement](password); 124 case 'match': 125 return validators[requirement](password, passwordRe); 126 case 'terms': 127 return validators.terms(); 128 default: 129 return false; 130 } 131 }); 132 } 133 function getFailedValidators() { 134 const email = emailInput.value; 135 const username = usernameInput.value; 136 const password = passwordInput.value; 137 const passwordRe = passwordReInput.value; 138 const failedValidators = []; 139 140 Object.keys(validators).forEach(requirement => { 141 let isValid = false; 142 143 switch (requirement) { 144 case 'email': 145 isValid = validators.email(email); 146 break; 147 case 'username': 148 isValid = validators.username(username); 149 break; 150 case 'length': 151 case 'number': 152 case 'capital': 153 case 'lowercase': 154 case 'special': 155 isValid = validators[requirement](password); 156 break; 157 case 'match': 158 isValid = validators[requirement](password, passwordRe) 159 break; 160 case 'terms': 161 isValid = validators.terms(); 162 break; 163 default: 164 isValid = false; 165 } 166 167 if (!isValid) { 168 failedValidators.push(requirement); 169 } 170 }); 171 172 return failedValidators; 173 } 174 175 if (allValidatorsPassed()) { 176 177 submitForm('sso_form_register') 178 .then(result => { 179 if (result.success) { 180 console.log('Form submitted successfully:', result.data); 181 if (result.data.status == 200) { 182 // console.log(response) 183 document.getElementById('se-sso').innerHTML = 184 ` 185 <div class="se-sso-container se-sso-container--activation"> 186 <div class="se-sso-title se-sso-title--activation">Aktivacijski email</div> 187 <div class="se-sso-container se-sso-container--button"> 188 <label for="se_header_default" class="se-sso-label se-sso-label--close"> 189 <svg focusable="false" viewBox="0 0 32 32" aria-hidden="true"><path d="M 28.035255,32.000001 0,3.9647831 3.9647831,0 32.000001,28.035255 Z"></path><path d="M 3.9647831,32.000001 32.000001,3.9647831 28.035255,0 3.5648696e-6,28.035255 Z"></path></svg> 190 </label> 191 </div> 192 <div class="se-sso-div"> 193 <span>Na tvoju email adresu je poslan aktivacijski email.</span> 194 </div> 195 <div class="se-sso-container se-sso-container--button-activation"> 196 <label for="se_header_default" class="se-sso-label se-sso-label--close"> 197 U redu 198 </label> 199 </div> 200 </div> 201 `; 202 } else { 203 // document.getElementById('registration_response_info').innerHTML = response.message; 204 if (result.data.status == 400) { 205 generateBRM(result.data.error_code) 206 207 } 208 } 209 } else { 210 console.error('Form submission failed:', result.error); 211 } 212 }); 213 } else { 214 let failedValidators = getFailedValidators() 215 let brmCodes = failedValidators.map(validator => { 216 const map = { email: 1, length: 3, number: 4, capital: 5, lowercase: 6, special: 7, match: 8, terms: 12, username: 13, }; 217 return map[validator]; 218 }); 219 brmCodes.forEach(code => { 220 let offset = 0 221 switch (code) { 222 case 1: 223 offset = 7; 224 break; 225 case 3: 226 offset = 4; 227 break; 228 case 4: 229 offset = 4; 230 break; 231 case 5: 232 offset = 4; 233 break; 234 case 6: 235 offset = 4; 236 break; 237 case 7: 238 offset = 4; 239 break; 240 case 8: 241 offset = 3; 242 break; 243 case 12: 244 offset = 1; 245 break; 246 case 13: 247 offset = 5; 248 break; 249 } 250 generateBRM(code, document.getElementById('sso_form_register'), offset, false) 251 }) 252 } 253 254} 255 256 257/* function getPackagePrice(packageID) { 258 259 var xhrobj = new XMLHttpRequest(); 260 261 data = { 262 "action": "getPackagePrice", 263 "packageID": packageID 264 }, 265 266 xhrobj.onreadystatechange = function () { 267 if (this.readyState == 4 && this.status === 200) { 268 var response = JSON.parse(xhrobj.responseText); 269 if (response.status == 200) { 270 271 if (response.product.discounted_price != 0) { 272 document.getElementById('amount').value = response.product.discounted_price; 273 } else { 274 document.getElementById('amount').value = response.product.price; 275 } 276 } 277 return false; 278 } 279 } 280 281 xhrobj.open('POST', 'https://rtlsso.storyeditor.eu/include/public_actions.php'); 282 xhrobj.setRequestHeader("Content-Type", "text/plain"); 283 xhrobj.send(JSON.stringify(data)); 284} */ 285 286/* function getArticleData(url) { 287 var token = getCookie('SE_SSO_token'); 288 289 var xhrobj = new XMLHttpRequest(); 290 291 data = { 292 "action": "getArticleData", 293 "token": token, 294 "url": url 295 }, 296 297 xhrobj.onreadystatechange = function () { 298 if (this.readyState == 4 && this.status === 200) { 299 var response = JSON.parse(xhrobj.responseText); 300 if (response.status == 200) { 301 var web_text = response.web_text.replace('{---------- PAGE STOPPER ----------}', ''); 302 303 document.getElementsByClassName('se-article__content')[0].innerHTML = web_text; 304 } 305 return false; 306 } 307 } 308 309 xhrobj.open('POST', 'https://rtlsso.storyeditor.eu/include/public_actions.php'); 310 xhrobj.setRequestHeader("Content-Type", "text/plain"); 311 xhrobj.send(JSON.stringify(data)); 312 313} */ 314 315function getCookie(name) { 316 const cookieString = document.cookie; 317 const cookies = cookieString.split('; '); 318 319 for (let cookie of cookies) { 320 const [cookieName, cookieValue] = cookie.split('='); 321 if (cookieName === name) { 322 return cookieValue; 323 } 324 } 325 return undefined; // Return undefined if the cookie is not found 326} 327 328function activateUser() { 329 submitForm('activationForm') 330 .then(result => { 331 if (result.success) { 332 console.log('Form submitted successfully:', result.data); 333 if (result.data.status == 200) { 334 var now = new Date(); 335 var time = now.getTime(); 336 var expireTime = time + 3600000 * 24 * 30; 337 now.setTime(expireTime); 338 339 document.cookie = "SE_SSO_token=" + result.data.token + ";expires=" + now.toUTCString() + ";domain=net.hr;path=/"; 340 document.cookie = "SE_SSO_username=" + result.data.userData.username + ";expires=" + now.toUTCString() + ";domain=net.hr;path=/"; 341 342 // Show popup 343 showActivationPopup(); 344 345 // Wait 2.5 seconds, then redirect 346 setTimeout(() => { 347 window.location.href = '/'; 348 }, 2000); 349 350 } else { 351 showPopup('Došlo je do pogreške!'); 352 /* document.getElementById('naslov').innerHTML = 'Doslo je do pogreske.' 353 document.getElementById('tekst').innerHTML = response.message */ 354 } 355 } else { 356 console.error('Form submission failed:', result.error); 357 } 358 });
359} 360 361function resetPassword() { 362 363 submitForm('sso_reset_password') 364 .then(result => { 365 if (result.success) { 366 console.log('Form submitted successfully:', result.data); 367 if (result.data.status == 200) { 368 generateBRM('resetPass', document.getElementById('sso-reset')); 369 setTimeout(() => { 370 window.location.replace('/') 371 }, 3000) 372 } else { 373 generateBRM(result.data.error_code, document.getElementById('sso-reset')); 374 } 375 } else { 376 console.error('Form submission failed:', result.error); 377 } 378 }); 379} 380 381function resetPasswordFromOld() { 382 383 submitForm('reset_password_form') 384 .then(result => { 385 if (result.success) { 386 console.log('Form submitted successfully:', result.data); 387 if (result.data.status == 200) { 388 generateBRM('resetPass', document.getElementById('reset_password_response')); 389 } else { 390 generateBRM(result.data.error_code, document.getElementById('reset_password_response')); 391 } 392 } else { 393 generateBRM(result.data.error_code, document.getElementById('reset_password_response')); 394 } 395 }); 396} 397 398function forgotPassword() { 399 400 submitForm('sso_form_forgot_password') 401 .then(result => { 402 if (result.success) { 403 console.log('Form submitted successfully:', result.data); 404 if (result.data.status == 200) { 405 generateBRM('forgotPass'); 406 } else { 407 generateBRM('userNoExist') 408 } 409 } else { 410 console.error('Form submission failed:', result.error); 411 } 412 }); 413 414} 415 416function sendNewActivationCode() { 417 document.getElementById('login_action').value = 'SendNewActivationCode'; 418 submitForm('sso_form_login') 419 .then(result => { 420 if (result.success) { 421 console.log('Form submitted successfully:', result.data); 422 if (result.data.status == 200) { 423 document.getElementById('se-sso').innerHTML = 424 ` 425 <div class="se-sso-container se-sso-container--activation"> 426 <div class="se-sso-title se-sso-title--activation">Aktivacijski email</div> 427 <div class="se-sso-container se-sso-container--button"> 428 <label for="se_header_default" class="se-sso-label se-sso-label--close"> 429 <svg focusable="false" viewBox="0 0 32 32" aria-hidden="true"><path d="M 28.035255,32.000001 0,3.9647831 3.9647831,0 32.000001,28.035255 Z"></path><path d="M 3.9647831,32.000001 32.000001,3.9647831 28.035255,0 3.5648696e-6,28.035255 Z"></path></svg> 430 </label> 431 </div> 432 <div class="se-sso-div"> 433 <span>Na tvoju email adresu je poslan aktivacijski email.</span> 434 </div> 435 <div class="se-sso-container se-sso-container--button-activation"> 436 <label for="se_header_default" class="se-sso-label se-sso-label--close"> 437 U redu 438 </label> 439 </div> 440 </div> 441 `; 442 } else { 443 generateBRM(99, document.getElementById('sso_form_login'), 4) 444 } 445 }else { 446 console.error('Form submission failed:', result.error); 447 } 448 }); 449} 450 451function buySubscription(packageID) { 452 window.location.href = '/narocnina-buy-subscription/?packageID=' + packageID; 453} 454 455function userLogout() { 456 var now = new Date(); 457 var time = now.getTime(); 458 var expireTime = time - 3600000 * 24; 459 now.setTime(expireTime); 460 document.cookie = "SE_SSO_token=;expires=Thu, 01-Jan-70 00:00:01 GMT;domain=net.hr;path=/"; 461 document.cookie = "SE_SSO_username=;expires=Thu, 01-Jan-70 00:00:01 GMT;domain=net.hr;path=/"; 462 463 window.location.reload(); 464 465} 466function removeBRM() { 467 if (document.querySelectorAll('.se-sso-brm').length > 0) { 468 for (i of document.querySelectorAll('.se-sso-brm')) { 469 i.remove() 470 } 471 } 472} 473 474function stringToColor(str) { 475 if (str.length < 2) { 476 throw new Error("String must be at least 2 characters long"); 477 } 478 479 // Turn the 2 chars into a number using char codes 480 let code = str.charCodeAt(0) * 31 + str.charCodeAt(1);
481 482 // Convert to hex and pad to 6 digits 483 let hex = (code * 1234567).toString(16).slice(0, 6); 484 485 // Ensure it's 6 chars 486 hex = hex.padEnd(6, '0'); 487 488 return `#${hex}`; 489} 490 491function getUserDetails() { 492 493 submitForm('get_user_data') 494 .then(result => { 495 if (result.success) { 496 console.log('Form submitted successfully:', result.data); 497 if (result.data.status == 200) { 498 console.log(result.data); 499 Object.entries(result.data.userData).forEach(([key, value]) => { 500 const input = document.getElementById('user_' + key); 501 if (input) { 502 if (input.type === 'checkbox') { 503 input.checked = value == 'Y' || value === true; 504 } else { 505 input.value = value; 506 } 507 } 508 }); 509 if (result.data.userData.username != '') { 510 document.getElementById('profile_avatar').innerHTML = '<div class="se-comments-avatar-char" style="background-color:' + stringToColor((result.data.userData.username).substring(0,2) ) + '">' + result.data.userData.username.substring(0,2) + '</div>'; 511 document.getElementById('profile_name').innerHTML = result.data.userData.username; 512 document.getElementById('profile_email').innerHTML = result.data.userData.email; 513 514 } 515 if(result.data.userData.package_name!=null){ 516 const voyoDiv = document.getElementById('voyo_div'); 517 voyoDiv.innerHTML = 'Povezani ste s Voyo pretplatom'; 518 voyoDiv.onclick = undefined; 519 voyoDiv.classList.add('active'); 520 521 } 522 } 523 524 } else { 525 console.error('Form submission failed:', result.error); 526 } 527 }); 528 /*const token = getCookie('SE_SSO_token'); 529 var xhrobj = new XMLHttpRequest(); 530 531 data = { 532 "action": "getUserData", 533 "token": token 534 }, 535 536 xhrobj.onreadystatechange = function () { 537 if (this.readyState == 4 && this.status === 200) { 538 var response = JSON.parse(xhrobj.responseText); 539 console.log(response.userData); 540 if (response.status == 200) { 541 // Loop through response to populate all matching input fields dynamically 542 Object.entries(response.userData).forEach(([key, value]) => { 543 const input = document.getElementById('user_' + key); 544 if (input) { 545 if (input.type === 'checkbox') { 546 input.checked = value == 'Y' || value === true; 547 } else { 548 input.value = value; 549 } 550 } 551 }); 552 } 553 } 554 } 555 556 xhrobj.open('POST', 'https://rtlsso.storyeditor.eu/include/public_actions.php'); 557 xhrobj.setRequestHeader("Content-Type", "text/plain"); 558 xhrobj.send(JSON.stringify(data)); */ 559} 560 561 562function updateUserData() { 563 564 const token = getCookie('SE_SSO_token'); 565 let form = document.getElementById('user_form_token') 566 form.value = token; 567 const message = document.getElementById('profile_submit_message') 568 message.innerText = 'Uspješna izmjena podataka!' 569 570 submitForm('user_form') 571 .then(result => { 572 if (result.success) { 573 console.log('Form submitted successfully:', result.data); 574 if (result.data.status == 200) { 575 console.log("Success!"); 576 } 577 message.classList.add('profile-submit-message--active') 578 579 } else { 580 console.error('Form submission failed:', result.error); 581 message.classList.add('profile-submit-message--active') 582 message.classList.add('profile-submit-message--fail') 583 message.innerText = 'Došlo je do pogreške!' 584 } 585 setTimeout(() => { 586 message.setAttribute('class', 'profile-submit-message'); 587 window.location.href="/profil"; 588 }, 2500) 589 }); 590} 591 592function registerVoyoMail() { 593 594 submitForm('voyo_form') 595 .then(result => { 596 if (result.success) { 597 console.log('Form submitted successfully:', result.data); 598 if (result.data.status == 200) { 599 console.log("Success!"); 600 showPopup('Uspješna registracija Voyo korisnika!'); 601 }else{ 602 showPopup('Ovaj mail nema Voyo pretplatu!'); 603 } 604 } else { 605 console.error('Form submission failed:', result.error); 606 showPopup('Došlo je do pogreške!'); 607 } 608 });
609} 610/* 611function updateUserData() { 612 613 const token = getCookie('SE_SSO_token'); 614 document.getElementById('user_form_token').value = token; 615 616 submitForm('user_form') 617 .then(result => { 618 if (result.success) { 619 console.log('Form submitted successfully:', result.data); 620 if (result.data.status == 200) { 621 console.log("Success!"); 622 } 623 } else { 624 console.error('Form submission failed:', result.error); 625 } 626 }); 627 const formObject = {}; 628 629 for (let [key, value] of formData.entries()) { 630 formObject[key] = value; 631 } 632 633 // Add extra data 634 formObject.token = token; 635 formObject.action = 'updateUserData'; 636 637 var xhrobj = new XMLHttpRequest(); 638 639 console.log("FormData entries:"); 640 641 xhrobj.onload = function () { 642 if (xhrobj.status === 200) { 643 console.log("Success!"); 644 } else { 645 alert("Error occured"); 646 } 647 }; 648 xhrobj.open('POST', 'https://rtlsso.storyeditor.eu/include/public_actions.php'); 649 xhrobj.setRequestHeader("Content-Type", "text/plain"); 650 xhrobj.send(JSON.stringify(formObject)); 651 652 return false; 653} 654*/ 655 656function getMyComments() { 657 658 submitForm('get_comments_form') 659 .then(result => { 660 if (result.success) { 661 if (result.data.status == 200) { 662 comments = result.data.comments; 663 console.log(comments); 664 665 var commentContainer = document.getElementsByClassName('se-user-comments')[0]; 666 comments.forEach((comment) =>{ 667 if(comment.web_head==''){ 668 comment.web_head = "Odgovor na komentar"; 669 } 670 var result = 0; 671 if(comment.votes_up!=null && comment.votes_down!=null){ 672 result = comment.votes_up-comment.votes_down; 673 } 674 var upClass = ''; 675 var downClass = ''; 676 var resultColor = ''; 677 if(result>0){ 678 upClass = 'active'; 679 resultColor = 'color:#F15B24'; 680 } 681 if(result<0){ 682 downClass = 'active'; 683 resultColor = 'color:#2495F1'; 684 } 685 commentContainer.innerHTML += ` 686 <div class="se-user-comment-container"> 687 <div class="se-user-comment-article"> 688 ${comment.web_head} 689 </div> 690 <div class="se-user-comment-time">${comment.c_date}</div> 691 <div class="se-user-comment-content">${comment.comment}</div> 692 <div class="se-user-comment-rating-container"> 693 <button class="se-user-comment-rate se-user-comment-rate--up ${upClass}" onclick=""> 694 <svg width="10" height="10" viewBox="0 0 10 10" 695 xmlns="http://www.w3.org/2000/svg"> 696 <path fill-rule="evenodd" clip-rule="evenodd" 697 d="M5.00008 0L9.70718 4.70711L8.29297 6.12132L6.00008 3.82843V9.91421H4.00008V3.82843L1.70718 6.12132L0.292969 4.70711L5.00008 0Z"/> 698 </svg> 699 </button> 700 <div class="se-user-comment-rating-result" style="${resultColor}">${result}</div> 701 <button class="se-user-comment-rate se-user-comment-rate--down ${downClass}"> 702 <svg width="10" height="10" viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"> 703 <path fill-rule="evenodd" clip-rule="evenodd" 704 d="M4.99995 10.0001L9.70706 5.29302L8.29285 3.8788L5.99995 6.1717V0.0859089H3.99995V6.1717L1.70706 3.8788L0.292847 5.29302L4.99995 10.0001Z" /> 705 </svg> 706 </button> 707 <button class="se-comment-action se-comment-action--delete" onclick="document.getElementById('deleteID').value=${comment.id};deleteComment();">Obriši</button> 708 </div> 709 710 </div>` 711 } 712 713 ); 714 715 716 } else { 717 console.log(result); 718 719 comments = null; 720 } 721 } 722 });
723} 724 725function deleteComment(commentID) { 726 submitForm('delete_comment') 727 .then(result => { 728 console.log(result); 729 730 if (result.success) { 731 if (result.data.status == 200) { 732 alert('Komentar obrisan!'); 733 } else { 734 alert('Doslo je do pogreske!'); 735 } 736 } 737 }); 738} 739 740async function userHasActivePremium(){ 741 const token = getCookie('SE_SSO_token'); 742 if(token){ 743 console.log(token); 744 // Define your data in JS 745 const data = { 746 action: 'userHasActiveSubscription', 747 token: token 748 }; 749 750 // Create FormData and populate it 751 const formData = new FormData(); 752 formData.append('action', data.action); 753 formData.append('token', data.token); 754 755 // Your original pattern works the same 756 const options = { 757 method: 'POST', 758 body: formData 759}; 760 761const response = await fetch('/submit/', options); 762 763 if (!response.ok) { 764 throw new Error(`HTTP error! status: ${response.status}`); 765 } 766 767 return await response.json(); 768 769 } 770 return false; 771 772} 773 774async function submitForm(formName) { 775 try { 776 // Get the form element by name 777 const form = document.getElementById(formName); 778 779 if (!form) { 780 throw new Error(`Form with name "${formName}" not found`); 781 } 782 783 var endpoint = '/submit/'; 784 785 const input = form.querySelector('input[name="request_type"]'); 786 787 if (input) { 788 endpoint = '/submit/?request_type=data'; 789 } 790 console.log(input); 791 792 console.log(endpoint); 793 // Create FormData from the form 794 const formData = new FormData(form); 795 796 // Fixed options 797 const options = { 798 method: 'POST', 799 body: formData 800 }; 801 802 // Make the request 803 const response = await fetch(endpoint, options); 804 805 // Check if response is ok 806 if (!response.ok) { 807 throw new Error(`HTTP error! status: ${response.status}`); 808 } 809 810 // Try to parse JSON, fallback to text if it fails 811 let result; 812 try { 813 result = await response.json(); 814 } catch (e) { 815 result = await response.text(); 816 } 817 818 return { 819 success: true, 820 data: result, 821 status: response.status, 822 statusText: response.statusText 823 }; 824 825 } catch (error) { 826 return { 827 success: false, 828 error: error.message, 829 data: null 830 }; 831 } 832} 833 834 835 836window.addEventListener('DOMContentLoaded', () => { 837 const sso = document.getElementById('se-sso') 838 const passwordInput = document?.getElementById('sso_register_password'); 839 const termsCheckbox = document?.getElementById('sso_register_terms'); 840 const requirementItems = document?.querySelectorAll('.se-sso-reg-check'); 841 const ssoLabel = document.getElementById('se_header_sso_label') 842 const objaviButton = document.getElementById('article_comment')?.querySelector('button') 843 const textboxInput = document.getElementById('comment_textarea'); 844 845 846 // Define validation functions for each requirement 847 const validators = { 848 length: (password) => password.length >= 8, 849 number: (password) => /\d/.test(password), 850 capital: (password) => /[A-Z]/.test(password), 851 special: (password) => /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~`]/.test(password), 852 terms: () => termsCheckbox.checked 853 }; 854 855 // Function to validate all requirements and update UI 856 function validateRequirements() { 857 const password = passwordInput.value; 858 859 requirementItems.forEach(item => { 860 const requirement = item.dataset.requirement; 861 const isValid = validators[requirement](password); 862 863 if (isValid) { 864 item.classList.add('valid'); 865 } else { 866 item.classList.remove('valid'); 867 } 868 }); 869 } 870 871 // Add event listeners for password input 872 passwordInput?.addEventListener('input', validateRequirements); 873 passwordInput?.addEventListener('focus', validateRequirements); 874 875 // Add event listeners for terms checkbox 876 termsCheckbox?.addEventListener('change', validateRequirements); 877 termsCheckbox?.addEventListener('focus', validateRequirements); 878 879 if (getCookie('SE_SSO_token')) { 880 ssoLabel?.insertAdjacentHTML('beforeend', ` 881 <div class="sso-user-popup" id="sso_user_popup"> 882 <a class="sso-user-popup__profile" href="/profil"> 883 Moj Profil
884 <svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg"> 885 <path fill-rule="evenodd" clip-rule="evenodd" 886 d="M9.91421 5.29289L5.20711 0.585787L3.79289 2L6.08579 4.29289L1.65788e-06 4.29289L1.74531e-06 6.29289L6.08579 6.29289L3.79289 8.58579L5.20711 10L9.91421 5.29289Z" 887 fill="#666766"></path> 888 </svg> 889 </a> 890 <div class="sso-user-popup__logout">Odjavi se</div> 891 </div> 892 `) 893 document.getElementById('sso_user_popup')?.querySelector('.sso-user-popup__logout').addEventListener('click', e => { 894 e.preventDefault(); 895 e.stopPropagation(); 896 userLogout(); 897 }) 898 899 } else { 900 if (objaviButton) { 901 objaviButton.removeAttribute('onclick'); 902 objaviButton.innerHTML = 'Prijavi se'; 903 textboxInput.placeholder = 'Prijavi se da možeš komentirati...'; 904 objaviButton.addEventListener('click', () => { 905 ssoLabel?.click() 906 }) 907 } 908 } 909}) 910 911document.addEventListener('click', (e) => { 912 const link = e.target.closest('a[href="#sso-register"]'); 913 if (!link) return; 914 915 e.preventDefault(); 916 917 document.getElementById('sso_control_register')?.click(); 918 document.getElementById('se_header_sso')?.click(); 919});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.