-
Notifications
You must be signed in to change notification settings - Fork 0
/
weibo-mobile-redirect.user.js
102 lines (96 loc) · 3.69 KB
/
weibo-mobile-redirect.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// ==UserScript==
// @name Weibo Mobile Redirect
// @name:zh-cn 新浪微博移动版跳转
// @namespace https://github.com/Vinfall/UserScripts
// @version 1.3.0
// @author Vinfall
// @match https://video.weibo.com/show?fid=*
// @match https://weibo.com/*/*
// @match https://weibo.com/ttarticle/p/show?id=*
// @match https://weibo.com/u/*
// @match https://www.weibo.com/detail/*
// @exclude-match https://card.weibo.com/article/*
// @exclude-match https://m.weibo.cn/detail/*
// @exclude-match https://m.weibo.cn/status/*
// @exclude-match https://m.weibo.cn/u/*
// @exclude-match https://passport.weibo.com/*
// @exclude-match https://weibo.com/signup/*
// @exclude-match https://weibo.com/tv/show/*
// @grant none
// @run-at document-start
// @license CC0 1.0 Universal (Public Domain)
// @icon https://m.weibo.cn/favicon.ico
// @description Auto redirect Weibo to mobile version
// @description:zh-cn 新浪微博自动跳转移动版,支持微博、文章、视频
// ==/UserScript==
(function () {
'use strict';
const currentUrl = window.location.href;
// Defend in depth
if (currentUrl.includes('card.weibo.com') || currentUrl.includes('m.weibo.cn')) {
return;
}
// TODO: fix redirect to passport.weibo.com when nojs is OFF
// function delayedRedirect(url, delay = 500) {
// setTimeout(() => {
// window.location.replace(url);
// }, delay);
// }
const cases = [
// weibo.com/u/*
{
pattern: /^https:\/\/weibo\.com\/u\/(\d+)/,
handle: (match) => {
const userId = match[1];
const userMobileUrl = `https://m.weibo.cn/u/${userId}`;
window.location.replace(userMobileUrl);
},
},
// weibo.com/ttarticle/p/show?id=*
{
pattern: /^https:\/\/weibo\.com\/ttarticle\/p\/show\?id=(\d+)/,
handle: (match) => {
const articleId = match[1];
const articleMobileUrl = `https://card.weibo.com/article/h5/s#cid=${articleId}`;
window.location.replace(articleMobileUrl);
},
},
// weibo.com/1234567890/1234567890123456
// used to be weibo.com/detail/*
{
pattern: /^https:\/\/weibo\.com\/\d{10}\/(\d{16})/,
handle: (match) => {
const detailId = match[1];
const detailMobileUrl = `https://m.weibo.cn/detail/${detailId}`;
window.location.replace(detailMobileUrl);
},
},
// weibo.com/1234567890/abcdEFG89
{
pattern: /^https:\/\/weibo\.com\/\d{10}\/(\w{9})/,
handle: (match) => {
const statusId = match[1];
const statusMobileUrl = `https://m.weibo.cn/status/${statusId}`;
window.location.replace(statusMobileUrl);
// delayedRedirect(statusMobileUrl);
},
},
// video.weibo.com/show?fid=1234:1234567890123456
// always auto redirect, added just in case
{
pattern: /^https:\/\/video\.weibo\.com\/show\?fid=(\d{4}:\d+)/,
handle: (match) => {
const fid = match[1];
const videoUrl = `https://weibo.com/tv/show/${fid}`;
window.location.replace(videoUrl);
},
},
];
for (const caseItem of cases) {
const match = currentUrl.match(caseItem.pattern);
if (match) {
caseItem.handle(match);
return;
}
}
})();