Lightweight Wikiwand

Link to Wikiwand page on Wikipedia (less intrusive than redirection).

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name Lightweight Wikiwand
// @namespace https://franklinyu.name
// @description Link to Wikiwand page on Wikipedia (less intrusive than redirection).
// @icon https://upload.wikimedia.org/wikipedia/commons/4/4e/WikiWand_Logo.png
// @author Franklin Yu
// @match https://*.wikipedia.org/*
// @match https://*.wikipedia.org/w/index.php?*
// @grant none
// @version 0.0.1.20180529040752
// ==/UserScript==

const lang = location.host.split('.')[0];

let title, lang_var;
if (location.pathname === '/w/index.php') {
	title = new URLSearchParams(location.search).get('title');
	lang_var = null;
} else {
	const path_segments = location.pathname.split('/');
	title = path_segments.slice(2).join('/');
	if (path_segments[1] === 'wiki')
		lang_var = null;
	else
		lang_var = path_segments[1];
}

const anchor = document.createElement('a');
anchor.href = `https://www.wikiwand.com/${lang_var || lang}/${title}`;
const image = document.createElement('img');
image.src = 'https://upload.wikimedia.org/wikipedia/commons/4/4e/WikiWand_Logo.png';
image.id = 'wikiwand-image';
anchor.appendChild(image);
document.getElementById('firstHeading').prepend(anchor);

const style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode('#wikiwand-image { width: 2em; }'));
document.head.appendChild(style);