jamescolin

Fake Social Proof Notification

Jul 11th, 2022 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
  2. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  3. <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
  4. <script>
  5. window.addEventListener('load', function () {
  6. var availableProducts = [
  7. 'LE LIVRE',
  8. 'LA FORMATION',
  9. 'LE CADEAU',
  10. 'LE BONUS',
  11. ];
  12.  
  13. let mynewdiv = document.createElement("div");
  14. mynewdiv.setAttribute("style", "position:fixed; bottom: 10px; left: 10px;");
  15. mynewdiv.setAttribute("class", "toast");
  16. mynewdiv.setAttribute("id", "toast-achat");
  17. mynewdiv.setAttribute("role", "alert");
  18. mynewdiv.setAttribute("aria-live", "assertive");
  19. mynewdiv.setAttribute("aria-atomic", "true");
  20.  
  21. mynewdiv.innerHTML = (`
  22. <div class="toast-header">
  23. <img id="personface" src="https://parmois.com/125x125.png" class="rounded-circle me-2" alt="...">
  24. <strong class="me-auto">PARMOIS<i>.com</i></strong>
  25. <small class="text-muted" id="date-achat">à l'instant</small>
  26. <button type="button" class="btn-close" data-dismiss="toast" aria-label="Close"></button>
  27. </div>
  28. <div class="toast-body" id="contenu-achat">
  29. </div>
  30. `);
  31. document.querySelector("#app").appendChild(mynewdiv);
  32.  
  33. const toastLive = new bootstrap.Toast(document.getElementById('toast-achat'), {animation: true, autohide: true, delay: 6000});
  34.  
  35. async function generatePerson() {
  36. const response = await fetch('https://randomuser.me/api/?nat=fr');
  37. const data = await response.json();
  38. return (data['results'][0]);
  39. }
  40.  
  41. function generateRandomNumber(maxInt, failSafe=false) {
  42. var finalNumber = Math.round(Math.random() * maxInt);
  43. if (failSafe === true) {
  44. if (finalNumber <= 8) {
  45. return finalNumber + 8;
  46. }
  47. }
  48. return finalNumber;
  49. }
  50.  
  51. function generateToastPopup() {
  52. toastLive.show();
  53. }
  54.  
  55. async function generateSalesNotification() {
  56. var person = await generatePerson();
  57. var fullname = person['name']['first'] +' '+ person['name']['last'];
  58. var picture = person['picture']['thumbnail'];
  59. var city = person['location']['city'];
  60. var selectedProduct = availableProducts[generateRandomNumber(availableProducts.length-1)];
  61. var whenBought = generateRandomNumber(59);
  62. if(whenBought <2) {
  63. if(whenBought <1) {
  64. whenBought = 'À l\'instant.';
  65. } else {
  66. whenBought = 'Il y a ' + whenBought + ' minute.';
  67. }
  68. } else {
  69. whenBought = 'Il y a ' + whenBought + ' minutes.';
  70. }
  71. var toastContentBody = fullname + ' (' + city + ') a téléchargé <em style="color: #d87d6a;">' + selectedProduct + '</em>';
  72. document.getElementById('personface').src = picture;
  73. document.getElementById('personface').alt = fullname;
  74. document.getElementById('date-achat').innerHTML = whenBought;
  75. document.getElementById('contenu-achat').innerHTML = toastContentBody;
  76. generateToastPopup();
  77. }
  78.  
  79. var randomTimeInterval = generateRandomNumber(22, failsafe=true) * 1000;
  80.  
  81. function randomPopupInterval() {
  82. randomTimeInterval = generateRandomNumber(22, failsafe=true) * 1000;
  83. generateSalesNotification();
  84. setTimeout(randomPopupInterval, randomTimeInterval);
  85. }
  86.  
  87. randomPopupInterval();
  88. });
  89. </script>
Add Comment
Please, Sign In to add comment