<!DOCTYPE html>
<html>
<head>
  <title>匹配百度网盘链接并添加提取码</title>
</head>
<body>
  <h1>匹配百度网盘链接并添加提取码</h1>
  
  <p>粘贴百度云分享链接:</p>
  <input type="text" id="urlInput">
  <button onclick="addPassword()">添加提取码</button>

  <script>
    // 添加提取码的函数
    function addPassword() {
      var urlInput = document.getElementById("urlInput");
      var url = urlInput.value;

      // 匹配百度网盘链接的正则表达式
      var pattern = /(https?:\/\/pan\.baidu\.com\/s\/[a-zA-Z0-9-_]+)\s*提取码[::]?(\w+)/;

      // 检查链接是否匹配
      if (pattern.test(url)) {
        // 获取匹配结果中的链接和提取码
        var matches = url.match(pattern);
        var resultUrl = matches[1] + "?pwd=" + matches[2];

        // 打开结果链接
        window.open(resultUrl, "_blank");
      } else {
        alert("无效的百度网盘链接或提取码");
      }
    }
  </script>
</body>
</html>