Greasy Fork

Greasy Fork is available in English.

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

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

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

// ==UserScript==
// @name         增加豌豆荚网页版中APP的历史版本下载按钮和相关历史版本app跳转到下载页
// @namespace    https://github.com/eaeful/
// @version      0.6
// @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==

//0.6版本:历史版本的跳转位置没变,还是在"评论"、"热门文章"旁边,app的历史版本也不需要跳转到/mip了,会在默认的网址中的"最新版本下载"按钮旁额外有一个"直接下载当前版本号的APK"的按钮,这个就是一键下载当前版本号的APK的按钮。

(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 apkLink = document.querySelector('.qr-info a').href;
    
    var downloadBtn = document.createElement('a');
    downloadBtn.target = '_blank';
    downloadBtn.href = apkLink;
    downloadBtn.className = 'v2-safe-btn';
    downloadBtn.style.background = '#0080ff';
    downloadBtn.innerHTML = '直接下载当前版本号的APK';

    
    var buttonWrap = document.querySelector('.download-v2-wrap .button-wrap');
    buttonWrap.appendChild(downloadBtn);


  } else if (match2) {

    let apkLink = document.querySelector('.qr-info a').href;

    let downloadBtn = document.createElement('a');
    downloadBtn.target = '_blank';
    downloadBtn.href = apkLink;
    downloadBtn.className = 'v2-safe-btn';
    downloadBtn.style.background = '#0080ff';
    downloadBtn.innerHTML = '直接下载当前版本号的APK';

    
    let buttonWrap = document.querySelector('.download-v2-wrap.m .button-wrap');
    buttonWrap.appendChild(downloadBtn);

  } 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);
      }
    }
  }
})();