Advertisement
nrzmalik

Storyline Course Expiry JavaScript

Jul 8th, 2023 (edited)
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.62 KB | Source Code | 0 0
  1. (function() {
  2.  
  3.     const currentDate = new Date();
  4.  
  5.  
  6.     const player = window.GetPlayer ? GetPlayer() : null;
  7.     if (!player) {
  8.         console.error('GetPlayer function not found');
  9.         return;
  10.     }
  11.  
  12.  
  13.     const courseExpiryDate = player.GetVar("ExpiryDate");
  14.     if (!courseExpiryDate || typeof courseExpiryDate !== 'string') {
  15.         console.error('Invalid expiry date');
  16.         return;
  17.     }
  18.  
  19.  
  20.     const [day, month, year] = courseExpiryDate.split('-').map(Number);
  21.     const finalCourseExpiryDate = new Date(year, month - 1, day);
  22.  
  23.     if (isNaN(finalCourseExpiryDate.getTime())) {
  24.         console.error('Invalid date format');
  25.         return;
  26.     }
  27.  
  28.     if (currentDate > finalCourseExpiryDate) {
  29.         showExpiryModal();
  30.     }
  31.  
  32.     function showExpiryModal() {
  33.         const overlay = document.createElement('div');
  34.         Object.assign(overlay.style, {
  35.             width: '100%',
  36.             height: '100%',
  37.             background: 'rgba(0, 0, 0, 0.5)',
  38.             position: 'fixed',
  39.             top: '0',
  40.             left: '0',
  41.             zIndex: '9999',
  42.             display: 'flex',
  43.             justifyContent: 'center',
  44.             alignItems: 'center'
  45.         });
  46.  
  47.         document.body.style.overflow = 'hidden';
  48.  
  49.         const modalDiv = document.createElement('div');
  50.         Object.assign(modalDiv.style, {
  51.             width: '400px',
  52.             background: '#fff',
  53.             color: '#000',
  54.             padding: '20px',
  55.             borderRadius: '8px',
  56.             boxShadow: '0px 0px 15px rgba(0,0,0,0.2)'
  57.         });
  58.  
  59.         const p = document.createElement('p');
  60.         p.textContent = 'This course has expired.';
  61.         Object.assign(p.style, {
  62.             fontSize: '18px',
  63.             textAlign: 'center'
  64.         });
  65.  
  66.         const button = document.createElement('button');
  67.         button.textContent = 'Close';
  68.         Object.assign(button.style, {
  69.             display: 'block',
  70.             width: '100%',
  71.             padding: '10px',
  72.             marginTop: '20px',
  73.             border: 'none',
  74.             background: '#3498db',
  75.             color: '#fff',
  76.             fontSize: '18px',
  77.             cursor: 'pointer',
  78.             borderRadius: '5px'
  79.         });
  80.  
  81.         button.addEventListener('click', () => {
  82.             document.body.style.overflow = 'auto';
  83.             overlay.remove();
  84.             if (window.close) {
  85.                 window.close();
  86.             }
  87.         });
  88.  
  89.         modalDiv.appendChild(p);
  90.         modalDiv.appendChild(button);
  91.         overlay.appendChild(modalDiv);
  92.         document.body.appendChild(overlay);
  93.     }
  94. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement