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.1
// @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,跳转到网址后面+/history
    var historyUrl = currentUrl + '/history';

    // 创建历史版本的新列表项,加上“历史版本”的html代码
    var listItem = document.createElement('li');
    listItem.className = 'current';
    listItem.innerHTML = '<a href="' + historyUrl + '" target="_blank">历史版本</a>';

    // 查找菜单容器并添加新列表项
    var menuContainer = document.querySelector('ul.menu-4.clearfix');
    menuContainer.appendChild(listItem);
  }
})();