Scroll to Trello list

Automatically scroll to the specified Trello-board list

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          Scroll to Trello list
// @description   Automatically scroll to the specified Trello-board list
// @author        Vassyutovich Ilya (https://github.com/VassyutovichIlya)
// @homepageURL   https://github.com/VassyutovichIlya/user-scripts
// @license       MIT
// @version       0.1.0
// @grant         none
// @include       https://trello.com/*
// @namespace https://greasyfork.org/users/629857
// ==/UserScript==

const listNameParameterName = "scrollToList";
const scriptExecutionTimeoutSeconds = 10;

const uriParams = new URLSearchParams(window.location.search);
const listName = uriParams.get(listNameParameterName);

if (listName == null) {
	return;
}

let executionTimedOut = false;
const executionTimeoutTimer = setTimeout(
	() => executionTimedOut = true,
	scriptExecutionTimeoutSeconds * 1000
);

const mutator = async (_, observer) => {
	if (executionTimedOut) {
		clearTimeout(executionTimeoutTimer);
		observer.disconnect();
		return;
	}

	const trelloRootElement = document.getElementById("trello-root");
	if (trelloRootElement == null) {
		return;
	}

	const trelloContentElement = document.getElementById("content");
	if (trelloContentElement == null) {
		return;
	}

	const trelloBoardElement = document.getElementById("board");
	if (trelloBoardElement == null) {
		return;
	}

	const listsTextAreas = Array.from(
		document
			.querySelectorAll("div .list-header textarea"));
	const foundList = listsTextAreas.find(textArea => textArea.value === listName);
	if (foundList === undefined) {
		return;
	}

	observer.disconnect();

	const scrollOptions = { "inline": "center" };
	foundList.scrollIntoView(scrollOptions);
}

const mutationObserver = new MutationObserver(mutator);
mutationObserver.observe(document, { childList: true, subtree: true });