雲端工具入門
雲端工具自動化設計
- GAS產生器
 - 公司自動流程設計、詢問
 - 專案設計、教學
 - mail: tawan158@gmail.com
 
Google Forms URL 轉換器
輸入 Google Forms viewform URL: 轉換
結果:
body {
  font-family: Arial, sans-serif;
  text-align: center;
  padding: 20px;
  }
  #form-container,
  #result-container {
    max-width: 98%;
    margin: 0 auto;
    padding: 20px;
    border: 1px solid #ccc;
    border-radius: 5px;
  }
  input[type="text"] {
    width: 100%;
    padding: 12px 20px;
    margin: 8px 0;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
  }
  button {
    background-color: #4CAF50;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
  }
  button:hover {
    background-color: #45a049;
  }
  // 函數定義
  function convertGoogleFormURL(url) {
    // 使用 URL 構造函數解析原始 URL
    const parsedUrl = new URL(url);
    // 替換路徑中的 viewform 為 formResponse
    parsedUrl.pathname = parsedUrl.pathname.replace("/viewform", "/formResponse");
    // 添加 submit=Submit 參數
    parsedUrl.searchParams.append("submit", "Submit");
    // 刪除 usp=pp_url 參數
    parsedUrl.searchParams.delete("usp");
    // 返回替換後的 URL 字符串
    return parsedUrl.toString();
  }
  // 獲取 DOM 元素
  const formContainer = document.getElementById('form-container');
  const resultContainer = document.getElementById('result-container');
  const urlForm = document.getElementById('url-form');
  const urlInput = document.getElementById('url-input');
  const resultElement = document.getElementById('result');
  const openBtn = document.getElementById('open-btn');
  const backBtn = document.getElementById('back-btn');
  // 表單提交事件
  urlForm.addEventListener('submit', (event) => {
    event.preventDefault();
    const originalURL = urlInput.value.trim();
    if (originalURL) {
      const convertedURL = convertGoogleFormURL(originalURL);
      resultElement.textContent = convertedURL;
      formContainer.style.display = 'none';
      resultContainer.style.display = 'block';
    }
  });
  // 在新視窗中打開按鈕事件
  openBtn.addEventListener('click', () => {
    const convertedURL = resultElement.textContent;
    window.open(convertedURL, '_blank');
  });
  // 返回表單按鈕事件
  backBtn.addEventListener('click', () => {
    formContainer.style.display = 'block';
    resultContainer.style.display = 'none';
    urlInput.value = '';
  });
	在新視窗中打開返回表單