Google Forms - Full Width Fix

Force la largeur à 100% de manière dynamique sur Google Forms

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Google Forms - Full Width Fix
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Force la largeur à 100% de manière dynamique sur Google Forms
// @author       Kyorai
// @match        https://docs.google.com/forms/*
// @grant        none
// @run-at       document-start
// @license MIT 
// ==/UserScript==

(function() {
    'use strict';

    function forceFullWidth() {
        // 1. On cible le formulaire principal (vue utilisateur)
        const form = document.querySelector('form[action*="formResponse"]');
        if (form && form.parentElement) {
            form.parentElement.style.setProperty('width', '100%', 'important');
            form.parentElement.style.setProperty('max-width', '100%', 'important');
        }

        // 2. On cible l'éditeur / vue des réponses (vue créateur - tes captures d'écran)
        // On cherche le conteneur principal qui a une largeur max définie par Google (généralement 770px ou 90vw)
        const containers = document.querySelectorAll('div[jsname]');
        containers.forEach(el => {
            const style = window.getComputedStyle(el);
            // Si l'élément a une largeur max ou une largeur fixe définie par Google, on la fait sauter
            if (style.width.includes('px') && parseInt(style.width) > 600 && parseInt(style.width) < 800) {
                 el.style.setProperty('width', '100%', 'important');
                 el.style.setProperty('max-width', '100%', 'important');
            }
        });

        // 3. Ciblage direct des conteneurs de structure majeurs de Google Forms
        const structuralDivs = document.querySelectorAll('div[role="main"], div[jsname="scpA6d"], div[jsname="le6uub"]');
        structuralDivs.forEach(div => {
            div.style.setProperty('width', '100%', 'important');
            div.style.setProperty('max-width', '100%', 'important');
            // On applique aussi aux enfants directs si nécessaire
            if (div.firstElementChild) {
                div.firstElementChild.style.setProperty('width', '100%', 'important');
                div.firstElementChild.style.setProperty('max-width', '100%', 'important');
            }
        });
    }

    // On lance une observation du DOM pour appliquer le style dès que les éléments s'affichent
    const observer = new MutationObserver((mutations) => {
        forceFullWidth();
    });

    // On commence à observer dès que le document est prêt
    document.addEventListener('DOMContentLoaded', () => {
        forceFullWidth();
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });

})();