✨ 讓 Google 幫您免費架設 `https://` 手機網頁+雲端同步資料庫(手機在外面 4G/5G 也能直接點開連結!):
- 打開 Google 試算表 (sheets.new),點選頂部選單「擴充功能」→「Apps Script」。
- 在左側「檔案」的
程式碼.gs 中,清空原本內容,點擊下方按鈕複製「步驟 1:伺服器程式碼」貼上:
function doGet(e) {
if (e && e.parameter && e.parameter.action === 'sync') {
var room = e.parameter.room || 'my-home-2026';
var data = PropertiesService.getScriptProperties().getProperty('ROOM_' + room) || '{}';
return ContentService.createTextOutput(data).setMimeType(ContentService.MimeType.JSON);
}
return HtmlService.createHtmlOutputFromFile('index')
.setTitle('日常消耗品智慧管家')
.addMetaTag('viewport', 'width=device-width, initial-scale=1')
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
function doPost(e) {
var body = JSON.parse(e.postData.contents);
var room = body.room || 'my-home-2026';
PropertiesService.getScriptProperties().setProperty('ROOM_' + room, JSON.stringify(body.payload));
return ContentService.createTextOutput(JSON.stringify({ok:true})).setMimeType(ContentService.MimeType.JSON);
}
function gasPullRoom(room) {
return PropertiesService.getScriptProperties().getProperty('ROOM_' + (room || 'my-home-2026')) || '{}';
}
function gasPushRoom(room, payloadJson) {
PropertiesService.getScriptProperties().setProperty('ROOM_' + (room || 'my-home-2026'), payloadJson);
return true;
}
- 在 Apps Script 左側「檔案」旁點擊 「+」→ 選擇「HTML」,檔案名稱請輸入
index(小寫)。
- 清空
index.html 裡面的內容,點擊下方按鈕「📋 一鍵複製完整網頁 HTML 碼」並貼進 Apps Script 的 index.html 中:
- 點右上角「部署」→「新增部署作業」(若已部署過請選「管理部署作業」→ 編輯 → 版本選「新版本」),誰可以存取選「所有人 (Anyone)」。
- 部署完成後產生的
https://script.google.com/macros/s/.../exec 就是真正的有效網站連結!貼回上方欄位儲存後,手機直接點該連結就能打開網頁並與電腦同步!