back/forward arrows work with bypass preview

This commit is contained in:
dragonwocky 2020-09-25 17:44:55 +10:00
parent a31a93e206
commit 21b3802e08
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D
5 changed files with 53 additions and 10 deletions

View File

@ -11,6 +11,8 @@
- bugfix: font chooser will continue iterating through fonts after encountering a blank option.
- bugfix: block indents are no longer overriden.
- bugfix: neutral does not force full width pages.
- bugfix: bypass preview extension works with the back/forward arrows.
### v0.9.0 (2020-09-20)

View File

@ -30,6 +30,7 @@ download:
```sh
git clone https://github.com/dragonwocky/notion-enhancer
cd notion-enhancer
git checkout dev
npm link
```
@ -52,6 +53,12 @@ to keep a consistent informative code style it is preferred to name variables wi
`snake_case`, functions/methods with `camelCase`, and classes with `PascalCase`.
if a variable is a reference to a DOM element, it may be helpful to prefix it with a `$`.
some variables beginning with a double underscore are `__folder` paths and `ALL_CAPS` variables
are constant. this is not required, but these styles should not be used for any other purpose.
the master branch is kept consistent with the current release,
so all changes should be made to the dev branch.
## review
active core devs will manually look through each pull request and communicate with contributors before merging to

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 +