私が先ほど別のユーザーさんにお答えしたものです。
そのまま引用してきました。
引用元: https://teratail.com/questions/140314#reply-215280
フォルダ構造
| | |
---|
root | manifest.json | |
| popup | popup.html |
| popup_common.js | |
| sender | sender.html |
| sender_common.js | |
※アルファベット順のため、順番が異なります。
manifest.json
json
1{
2 "manifest_version": 2,
3 "name": "XXXXXXXXXX",
4 "version": "0.0.0",
5 "description": "XXXXXXXXXX",
6 "browser_action": {
7 "default_title": "XXXXXXXXXX",
8 "default_popup": "popup/popup.html"
9 },
10 "permissions": [
11 "tabs",
12 "http://*.google.com/*",
13 "https://*.google.com/*"
14 ]
15}
popup/popup.html
html
1<!DOCTYPE html>
2<html lang="ja">
3<head>
4 <meta charset="UTF-8">
5 <title>XXXXXXXXXX</title>
6 <script src="./popup_common.js" async defer></script>
7</head>
8<body>
9 <form name="form" action="../sender/sender.html" method="get">
10 <input type="text" name="entry.0000000000" id="js_title" value="" placeholder="タイトル"><br>
11 <input type="text" name="entry.0000000000" id="js_url" value="" placeholder="URL"><br>
12 <textarea name="entry.0000000000" cols="30" rows="10" placeholder="コメント"></textarea>
13
14 <input type="submit" value="Submit">
15 </form>
16</body>
17</html>
popup/popup_common.js
javascript
1chrome.tabs.getSelected(null, function(tab){
2 document.getElementById("js_title").value = tab.title;
3 document.getElementById("js_url") .value = tab.url;
4});
sender/sender.html
html
1<!DOCTYPE html>
2<html lang="ja">
3<head>
4 <meta charset="UTF-8">
5 <title>XXXXXXXXXX</title>
6 <script src="./sender_common.js" async defer></script>
7</head>
8<body>
9 <iframe id="js_sendData" width="0" height="0" style="display: none;"></iframe>
10 <p id="status">送信しています...</p>
11</body>
12</html>
sender/sender_common.js
javascript
1(function(){
2 let query = location.search;
3 let url = "https://docs.google.com/forms/d/e/XXXXXXXXXXXXXXXXXXXX/formResponse";
4
5 let targetURL = url + query;
6
7 document.getElementById("js_sendData").src = targetURL;
8
9 document.getElementById("status").innerText = "送信が完了しました";
10})();
意味の分からないところがあればコメントください。