将手机版网页转换为PC版网页

将京东、B站、淘宝、天猫、微博、知乎、豆瓣手机版网页转换为PC版网页

  1. // ==UserScript==
  2. // @name 将手机版网页转换为PC版网页
  3. // @namespace none
  4. // @version 1.1
  5. // @description 将京东、B站、淘宝、天猫、微博、知乎、豆瓣手机版网页转换为PC版网页
  6. // @author owovo
  7. // @match *://item.m.jd.com/*
  8. // @match *://www.bilibili.com/mobile/video/*
  9. // @match *://detail.m.tmall.com/*
  10. // @match *://h5.m.taobao.com/*
  11. // @match *://shop.m.jd.com/*
  12. // @match *://m.weibo.cn/*
  13. // @match *://zhuanlan.zhihu.com/p/*
  14. // @match *://www.zhihu.com/question/*
  15. // @match *://m.douban.com/*
  16. // @grant none
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21.  
  22. // URL转换规则配置
  23. const urlRules = [
  24. {
  25. // 京东商品详情页
  26. regex: /^https?:\/\/item\.m\.jd\.com\/(?:product\/(\d+)|detail\/(\d+))\.html(?:[\?#].*)?$/,
  27. replace: (match, p1, p2) => `https://item.jd.com/${p1 || p2}.html`,
  28. description: "京东商品详情页转换(product/ 或 detail/ 路径)"
  29. },
  30. {
  31. regex: /^https?:\/\/item\.m\.jd\.com\/ware\/view\.action\?.*wareId=(\d+).*$/,
  32. replace: 'https://item.jd.com/$1.html',
  33. description: "京东商品详情页转换(wareId 参数)"
  34. },
  35. {
  36. // 京东店铺首页
  37. regex: /^https?:\/\/shop\.m\.jd\.com\/shop\/home\/(\w+)\.html$/,
  38. replace: 'https://shop.jd.com/home/popup/shopHome.html?id=$1',
  39. description: "京东店铺首页转换"
  40. },
  41. {
  42. // 哔哩哔哩
  43. regex: /^https?:\/\/www\.bilibili\.com\/mobile\/video\/(av\d+|bv\w+)\.html$/,
  44. replace: 'https://www.bilibili.com/video/$1/',
  45. description: "哔哩哔哩视频页转换(支持 av 号和 bv 号)"
  46. },
  47. {
  48. // 天猫
  49. regex: /^https?:\/\/detail\.m\.tmall\.com\/item\.htm\?(.*)$/,
  50. replace: (match, params) => {
  51. try {
  52. const id = new URLSearchParams(params).get('id');
  53. return id && `https://detail.tmall.com/item.htm?id=${id}`;
  54. } catch (error) {
  55. return null;
  56. }
  57. },
  58. description: "天猫商品详情页转换(使用 URLSearchParams 处理参数)"
  59. },
  60. {
  61. // 淘宝
  62. regex: /^https?:\/\/h5\.m\.taobao\.com\/awp\/core\/detail\.htm\?(.*)$/,
  63. replace: (match, params) => {
  64. try {
  65. const id = new URLSearchParams(params).get('id');
  66. return id && `https://item.taobao.com/item.htm?id=${id}`;
  67. } catch (error) {
  68. return null;
  69. }
  70. },
  71. description: "淘宝商品详情页转换(使用 URLSearchParams 处理参数)"
  72. },
  73. {
  74. // 新浪微博
  75. regex: /^https?:\/\/m\.weibo\.cn\/(.*)$/,
  76. replace: 'https://weibo.com/$1',
  77. description: "新浪微博转换"
  78. },
  79. {
  80. // 知乎(文章)
  81. regex: /^https?:\/\/zhuanlan\.zhihu\.com\/p\/(.*)$/,
  82. replace: 'https://zhuanlan.zhihu.com/p/$1',
  83. description: "知乎文章转换"
  84. },
  85. {
  86. // 知乎(问题)
  87. regex: /^https?:\/\/www\.zhihu\.com\/question\/(\d+)(\/.*)?$/,
  88. replace: (match, questionId, subPath) => {
  89. // 保留子路径(如 /answer/123456)
  90. return `https://www.zhihu.com/question/${questionId}${subPath || ''}`;
  91. },
  92. description: "知乎问题转换(保留子路径)"
  93. },
  94. {
  95. // 豆瓣
  96. regex: /^https?:\/\/m\.douban\.com\/(.*)$/,
  97. replace: 'https://www.douban.com/$1',
  98. description: "豆瓣转换"
  99. }
  100. ];
  101.  
  102. // 工具函数
  103. const utils = {
  104. isValidUrl: (url) => {
  105. try {
  106. new URL(url);
  107. return true;
  108. } catch (e) {
  109. return false;
  110. }
  111. },
  112.  
  113. safeReplaceUrl: (url, regex, replace) => {
  114. try {
  115. const newUrl = typeof replace === 'function'
  116. ? url.replace(regex, replace)
  117. : url.replace(regex, replace);
  118. return utils.isValidUrl(newUrl) ? newUrl : null;
  119. } catch (e) {
  120. return null;
  121. }
  122. }
  123. };
  124.  
  125. // 主逻辑
  126. try {
  127. const currentUrl = window.location.href;
  128.  
  129. const matchedRule = urlRules.find(rule => {
  130. const { regex, replace } = rule;
  131. const newUrl = utils.safeReplaceUrl(currentUrl, regex, replace);
  132.  
  133. if (newUrl && newUrl !== currentUrl) {
  134. window.location.replace(newUrl);
  135. return true;
  136. }
  137. return false;
  138. });
  139. } catch (e) {
  140. console.error('URL conversion failed');
  141. }
  142. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址