Advertisement
plirof2

pack_JS_convetLinksFOrRuffle 241127c

Nov 28th, 2024 (edited)
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. // ((((((((((((((((((((((replace_swfChangeHrefToRuffle v01 211127 opengame Ruffle, noopengame ((((((((((((((((((((((
  3. //<!-- Modify HREF for ruffle 241127c (add it to the end of the script)-->
  4.  
  5.     // Function to get the Chrome version
  6.     function getBrowserVersion() {
  7.         const userAgent = navigator.userAgent;
  8.         //const match = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
  9.         //return match ? parseInt(match[2], 10) : null;
  10.         // Detect Chrome or Chromium (including version number)
  11.         const chromeMatch = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
  12.         if (chromeMatch) {
  13.             return parseInt(chromeMatch[2], 10);
  14.         }
  15.  
  16.         // Detect Firefox (including version number)
  17.         const firefoxMatch = userAgent.match(/Firefox\/([0-9]+)\./);
  18.         if (firefoxMatch) {
  19.             return parseInt(firefoxMatch[1], 10);
  20.         }
  21.         // If neither Chrome nor Firefox is found
  22.         return 0;        
  23.     }
  24.  
  25.     // Function to modify href links
  26.     function modifyLinks() {
  27.         const links = document.querySelectorAll('a');
  28.         const prefix = './opengame_ruffle.php?file=';
  29.  
  30.         links.forEach(link => {
  31.             const currentHref = link.getAttribute('href');
  32.             if (currentHref && currentHref.includes('.swf')  && !currentHref.includes('ruffle') ) {
  33.                 //link.setAttribute('href', prefix + encodeURIComponent(currentHref)); //ORIG works but shows %2F instead of '/'
  34.                 link.setAttribute('href', prefix + (currentHref));
  35.             }
  36.         });
  37.     }
  38.  
  39.     // Check Chrome version and modify links if necessary
  40.     const browserVersion = getBrowserVersion();
  41.     console.log("-------------CHROMEversion="+browserVersion);
  42.     if (browserVersion > 70 && swfChangeHrefToRuffle) {
  43.         modifyLinks();
  44.     }
  45.  
  46. // )))))))))))))))))))))) replace_swfChangeHrefToRuffle ))))))))))))))))))))))
  47. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement