scripts.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*!
  2. * Start Bootstrap - Freelancer v7.0.7 (https://startbootstrap.com/theme/freelancer)
  3. * Copyright 2013-2023 Start Bootstrap
  4. * Licensed under MIT (https://github.com/StartBootstrap/startbootstrap-freelancer/blob/master/LICENSE)
  5. */
  6. //
  7. // Scripts
  8. //
  9. window.addEventListener('DOMContentLoaded', event => {
  10. // Navbar shrink function
  11. var navbarShrink = function () {
  12. const navbarCollapsible = document.body.querySelector('#mainNav');
  13. if (!navbarCollapsible) {
  14. return;
  15. }
  16. if (window.scrollY === 0) {
  17. navbarCollapsible.classList.remove('navbar-shrink')
  18. } else {
  19. navbarCollapsible.classList.add('navbar-shrink')
  20. }
  21. };
  22. // Shrink the navbar
  23. navbarShrink();
  24. // Shrink the navbar when page is scrolled
  25. document.addEventListener('scroll', navbarShrink);
  26. // Activate Bootstrap scrollspy on the main nav element
  27. const mainNav = document.body.querySelector('#mainNav');
  28. if (mainNav) {
  29. new bootstrap.ScrollSpy(document.body, {
  30. target: '#mainNav',
  31. rootMargin: '0px 0px -40%',
  32. });
  33. };
  34. // Collapse responsive navbar when toggler is visible
  35. const navbarToggler = document.body.querySelector('.navbar-toggler');
  36. const responsiveNavItems = [].slice.call(
  37. document.querySelectorAll('#navbarResponsive .nav-link')
  38. );
  39. responsiveNavItems.map(function (responsiveNavItem) {
  40. responsiveNavItem.addEventListener('click', () => {
  41. if (window.getComputedStyle(navbarToggler).display !== 'none') {
  42. navbarToggler.click();
  43. }
  44. });
  45. });
  46. });
  47. // $(document).ready(function () {
  48. // $('#screenshotbtn').on('click', function () {
  49. // const url = '/api/take-screenshot/';
  50. // $.ajax({
  51. // url: url,
  52. // type: 'POST',
  53. // data: {}, // no data to send
  54. // contentType: 'application/json',
  55. // dataType: 'json', // expect JSON response
  56. // success: function (res) {
  57. // if (res.image_url && res.image_url.includes('walmart')) {
  58. // $("#crop_container1 img").attr("src", res.image_url + '?t=' + new Date().getTime());
  59. // } else if (res.image_url && res.image_url.includes('amazon')) {
  60. // $("#crop_container2 img").attr("src", res.image_url + '?t=' + new Date().getTime());
  61. // } else if (res.image_url && res.image_url.includes('target')) {
  62. // $("#crop_container3 img").attr("src", res.image_url + '?t=' + new Date().getTime());
  63. // } else if (res.image_url && res.image_url.includes('bestbuy')) {
  64. // $("#crop_container4 img").attr("src", res.image_url + '?t=' + new Date().getTime());
  65. // } else {
  66. // alert("No image found");
  67. // }
  68. // },
  69. // error: function (xhr) {
  70. // console.error("Error:", xhr.responseText);
  71. // alert("Error: " + xhr.responseText);
  72. // }
  73. // });
  74. // });
  75. // });
  76. $(document).ready(function () {
  77. $('#screenshotbtn').on('click', function () {
  78. const urls = [
  79. 'walmart',
  80. 'amazon',
  81. 'target',
  82. 'bestbuy'
  83. ];
  84. // function to call Django API one by one
  85. function processNext(index) {
  86. if (index >= urls.length) return; // stop when done
  87. $.ajax({
  88. url: '/api/take-screenshot/',
  89. type: 'POST',
  90. data: JSON.stringify({ site: urls[index] }), // optional if you want to send current site name
  91. contentType: 'application/json',
  92. dataType: 'json',
  93. success: function (res) {
  94. const ts = '?t=' + new Date().getTime();
  95. if (res.image_url && res.image_url.includes('walmart')) {
  96. $("#crop_container1 img").attr("src", res.image_url + ts);
  97. } else if (res.image_url && res.image_url.includes('amazon')) {
  98. console.log("hereeeeee", res.carousel_img1)
  99. $("#crop_container2 img").attr("src", res.image_url + ts);
  100. $('#crop_container5 img').attr("src", res.image_url + ts);
  101. $('#crop_container13 img').attr("src", res.image_url + ts);
  102. $('#crop_container16 img').attr("src", res.image_url + ts);
  103. $('#crop_container19 img').attr("src", res.best_seller_img1 + ts);
  104. $('#crop_container22 img').attr("src", res.best_seller_img2 + ts);
  105. $('#upload_container1 img').eq(0).attr("src", res.carousel_img1 + ts);
  106. $('#upload_container1 img').eq(1).attr("src", res.carousel_img2 + ts);
  107. $('#upload_container1 img').eq(2).attr("src", res.carousel_img3 + ts);
  108. $('#amazonCarosalLink .editable-link').attr("href", res.carousel_link1).text(res.carousel_name1);
  109. // here the best seller content taxt should be laces in a li elements for the id amazonEditableBestSellerContent
  110. try {
  111. const bestSellers = JSON.parse(res.best_seller_content1);
  112. let listHtml = '<ul class="editable-list">';
  113. console.log(bestSellers)
  114. for (const section in bestSellers) {
  115. console.log("section", section)
  116. const items = bestSellers[section];
  117. console.log("item", typeof(items))
  118. // listHtml += `<h5>${section}</h5><ul class="editable-list">`;
  119. // items.forEach(item => {
  120. listHtml += `<li contenteditable="true">${items}</li>`;
  121. // });
  122. }
  123. listHtml += `</ul>`;
  124. // replace only the content section without breaking other editable tools
  125. const $content = $('#amazonEditableBestSellerContent');
  126. $content.find('.editable-list, h5').remove(); // remove old lists and headers
  127. console.log(listHtml)
  128. $content.prepend(listHtml); // append new HTML
  129. } catch (e) {
  130. console.error("Error parsing best seller content:", e);
  131. }
  132. try {
  133. const bestSellers = JSON.parse(res.best_seller_content2);
  134. let listHtml = '<ul class="editable-list">';
  135. console.log(bestSellers)
  136. for (const section in bestSellers) {
  137. console.log("section", section)
  138. const items = bestSellers[section];
  139. console.log("item", typeof(items))
  140. // listHtml += `<h5>${section}</h5><ul class="editable-list">`;
  141. // items.forEach(item => {
  142. listHtml += `<li contenteditable="true">${items}</li>`;
  143. // });
  144. }
  145. listHtml += `</ul>`;
  146. // replace only the content section without breaking other editable tools
  147. const $content = $('#amazonEditableBestSellerContent1');
  148. $content.find('.editable-list, h5').remove(); // remove old lists and headers
  149. console.log(listHtml)
  150. $content.prepend(listHtml); // append new HTML
  151. } catch (e) {
  152. console.error("Error parsing best seller content:", e);
  153. }
  154. // $('#upload_container1 img').attr("src", res.carousel_img1)
  155. // $('#amazonCarosalLink a').attr("href", res.carousel_link1)
  156. // $('#amazonCarosalLink a').text(res.carousel_name1)
  157. } else if (res.image_url && res.image_url.includes('target')) {
  158. $("#crop_container3 img").attr("src", res.image_url + ts);
  159. $("#crop_container6 img").attr("src", res.image_url + ts);
  160. $("#crop_container11 img").attr("src", res.image_url + ts);
  161. $("#crop_container14 img").attr("src", res.image_url + ts);
  162. $("#crop_container17 img").attr("src", res.image_url + ts);
  163. $("#crop_container20 img").attr("src", res.image_url + ts);
  164. $("#crop_container23 img").attr("src", res.image_url + ts);
  165. } else if (res.image_url && res.image_url.includes('bestbuy')) {
  166. $("#crop_container4 img").attr("src", res.image_url + ts);
  167. $("#crop_container7 img").attr("src", res.image_url + ts);
  168. $("#crop_container15 img").attr("src", res.image_url + ts);
  169. $("#crop_container18 img").attr("src", res.image_url + ts);
  170. $("#crop_container12 img").attr("src", res.first_section + ts);
  171. $('#amazonCarosalLink1 .editable-link').attr("href", res.first_section_url).text(res.first_section_title);
  172. $("#crop_container21 img").attr("src", res.best_seller_img1 + ts);
  173. $("#crop_container24 img").attr("src", res.best_seller_img2 + ts);
  174. try {
  175. const bestSellers = JSON.parse(res.best_seller_content1);
  176. let listHtml = '<ul class="editable-list">';
  177. console.log(bestSellers)
  178. for (const section in bestSellers) {
  179. console.log("section", section)
  180. const items = bestSellers[section];
  181. console.log("item", typeof(items))
  182. // listHtml += `<h5>${section}</h5><ul class="editable-list">`;
  183. // items.forEach(item => {
  184. listHtml += `<li contenteditable="true">${items}</li>`;
  185. // });
  186. }
  187. listHtml += `</ul>`;
  188. // replace only the content section without breaking other editable tools
  189. const $content = $('#amazonEditableBestSellerContent2');
  190. $content.find('.editable-list, h5').remove(); // remove old lists and headers
  191. console.log(listHtml)
  192. $content.prepend(listHtml); // append new HTML
  193. } catch (e) {
  194. console.error("Error parsing best seller content:", e);
  195. }
  196. try {
  197. const bestSellers = JSON.parse(res.best_seller_content2);
  198. let listHtml = '<ul class="editable-list">';
  199. console.log(bestSellers)
  200. for (const section in bestSellers) {
  201. console.log("section", section)
  202. const items = bestSellers[section];
  203. console.log("item", typeof(items))
  204. // listHtml += `<h5>${section}</h5><ul class="editable-list">`;
  205. // items.forEach(item => {
  206. listHtml += `<li contenteditable="true">${items}</li>`;
  207. // });
  208. }
  209. listHtml += `</ul>`;
  210. // replace only the content section without breaking other editable tools
  211. const $content = $('#amazonEditableBestSellerContent3');
  212. $content.find('.editable-list, h5').remove(); // remove old lists and headers
  213. console.log(listHtml)
  214. $content.prepend(listHtml); // append new HTML
  215. } catch (e) {
  216. console.error("Error parsing best seller content:", e);
  217. }
  218. }
  219. // process the next one
  220. processNext(index + 1);
  221. },
  222. error: function (xhr) {
  223. console.error("Error:", xhr.responseText);
  224. processNext(index + 1); // continue even if one fails
  225. }
  226. });
  227. }
  228. // start with the first URL
  229. processNext(0);
  230. });
  231. });