Greasy Fork

Greasy Fork is available in English.

userscripts 只显示中文

在userscripts.org Script页面只显示中文脚本,可与autopage 配合使用

当前为 2014-04-06 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @id             userscripts@[email protected]
// @name           userscripts 只显示中文
// @version        1.2.1
// @author         [email protected]
// @description    在userscripts.org Script页面只显示中文脚本,可与autopage 配合使用
// @include        /https?://userscripts.org/scripts$/
// 注: UserScriptLoader.uc.js 可能不支持正则
// @include        http*://userscripts.org/scripts?page=*
// @include        http*://userscripts.org/scripts/search?q=*
// @run-at         document-end
// @namespace http://greasyfork.icu/users/145
// ==/UserScript==

(function(){

var hided = false,
	contentDiv = document.getElementById('content'),
	contentHeight;

// 隐藏其它,只显示中文
function hideOthers(){
	var scripts = document.querySelectorAll(".script-meat"),
		script,
		parent;
	for (var i = scripts.length - 1; i >= 0; i--) {
		script = scripts[i];
		parent = script.parentElement;
		if(parent.className.indexOf('mhide') > -1){ 
			continue;
		}
		if(!/[\u4E00-\u9FA5]/.test(script.querySelector('a').textContent + script.querySelector('p.desc').textContent)){ 
			parent.className += ' mhide'; 
		}
	}

	hided = true;
}

function showAll () {
	var trs = document.querySelectorAll(".mhide");
	for (var i = trs.length - 1; i >= 0; i--) {
		trs[i].className = trs[i].className.replace(/(\s+|)mhide(\s+|)/g, '');
	}

	hided = false;
}

function addButton(){
	var button = document.createElement('button');
	button.type = "button";
	button.innerHTML = "只显示中文";
	button.onclick = function(){
		if(hided){
			showAll();
			button.innerHTML = "只显示中文";
			contentHeight = contentDiv.scrollHeight;
		}else{
			hideOthers();
			button.innerHTML = "显示全部";
			contentHeight = contentDiv.scrollHeight;
		}
	};

	var parent = document.querySelector("th.la");
	parent.appendChild(button);
}

function fixAutoPage(){
	var firstTime = true;
	document.onscroll = function(){
		if(firstTime){
			contentHeight = contentDiv.scrollHeight;
			firstTime = false;
		}
		// console.log(contentDiv.scrollHeight, contentHeight);
		if(contentDiv.scrollHeight > contentHeight){
			// console.log("add");
			if(hided){
				hideOthers();
			}else{
				showAll();
			}
		}
	};
}

GM_addStyle(".mhide {display:none !important}");
addButton();
fixAutoPage();

})();