Home>
How to drop a form Question content

Is it possible to get page information on the extension without using GAS → input comments → send?
If this is not possible, how can this system be created?

There is no source because there is only a base, but if you have any advice or articles that may be helpful, please give me a professor.

  • Answer # 1

    I tried to make corrections as easy as possible.
    It was awkward to write css, so the style is insanely rough and sorry I'm sorry orz
    Some are inline, so
    I hope you can rewrite it well

    Folder structure
    root manifest.json
    popup popup.html
    popup_common.js
    sender sender.html
    sender_common.js

    * Because of alphabetical order, the order is different.

    manifest.json
    {
        "manifest_version": 2,
        "name": "XXXXXXXXXX",
        "version": "0.0.0",
        "description": "XXXXXXXXXX",
        "browser_action": {
            "default_title": "XXXXXXXXXX",
            "default_popup": "popup/popup.html"
        },
        "permissions": [
            "tabs",
            "http: //*.google.com/*",
            "https: //*.google.com/*"
        ]
    }
    popup/popup.html
    <! DOCTYPE html>
    <html lang = "en">
    <head>
        <meta charset = "UTF-8">
        <title>XXXXXXXXXX</title>
        <script src = "./ popup_common.js" async defer></script>
    </head>
    <body>
        <form name = "form" action = "../ sender/sender.html" method = "get">
            <input type = "text" name = "entry.0000000000" id = "js_title" value = "" placeholder = "title"><br>
            <input type = "text" name = "entry.0000000000" id = "js_url" value = "" placeholder = "URL"><br>
            <textarea name = "entry.0000000000" cols = "30" rows = "10" placeholder = "comment"></textarea>
            <input type = "submit" value = "Submit">
        </form>
    </body>
    </html>
    popup/popup_common.js
    chrome.tabs.getSelected (null, function (tab) {
        document.getElementById ("js_title"). value = tab.title;
        document.getElementById ("js_url") .value = tab.url;
    });
    sender/sender.html
    <! DOCTYPE html>
    <html lang = "en">
    <head>
        <meta charset = "UTF-8">
        <title>XXXXXXXXXX</title>
        <script src = "./ sender_common.js" async defer></script>
    </head>
    <body>
        <iframe id = "js_sendData" width = "0" height = "0"&​​gt;</iframe>
        <p id = "status">Sending ...</p>
    </body>
    </html>
    sender/sender_common.js
    (function () {
        let query = location.search;
        let url = "https://docs.google.com/forms/d/e/XXXXXXXXXXXXXXXXXXXX/formResponse";
        let targetURL = url + query;
        document.getElementById ("js_sendData"). src = targetURL;
        document.getElementById ("status"). innerText = "Sending completed";
    }) ();

    Please comment if you do not understand the meaning.

  • Answer # 2

    Folder structure

    root manifest.json
    background.js
    popupWindow index.html
    common.js
    style.css

    * Because of alphabetical order, the order is different.

    manifest.json
    {
        "manifest_version": 2,
        "name": "AAAAAAAAAA",
        "version": "0.0.0",
        "description": "AAAAAAAAAA",
        "background": {
            "scripts": ["background.js"],
            "persistent": false
        },
        "browser_action": {
            "default_title": "AAAAAAAAAA"
        },
        "permissions": [
            "tabs",
            "http: //*.google.com/*",
            "https: //*.google.com/*"
        ]
    }
    background.js
    chrome.browserAction.onClicked.addListener ((tab) =>{
        chrome.runtime.sendMessage ({
            message: "popupWindow_closeWindow"
        });
        const w = 520;
        const h = 700;
        const s_w = window.parent.screen.width;
        const s_h = window.parent.screen.height;
        window.open ("./ popupWindow/index.html", "_blank", `width = ${w}, height = ${h}, left = ${(s_w-w)/2}, top = ${ (s_h-h)/2} `);
    });
    popupWindow/index.html
    <! DOCTYPE html>
    <html lang = "en">
    <head>
        <meta charset = "UTF-8">
        <title>Google Form</title>
        <link rel = "stylesheet" href = "style.css">
        <script src = "common.js" async defer></script>
    </head>
    <body>
        <iframe frameborder = "0" id = "js__iframeForm"></iframe>
    </body>
    </html>
    popupWindow/common.js
    const getQueryString = function getQueryString (obj) {
        let result = "";
        for (let key in obj) {
            result + = `&${encodeURIComponent (key)} = ${encodeURIComponent (obj [key])}`;
        }
        return `? ${result.slice (1)}`;
    }
    chrome.runtime.onMessage.addListener (async (request, sender, sendResponse) =>{
        if (request.message === "popupWindow_closeWindow") {
            window.close ();
        }
    });
    chrome.tabs.query ({
        active: true
    }, (arr_tab) =>{
        console.log (arr_tab);
        let title = arr_tab [0] .title;
        let url = arr_tab [0] .url;
        const iframe = document.getElementById ("js__iframeForm");
        iframe.src = `https://docs.google.com/forms/d/e/0123456789abcdef/viewform${getQueryString ({
            "entry.000000000": title,
            "entry.000000000": url
        })} `;
    });
    popupWindow/style.css
    html,
    body {
        border: 0;
        height: 100%;
        margin: 0;
        padding: 0;
        width: 100%;
    }
    iframe {
        border: 0;
        height: calc (100%-3px);
        margin: 0;
        width: 100%;
    }