Notion Fix

Fix bugs in Notion

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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;
		});
	}
})();