Skip to content

Instantly share code, notes, and snippets.

@funway
Created October 2, 2022 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funway/bdb448af3df5e4ae7f2f773a9d8afb83 to your computer and use it in GitHub Desktop.
Save funway/bdb448af3df5e4ae7f2f773a9d8afb83 to your computer and use it in GitHub Desktop.
a tempermonkey's js script that redirect wiki mobile page to desktop version.
// ==UserScript==
// @name Redirect Wiki Mobile to Desktop UI
// @name:zh-CN 移动端维基重定向到桌面端
// @namespace https://hawu.me
// @version 0.1
// @description Redirect wiki mobile version to desktop version. Auto redirect or Offer a hyperlink on the top of mobile version page.
// @description:zh-CN 将维基百科的移动端页面重定向到桌面端(两种方式:自动重定向 或 在移动端页首增加桌面端的跳转链接)
// @author funway
// @match https://zh.m.wikipedia.org/*
// @icon https://zh.wikipedia.org/favicon.ico
// @grant none
// ==/UserScript==
(function() {
//'use strict';
// Your code here...
let url = window.location.href;
let desturl = url;
let header = "zh.wikipedia.org/";
let mobile_header = "zh.m.wikipedia.org/";
if(url.search(mobile_header) != -1) {
desturl = url.replace(mobile_header, header);
}
/********************************************/
// 方式一,直接跳转到桌面版
// window.location.replace(desturl);
/********************************************/
// 方式二,页首增加一个跳转链接
// 创建一个固定悬浮的 div 节点
var d = document.createElement("div");
d.style.position = "fixed";
d.style.top = "10px";
d.style.left = "150px";
d.style.zIndex = 99;
// 创建一个超链接节点
var a = document.createElement("a");
// 设置文本
a.innerText = ">> 桌面版 <<";
// 设置 href 属性
a.href = desturl;
// 将超链接节点附加到 body
d.append(a);
document.body.prepend(d);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment