Greasy Fork

Greasy Fork is available in English.

洛谷个人主页个性化

可用一套语言拓展洛谷主页文字,图片的局限性 包括iframe和video等等功能

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         洛谷个人主页个性化
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  可用一套语言拓展洛谷主页文字,图片的局限性 包括iframe和video等等功能
// @author       Haraki
// @match        https://www.luogu.com.cn/user/*
// @grant        none
// ==/UserScript==


function doit() {
	var a = document.querySelectorAll(".introduction p,h1,h2,h3,h4,h5,h6");
	var s, plc, fml;
	for (var i = 0; i < a.length; i++) {
		if (a[i].innerText.substr(0, 7) == "%align%") {
			a[i].innerText = a[i].innerText.substring(7, a[i].innerText.length);
			s = a[i].getAttribute("style");
			if (s == null) s = "";
			a[i].setAttribute("style", s + "text-align:center;");
		}
		if (a[i].innerText.substr(0, 6) == "%color") {
			var col = a[i].innerText.substr(6, 8);
			a[i].innerText = a[i].innerText.substring(15, a[i].innerText.length);
			s = a[i].getAttribute("style");
			if (s == null) s = "";
			a[i].setAttribute("style", s + "color" + col + ";");
		}
		if (a[i].innerText.substr(0, 12) == "%font-family") {
			plc = a[i].innerText.indexOf('%', 1);
			fml = a[i].innerText.substr(12, plc - 12);
			a[i].innerText = a[i].innerText.substring(plc + 1, a[i].innerText.length);
			s = a[i].getAttribute("style");
			if (s == null) s = "";
			a[i].setAttribute("style", s + "font-family" + fml + ";");
		}
		if (a[i].innerText.substr(0, 10) == "%font-size") {
			plc = a[i].innerText.indexOf('%', 1);
			fml = a[i].innerText.substr(10, plc - 10);
			a[i].innerText = a[i].innerText.substring(plc + 1, a[i].innerText.length);
			s = a[i].getAttribute("style");
			if (s == null) s = "";
			a[i].setAttribute("style", s + "font-size" + fml + ";");
		}
		if (a[i].innerText.substr(0, 6) == "%video") {
			plc = a[i].innerText.indexOf('%', 1);
			fml = a[i].innerText.substr(7, plc - 7);
			a[i].innerText = "";
			var vdo = document.createElement("video");
			vdo.setAttribute("src", fml);
			vdo.setAttribute("controls", "controls");
			vdo.setAttribute("style", "width:100%;height:auto;");
			vdo.innerText = "您的浏览器不支持 video 标签。";
			document.querySelector(".introduction").insertBefore(vdo, a[i].nextSibling);

		}
		if (a[i].innerText.substr(0, 7) == "%iframe") {
			plc = a[i].innerText.indexOf('%', 1);
			fml = a[i].innerText.substr(8, plc - 8);
			a[i].innerText = "";
			var ifr = document.createElement("iframe");
			ifr.setAttribute("src", fml);
			ifr.setAttribute("width", "100%");
			ifr.setAttribute("height", "500px");
			ifr.setAttribute("seamless", "");
			ifr.innerText = "您的浏览器不支持 iframe 标签。";
			document.querySelector(".introduction").insertBefore(ifr, a[i].nextSibling);

		}

	}
}
(function() {
	'use strict';
	var k = window.setInterval(doit, 500);
})();