#114 back/forward arrows work with bypass preview

This commit is contained in:
dragonwocky 2020-09-25 17:44:55 +10:00
parent 5655043b36
commit 287e3551b5
3 changed files with 44 additions and 10 deletions

View File

@ -19,23 +19,48 @@ module.exports = {
if (document.readyState !== 'complete') return false;
const attempt_interval = setInterval(enhance, 500);
function enhance() {
const notion_elem = document.querySelector(
'.notion-default-overlay-container'
);
const notion_elem = document.querySelector('.notion-app-inner');
if (!notion_elem) return;
clearInterval(attempt_interval);
process();
const observer = new MutationObserver(process);
observer.observe(notion_elem, {
childList: true,
subtree: true,
});
let pageHistory = [];
process();
function process(list, observer) {
let preview = document.querySelector(
'.notion-peek-renderer [style*="height: 45px;"] a'
);
if (preview) preview.click();
const pageID = (location.search
.slice(1)
.split('&')
.map((opt) => opt.split('='))
.find((opt) => opt[0] === 'p') || [
'',
...location.pathname.split(/(-|\/)/g).reverse(),
])[1],
preview = document.querySelector(
'.notion-peek-renderer [style*="height: 45px;"] a'
);
if (
pageID &&
(!pageHistory[0] ||
pageHistory[0][0] !== pageID ||
pageHistory[0][1] !== !!preview)
) {
if (preview) {
if (
pageHistory[1] &&
pageHistory[0][0] === pageID &&
pageHistory[1][0] === pageID &&
pageHistory[1][1]
) {
document.querySelector('.notion-history-back-button').click();
} else preview.click();
}
// most recent is at start for easier access
pageHistory.unshift([pageID, !!preview]);
}
}
}
});

View File

@ -0,0 +1,9 @@
/*
* bypass preview
* (c) 2020 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* under the MIT license
*/
.notion-peek-renderer {
opacity: 0;
}

View File

@ -119,6 +119,7 @@ module.exports = {
''
)}`;
$page.previousElementSibling.children[0].appendChild($container);
if (!$container.offsetParent) return;
$container.offsetParent.appendChild($tooltip);
$container
.querySelectorAll('p')
@ -130,7 +131,6 @@ module.exports = {
$container.querySelectorAll('[data-tooltip]').forEach((el) => {
el.addEventListener('mouseenter', (e) => {
$tooltip.innerText = el.getAttribute('data-tooltip');
console.log(e.target);
$tooltip.style.top = el.parentElement.offsetTop + 2.5 + 'px';
$tooltip.style.left =
el.parentElement.offsetLeft +