Greasy Fork

Greasy Fork is available in English.

增加豌豆荚网页版中APP的历史版本下载按钮和相关历史版本app跳转到下载页

增加豌豆荚网页版中APP的历史版本下载按钮和相关历史版本app跳转到正常的下载页

当前为 2023-06-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         增加豌豆荚网页版中APP的历史版本下载按钮和相关历史版本app跳转到下载页
// @namespace    https://github.com/eaeful/
// @version      0.2
// @description  增加豌豆荚网页版中APP的历史版本下载按钮和相关历史版本app跳转到正常的下载页
// @match        https://www.wandoujia.com/apps/*/history_v*
// @match        https://www.wandoujia.com/apps/*
// @grant        none
// @license      MIT License
// @run-at       document-end
// ==/UserScript==

(function() {
  var currentUrl = window.location.href;

  // 定义匹配第一条件的模式
  var pattern1 = /https:\/\/www.wandoujia.com\/apps\/(\d+)\/history_v(\d+)/;
  var match1 = currentUrl.match(pattern1);

  // 定义匹配第二条件的模式
  var pattern2 = /https:\/\/www.wandoujia.com\/apps\/(\d+)/;
  var match2 = currentUrl.match(pattern2);

  if (match1) {
    var appId = match1[1];
    var versionCode = match1[2];

    // 构建带有/mip/前缀的新URL
    var newUrl = 'https://www.wandoujia.com/mip/apps/' + appId + '/history_v' + versionCode;

    // 重定向到新URL
    window.location.href = newUrl;
  } else if (match2) {
    let appId = match2[1];

    // 构建历史版本的新URL
    var historyUrl = currentUrl + '/history';

    // 创建历史版本的链接元素,<a class="download install-btn" href="https://www.wandoujia.com/apps/xxxxx/" target="_blank">历史版本</a>
    var historyLink = document.createElement('a');
    historyLink.className = 'download install-btn';
    historyLink.href = historyUrl;
    historyLink.target = '_blank';
    historyLink.innerText = '历史版本';

    // 找到所有的下载容器并添加历史版本链接
    var downloadContainers = document.querySelectorAll('div.download-wp');
    for (var i = 0; i < downloadContainers.length; i++) {
      downloadContainers[i].appendChild(historyLink.cloneNode(true));
    }
  }
})();