Guest User

Untitled

a guest
Jul 19th, 2025
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         CFE Desktop View Forcer
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.0
  5. // @description  Force CFE receipt page to always display in desktop view
  6. // @author       You
  7. // @match        https://app.cfe.mx/Aplicaciones/CCFE/ReciboDeLuzGMX/Consulta*
  8. // @match        https://app.cfe.mx/Aplicaciones/CCFE/ReciboDeLuzGMX/*
  9. // @grant        none
  10. // @run-at       document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.     'use strict';
  15.    
  16.     // Function to force desktop view
  17.     function forceDesktopView() {
  18.         // Remove or modify viewport meta tag
  19.         const viewportMeta = document.querySelector('meta[name="viewport"]');
  20.         if (viewportMeta) {
  21.             viewportMeta.setAttribute('content', 'width=1024, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no');
  22.         } else {
  23.             // Create viewport meta tag if it doesn't exist
  24.             const newViewport = document.createElement('meta');
  25.             newViewport.name = 'viewport';
  26.             newViewport.content = 'width=1024, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no';
  27.             document.head.appendChild(newViewport);
  28.         }
  29.        
  30.         // Add CSS to force desktop layout
  31.         const style = document.createElement('style');
  32.         style.textContent = `
  33.             /* Force desktop view styles */
  34.             body {
  35.                 min-width: 1024px !important;
  36.                 width: auto !important;
  37.             }
  38.            
  39.             /* Override mobile-specific styles */
  40.             @media screen and (max-width: 768px) {
  41.                 * {
  42.                     max-width: none !important;
  43.                     width: auto !important;
  44.                 }
  45.                
  46.                 .container,
  47.                 .container-fluid {
  48.                     width: 100% !important;
  49.                     max-width: none !important;
  50.                     padding-left: 15px !important;
  51.                     padding-right: 15px !important;
  52.                 }
  53.                
  54.                 .row {
  55.                     margin-left: -15px !important;
  56.                     margin-right: -15px !important;
  57.                 }
  58.                
  59.                 .col-xs-12,
  60.                 .col-sm-12,
  61.                 .col-md-12,
  62.                 .col-lg-12 {
  63.                     width: 100% !important;
  64.                     float: left !important;
  65.                 }
  66.                
  67.                 /* Force table to display properly */
  68.                 table {
  69.                     width: 100% !important;
  70.                     table-layout: auto !important;
  71.                 }
  72.                
  73.                 /* Prevent text from being too large on mobile */
  74.                 input, select, textarea, button {
  75.                     font-size: 14px !important;
  76.                 }
  77.                
  78.                 /* Override any mobile-specific hiding */
  79.                 .hidden-xs {
  80.                     display: block !important;
  81.                 }
  82.                
  83.                 .visible-xs {
  84.                     display: none !important;
  85.                 }
  86.             }
  87.            
  88.             /* Ensure the page doesn't get squeezed */
  89.             html {
  90.                 min-width: 1024px !important;
  91.                 overflow-x: auto !important;
  92.             }
  93.            
  94.             /* Override Bootstrap responsive utilities if present */
  95.             .hidden-sm,
  96.             .hidden-md,
  97.             .hidden-lg {
  98.                 display: block !important;
  99.             }
  100.            
  101.             /* Force form elements to maintain desktop sizing */
  102.             .form-control {
  103.                 height: 34px !important;
  104.                 padding: 6px 12px !important;
  105.                 font-size: 14px !important;
  106.             }
  107.            
  108.             /* Ensure buttons maintain proper size */
  109.             .btn {
  110.                 padding: 6px 12px !important;
  111.                 font-size: 14px !important;
  112.             }
  113.         `;
  114.        
  115.         // Insert the style as early as possible
  116.         if (document.head) {
  117.             document.head.appendChild(style);
  118.         } else {
  119.             document.addEventListener('DOMContentLoaded', () => {
  120.                 document.head.appendChild(style);
  121.             });
  122.         }
  123.        
  124.         // Override window.screen properties to simulate desktop
  125.         if (typeof Object.defineProperty === 'function') {
  126.             try {
  127.                 Object.defineProperty(window.screen, 'width', {
  128.                     get: function() { return 1920; }
  129.                 });
  130.                 Object.defineProperty(window.screen, 'availWidth', {
  131.                     get: function() { return 1920; }
  132.                 });
  133.                 Object.defineProperty(window, 'innerWidth', {
  134.                     get: function() { return Math.max(1024, window.outerWidth || 1024); }
  135.                 });
  136.             } catch (e) {
  137.                 console.log('Could not override screen properties:', e);
  138.             }
  139.         }
  140.        
  141.         // Override navigator.userAgent if needed (some sites check this)
  142.         if (navigator.userAgent && navigator.userAgent.includes('Mobile')) {
  143.             Object.defineProperty(navigator, 'userAgent', {
  144.                 get: function() {
  145.                     return navigator.userAgent.replace(/Mobile/gi, 'Desktop');
  146.                 }
  147.             });
  148.         }
  149.     }
  150.    
  151.     // Apply desktop view immediately
  152.     forceDesktopView();
  153.    
  154.     // Also apply when DOM is loaded
  155.     if (document.readyState === 'loading') {
  156.         document.addEventListener('DOMContentLoaded', forceDesktopView);
  157.     }
  158.    
  159.     // Monitor for dynamic content changes
  160.     if (typeof MutationObserver !== 'undefined') {
  161.         const observer = new MutationObserver(function(mutations) {
  162.             let shouldReapply = false;
  163.             mutations.forEach(function(mutation) {
  164.                 if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  165.                     for (let node of mutation.addedNodes) {
  166.                         if (node.nodeType === Node.ELEMENT_NODE) {
  167.                             if (node.tagName === 'META' && node.getAttribute('name') === 'viewport') {
  168.                                 shouldReapply = true;
  169.                                 break;
  170.                             }
  171.                         }
  172.                     }
  173.                 }
  174.             });
  175.            
  176.             if (shouldReapply) {
  177.                 setTimeout(forceDesktopView, 100);
  178.             }
  179.         });
  180.        
  181.         observer.observe(document.documentElement, {
  182.             childList: true,
  183.             subtree: true
  184.         });
  185.     }
  186.    
  187.     console.log('CFE Desktop View Forcer: Applied desktop view settings');
  188. })();
Advertisement
Add Comment
Please, Sign In to add comment