Notion Fix

Fix bugs in Notion

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Notion Fix
// @namespace    https://github.com/alanleungcn/notion-fix
// @version      1.3
// @author       Alan Leung
// @description  Fix bugs in Notion
// @match        https://www.notion.so/*
// @license      MIT
// ==/UserScript==

(function () {
	'use strict';

	let preView = null;
	let curView = null;
	const checkInterval = 100;
	const viewList = [
		'table',
		'board',
		'timeline',
		'calendar',
		'gallery',
		'list',
	];

	const init = setInterval(() => {
		queryView();
		if (curView) {
			clearInterval(init);
			applyFix();
			fixFirefoxScrollbarWidth();
		}
	}, checkInterval);

	window.addEventListener('click', () => {
		applyFix();
	});

	// function fixTimelineDividerPosition() {
	// 	document.querySelector('.pseudoSelection').style.position = '';
	// }

	function fixScrollbarPosition() {
		document.querySelector(
			'.notion-scroller.vertical.horizontal'
		).scrollLeft = 0;
	}

	function fixFirefoxScrollbarWidth() {
		const style = document.createElement('style');
		style.textContent = `.notion-scroller { scrollbar-width: thin }`;
		document.head.append(style);
	}

	function queryView() {
		viewList.forEach((view, i) => {
			if (document.querySelector(`.notion-${view}-view`)) {
				curView = viewList[i];
			}
		});
	}

	function applyFix() {
		requestAnimationFrame(() => {
			queryView();
			// if (curView === 'timeline') {
			// 	fixTimelineDividerPosition();
			// }
			if (curView !== preView && preView === 'timeline') {
				fixScrollbarPosition();
			}
			preView = curView;
		});
	}
})();