Notion Fix

Fix bugs in Notion

Tính đến 11-08-2021. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Notion Fix
// @namespace    https://github.com/alanleungcn/notion-fix
// @version      1.0
// @author       Alan Leung
// @description  Fix bugs in Notion
// @match        https://www.notion.so/*
// ==/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();
		}
	}, checkInterval);

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

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

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

	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;
		});
	}
})();