TestingFrenzy

game.js

May 28th, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. document.addEventListener('DOMContentLoaded', function () {
  2. // Retrieve all elements for "Numero" and "Posizione" headers
  3. var numeroHeaders = document.querySelectorAll('th[data-header="Number"]');
  4. var posizioneHeaders = document.querySelectorAll('th[data-header="Position"]');
  5.  
  6. function checkScreenSize() {
  7. if (window.innerWidth <= 800) {
  8. // Update each "Numero" header
  9. numeroHeaders.forEach(function(header) {
  10. header.textContent = 'N';
  11. });
  12. // Update each "Posizione" header
  13. posizioneHeaders.forEach(function(header) {
  14. header.textContent = 'Pos'; // Shortened text for "Posizione"
  15. });
  16. } else {
  17. // Revert back to full text for larger screens
  18. numeroHeaders.forEach(function(header) {
  19. header.textContent = 'Number';
  20. });
  21. posizioneHeaders.forEach(function(header) {
  22. header.textContent = 'Position';
  23. });
  24. }
  25. }
  26.  
  27. // Add event listener for window resize
  28. window.addEventListener('resize', checkScreenSize);
  29. // Initial check on load
  30. checkScreenSize();
  31. });
  32.  
  33.  
  34. document.addEventListener('DOMContentLoaded', function() {
  35. // Define a mapping from full position names to abbreviations
  36. const positionAbbreviations = {
  37. 'Goalkeeper': 'GK',
  38. 'Left-Back': 'LB',
  39. 'Right-Back': 'RB',
  40. 'Centre-Back': 'CB',
  41. 'Defensive Midfield': 'DM',
  42. 'Left Midfield': 'LM',
  43. 'Central Midfield': 'CM',
  44. 'Right Midfield': 'RM',
  45. 'Centre-Forward': 'CF',
  46. 'Left Winger': 'LW',
  47. 'Right Winger': 'RW',
  48. 'Attacking Midfield': 'AM',
  49. 'Second Striker': 'SS'
  50. };
  51.  
  52. function replacePositionText() {
  53. if (window.innerWidth <= 800) { // Only execute if the screen size is 800px or smaller
  54. // Find all td elements that could contain these positions
  55. const tds = document.querySelectorAll('td');
  56.  
  57. // Loop through each td and replace the text if it matches a position
  58. tds.forEach(td => {
  59. // Check if the text content of the td is a key in the positionAbbreviations map
  60. if (positionAbbreviations[td.textContent]) {
  61. // Replace the text content with the corresponding abbreviation
  62. td.textContent = positionAbbreviations[td.textContent];
  63. }
  64. });
  65. }
  66. }
  67.  
  68. // Run when the page is loaded
  69. replacePositionText();
  70.  
  71. // Additionally, adjust when the window is resized
  72. window.addEventListener('resize', replacePositionText);
  73. });
  74.  
  75.  
  76.  
  77.  
Tags: js
Advertisement
Add Comment
Please, Sign In to add comment