自动展开

自动展开文档 隐藏部分

目前為 2022-01-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         自动展开
// @description  自动展开文档	隐藏部分
// @version      0.2
// @namespace    https://github.com/AirBashX/AutoUnfold/
// @author       airbash
// @match      	 *://*.jianshu.com/p/*
// @grant        none
// @license      GPL-3.0
// ==/UserScript==

(function () {
	/**
	 * 网站列表
	 * @type {name/url/操作类型}
	 */
	var websites = [
		{
			name: "简书",
			url: 'jianshu.com/p',
			handle: "click_item",
			type: "class",
			item: "ant-btn nP21pp"
		},
		{
			name: "百度经验",
			url: 'jingyan.baidu.com/article',
			handle: 'disaplay_item',
			type: "class",
			item: "read-whole-mask"
		}
	];

	var website = GetWebsite();
	var items = GetItemElement();
	if (website.handle == 'click_item') {
		//使用js的click():模拟点击'展开'命令;
		var interval = setInterval(() => {
			for (var item of items) {
				if (
					item != null &&
					item.getAttribute("opened") != "yes"
				) {
					item.click();
					item.setAttribute("opened", "yes");
				}
			}
		}, 100);
	} else {
		//使用css的display:none;隐藏遮挡部分
		for (var item of items) {
			item.style.display = "none";
		}
	}

	/**
	 * 校验当前网站是否匹配
	 * @return     {Website}  网站对象
	 */
	function GetWebsite() {
		for (var website of websites) {
			if (location.href.indexOf(website.url) != -1) {
				return website;
			}
		}
	}

	/**
	 * 根据选择器类型获取选择器
	 * @param      {object}  item    选择器
	 * @return     {Array}   falgs?元素数组:空数组
	 */
	function GetItemElement() {
		if (website.type == "class") {
			return document.getElementsByClassName(website.item);
		} else if (website.type == "id") {
			return [document.getElementById(website.item)];
		} else if (website.type == "tag") {
			return document.getElementsByTagName(website.item);
		}
		return [];
	}
})();