Greasy Fork

Greasy Fork is available in English.

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

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

目前为 2023-06-19 提交的版本,查看 最新版本

// ==UserScript==
// @name         增加豌豆荚网页版中APP的历史版本下载按钮和相关历史版本app跳转到下载页
// @namespace    https://github.com/eaeful/
// @version      0.5
// @description  增加豌豆荚网页版中APP的历史版本下载按钮和相关历史版本app跳转到正常的下载页
// @match        https://www.wandoujia.com/apps/*/history_v*
// @match        https://www.wandoujia.com/apps/*
// @match        https://m.wandoujia.com/apps/*/history_v*
// @match        https://m.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:\/\/m\.wandoujia\.com\/apps\/(\d+)\/history_v(\d+)/;
  var match2 = currentUrl.match(pattern2);

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

    // 构建新的跳转URL
    var newUrl = "https://www.wandoujia.com/mip/apps/" + appId + "/history_v" + version;

    // 跳转到新的URL
    window.location.href = newUrl;
  } else if (match2) {
    let appId = match2[1];
    let version = match2[2];

    // 构建新的跳转URL
    let newUrl = "https://m.wandoujia.com/mip/apps/" + appId + "/history_v" + version;

    // 跳转到新的URL
    window.location.href = newUrl;
  } else {
    var pattern3 = /https:\/\/www\.wandoujia\.com\/apps\/(\d+)/;
    var match3 = currentUrl.match(pattern3);

    var pattern4 = /https:\/\/m\.wandoujia\.com\/apps\/(\d+)/;
    var match4 = currentUrl.match(pattern4);

    if (match3) {

      // 构建历史版本的新URL,只保留 apps 后面的数字,并在基本 URL 后添加 /history
      let appId = currentUrl.match(/apps\/(\d+)/)[1];
      var historyUrl = currentUrl.replace('/apps/' + appId, '/apps/' + appId + '/history');

      // 创建历史版本的链接元素
      var historyLink = document.createElement('a');
      historyLink.href = historyUrl;
      historyLink.target = '_blank';
      historyLink.innerText = '历史版本';

      // 查找适合的插入位置
      var detailMenu = document.querySelector('div.detail-menu ul');
      var insertPosition = detailMenu || null;

      // 在插入位置添加历史版本链接,在简介、评论、热门文章右边添加“历史版本”的绿色文字按钮
      if (insertPosition) {
        var listItem = document.createElement('li');
        listItem.className = 'current';
        listItem.appendChild(historyLink);
        insertPosition.appendChild(listItem);
      }
    } else if (match4) {

      // 构建历史版本的新URL,只保留 apps 后面的数字,并在基本 URL 后添加 /history
        let appId = currentUrl.match(/apps\/(\d+)/)[1];
        let historyUrl = currentUrl.replace('/apps/' + appId, '/apps/' + appId + '/history');

      // 创建历史版本的链接元素
      let historyLink = document.createElement('a');
      historyLink.href = historyUrl;
      historyLink.target = '_blank';
      historyLink.innerText = '历史版本';

      // 查找适合的插入位置
      let detailMenu = document.querySelector('div.detail-menu ul');
      let insertPosition = detailMenu || null;

      // 在插入位置添加历史版本链接,在简介、评论、热门文章右边添加“历史版本”的绿色文字按钮
      if (insertPosition) {
        let listItem = document.createElement('li');
        listItem.className = 'current';
        listItem.appendChild(historyLink);
        insertPosition.appendChild(listItem);
      }
    }
  }
})();