mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-06 21:49:03 +00:00
bypass-preview
This commit is contained in:
parent
f6d8f222a6
commit
4e3f921ee3
@ -87,7 +87,6 @@ storage.set = (namespace, key, value) => {
|
||||
storage._onChangeListeners.forEach((listener) =>
|
||||
listener({ type: 'set', namespace, key, new: value, old: values[key] })
|
||||
);
|
||||
console.log(namespace, key, value, { ...values, [key]: value });
|
||||
chrome.storage.sync.set({ [namespace]: { ...values, [key]: value } }, res);
|
||||
});
|
||||
storage._queue.push(interaction);
|
||||
@ -271,6 +270,39 @@ web.hotkeyListener = (keys, callback) => {
|
||||
}
|
||||
web._hotkeys.push({ keys, callback });
|
||||
};
|
||||
web.observeDocument = (callback, selectors = []) => {
|
||||
if (!web._documentObserver) {
|
||||
web._documentObserverListeners = [];
|
||||
web._documentObserverEvents = [];
|
||||
const handle = (queue) => {
|
||||
while (queue.length) {
|
||||
const event = queue.shift();
|
||||
for (const listener of web._documentObserverListeners) {
|
||||
if (
|
||||
!listener.selectors.length ||
|
||||
listener.selectors.some(
|
||||
(selector) =>
|
||||
event.target.matches(selector) || event.target.matches(`${selector} *`)
|
||||
)
|
||||
) {
|
||||
listener.callback(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
web._documentObserver = new MutationObserver((list, observer) => {
|
||||
if (!web._documentObserverEvents.length)
|
||||
requestIdleCallback(() => handle(web._documentObserverEvents));
|
||||
web._documentObserverEvents.push(...list);
|
||||
});
|
||||
web._documentObserver.observe(document.body, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
});
|
||||
}
|
||||
web._documentObserverListeners.push({ callback, selectors });
|
||||
};
|
||||
|
||||
/**
|
||||
* helpers for formatting or parsing text
|
||||
|
@ -13,7 +13,6 @@
|
||||
- tag sort
|
||||
- documentation e.g. \_file
|
||||
- complete/bugfix theming variables
|
||||
- clear file pickers
|
||||
- color pickers
|
||||
|
||||
#### app-specific
|
||||
|
@ -0,0 +1,9 @@
|
||||
/*
|
||||
* notion-enhancer core: bypass-preview
|
||||
* (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
|
||||
* (https://notion-enhancer.github.io/) under the MIT license
|
||||
*/
|
||||
|
||||
.notion-peek-renderer {
|
||||
display: none;
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* notion-enhancer core: bypass-preview
|
||||
* (c) 2021 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
|
||||
* (https://notion-enhancer.github.io/) under the MIT license
|
||||
*/
|
||||
|
||||
import { web } from '../../api.js';
|
||||
|
||||
web.whenReady().then(async () => {
|
||||
const openAsPage = document.querySelector(
|
||||
'.notion-peek-renderer [style*="height: 45px;"] a'
|
||||
);
|
||||
if (openAsPage) openAsPage.click();
|
||||
});
|
||||
|
||||
function getCurrentPage() {
|
||||
const previewID = location.search
|
||||
.slice(1)
|
||||
.split('&')
|
||||
.map((opt) => opt.split('='))
|
||||
.find((opt) => opt[0] === 'p');
|
||||
if (previewID) return { type: 'preview', id: previewID[1] };
|
||||
return { type: 'page', id: location.pathname.split(/(-|\/)/g).reverse()[0] };
|
||||
}
|
||||
let lastPage = getCurrentPage();
|
||||
web.observeDocument((event) => {
|
||||
const currentPage = getCurrentPage();
|
||||
if (currentPage.id !== lastPage.id || currentPage.type !== lastPage.type) {
|
||||
const openAsPage = document.querySelector(
|
||||
'.notion-peek-renderer [style*="height: 45px;"] a'
|
||||
);
|
||||
if (openAsPage) {
|
||||
if (currentPage.id === lastPage.id && currentPage.type === 'preview') {
|
||||
history.back();
|
||||
} else openAsPage.click();
|
||||
}
|
||||
lastPage = getCurrentPage();
|
||||
}
|
||||
});
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "bypass-preview",
|
||||
"id": "cb6fd684-f113-4a7a-9423-8f0f0cff069f",
|
||||
"description": "go straight to the normal full view when opening a page..",
|
||||
"version": "0.2.0",
|
||||
"tags": ["extension", "automation"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "dragonwocky",
|
||||
"email": "thedragonring.bod@gmail.com",
|
||||
"url": "https://dragonwocky.me/",
|
||||
"icon": "https://dragonwocky.me/avatar.jpg"
|
||||
}
|
||||
],
|
||||
"js": {
|
||||
"client": ["client.js"]
|
||||
},
|
||||
"css": {
|
||||
"client": ["client.css"]
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
[
|
||||
"menu@a6621988-551d-495a-97d8-3c568bca2e9e",
|
||||
"theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082",
|
||||
"tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2"
|
||||
"tweaks@5174a483-c88d-4bf8-a95f-35cd330b76e2",
|
||||
"bypass-preview@cb6fd684-f113-4a7a-9423-8f0f0cff069f"
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user