perf improvements + fullwidth page banner in preview

This commit is contained in:
dragonwocky 2020-08-16 12:42:03 +10:00
parent a57b7ca57a
commit 7b12815953
Signed by: dragonwocky
GPG Key ID: C7A48B7846AA706D
5 changed files with 85 additions and 14 deletions

View File

@ -97,7 +97,6 @@
max-width: var(--theme--preview-width) !important; max-width: var(--theme--preview-width) !important;
} }
.notion-peek-renderer .notion-scroller.vertical > div:nth-child(1) > div,
.notion-peek-renderer .notion-scroller.vertical > div:nth-child(2), .notion-peek-renderer .notion-scroller.vertical > div:nth-child(2),
.notion-peek-renderer .notion-page-view-discussion, .notion-peek-renderer .notion-page-view-discussion,
.notion-peek-renderer .notion-page-content { .notion-peek-renderer .notion-page-content {

View File

@ -63,7 +63,7 @@ window['__start'] = async () => {
return { return {
el, el,
resolve() { resolve() {
el.outerHTML = ''; el.remove();
}, },
prepend() { prepend() {
document.querySelector('#alerts').prepend(el); document.querySelector('#alerts').prepend(el);
@ -250,7 +250,7 @@ window['__start'] = async () => {
// ![image_title](source) // ![image_title](source)
.replace( .replace(
/([^\\])?\!\[([^\]]*[^\\\]]?)\]\(([^)]*[^\\)])\)/g, /([^\\])?\!\[([^\]]*[^\\\]]?)\]\(([^)]*[^\\)])\)/g,
`$1<img alt="$2" src="$3" onerror="this.outerHTML=''">` `$1<img alt="$2" src="$3" onerror="this.remove()">`
) )
// [link](destination) // [link](destination)
.replace( .replace(

View File

@ -47,7 +47,7 @@ module.exports = {
.querySelectorAll( .querySelectorAll(
'[src*="notion-emojis.s3-us-west-2.amazonaws.com"]:not(.notion-emoji)' '[src*="notion-emojis.s3-us-west-2.amazonaws.com"]:not(.notion-emoji)'
) )
.forEach((el) => (el.outerHTML = '')); .forEach((el) => el.remove());
if ( if (
(store().style === 'microsoft' && process.platform === 'win32') || (store().style === 'microsoft' && process.platform === 'win32') ||
(store().style === 'apple' && process.platform === 'darwin') (store().style === 'apple' && process.platform === 'darwin')

View File

@ -18,22 +18,31 @@ module.exports = {
'renderer/preload.js'(store, __exports) { 'renderer/preload.js'(store, __exports) {
document.addEventListener('readystatechange', (event) => { document.addEventListener('readystatechange', (event) => {
if (document.readyState !== 'complete') return false; if (document.readyState !== 'complete') return false;
let queue = [];
const observer = new MutationObserver((list, observer) => { const observer = new MutationObserver((list, observer) => {
document if (!queue.length) requestAnimationFrame(process);
.querySelectorAll( queue.push(...list);
'.notion-page-content > div[data-block-id]:not([dir])' console.log(queue.length);
)
.forEach((block) => block.setAttribute('dir', 'auto'));
document
.querySelectorAll("div[placeholder='List']")
.forEach((item) => {
item.style['text-align'] = 'start';
});
}); });
observer.observe(document, { observer.observe(document, {
childList: true, childList: true,
subtree: true, subtree: true,
characterData: true,
}); });
function process() {
const cache = queue;
queue = [];
for (let { target } of cache) {
if (!target.innerText) return;
if (target.getAttribute('dir') !== 'auto')
target.setAttribute('dir', 'auto');
if (
getComputedStyle(target).getPropertyValue('text-align') !==
'start'
)
target.style.setProperty('text-align', 'start');
}
}
}); });
}, },
}, },

63
mods/weekly-view/mod.js Normal file
View File

@ -0,0 +1,63 @@
/*
* weekly view
* (c) 2020 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* (c) 2020 adihd
* under the MIT license
*/
'use strict';
module.exports = {
id: '4c7acaea-6596-4590-85e5-8ac5a1455e8f',
tags: ['extension'],
name: 'weekly view',
desc: 'view 7-day calendars.',
version: '0.5.0',
author: 'adihd',
hacks: {
'renderer/preload.js'(store, __exports) {
document.addEventListener('readystatechange', (event) => {
if (document.readyState !== 'complete') return false;
const observer = new MutationObserver((list, observer) => {
document
.querySelectorAll('.notion-collection-view-select > :nth-child(2)')
.forEach((collection_view) => {
if (collection_view.innerText === 'weekly') {
collection_view =
collection_view.parentElement.parentElement.parentElement
.parentElement.parentElement;
// collection_view.classList.add('weekly_view');
// document
// .querySelectorAll('.adi_week_cal .notion-calendar-view-day')
// .forEach((day) => {
// if (day.style.background)
// day.parentElement.parentElement.classList.add(
// 'this_week'
// );
// });
// var weeks = document.querySelectorAll('.this_week')[0].parentElement
// .children;
// // delete al div that not contain a class of "this_week"
// while (weeks.length > 1) {
// for (let index = 0; index < weeks.length; index++) {
// // const element = array[index];
// if (weeks[index].classList.contains('this_week')) {
// console.log('yes');
// } else {
// // console.log(index);
// weeks[index].remove();
// }
// }
// }
}
});
});
observer.observe(document, {
childList: true,
subtree: true,
attributes: true,
});
});
},
},
};