mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-07 05:59:02 +00:00
#106: make use of user-agent for emoji sets
This commit is contained in:
parent
0c18f19dac
commit
f39e497f4c
@ -6,14 +6,12 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
let tweaked = false;
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
id: 'a2401ee1-93ba-4b8c-9781-7f570bf5d71e',
|
id: 'a2401ee1-93ba-4b8c-9781-7f570bf5d71e',
|
||||||
tags: ['extension'],
|
tags: ['extension'],
|
||||||
name: 'emoji sets',
|
name: 'emoji sets',
|
||||||
desc: 'pick from a variety of emoji styles to use.',
|
desc: 'pick from a variety of emoji styles to use.',
|
||||||
version: '0.1.3',
|
version: '0.2.0',
|
||||||
author: 'dragonwocky',
|
author: 'dragonwocky',
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
@ -40,56 +38,58 @@ module.exports = {
|
|||||||
],
|
],
|
||||||
hacks: {
|
hacks: {
|
||||||
'renderer/preload.js'(store, __exports) {
|
'renderer/preload.js'(store, __exports) {
|
||||||
document.addEventListener('readystatechange', (event) => {
|
const useNative =
|
||||||
if (document.readyState !== 'complete') return false;
|
(store().style === 'microsoft' && process.platform === 'win32') ||
|
||||||
let queue = [];
|
(store().style === 'apple' && process.platform === 'darwin');
|
||||||
const observer = new MutationObserver((list, observer) => {
|
|
||||||
if (!queue.length) requestAnimationFrame(process);
|
|
||||||
queue.push(...list);
|
|
||||||
});
|
|
||||||
observer.observe(document.body, {
|
|
||||||
childList: true,
|
|
||||||
subtree: true,
|
|
||||||
characterData: true,
|
|
||||||
});
|
|
||||||
function process() {
|
|
||||||
queue = [];
|
|
||||||
|
|
||||||
// if (
|
Object.defineProperty(navigator, 'userAgent', {
|
||||||
// (store().style === 'microsoft' && process.platform === 'win32') ||
|
get: function () {
|
||||||
// (store().style === 'apple' && process.platform === 'darwin')
|
// macOS useragent uses system emojis instead of images
|
||||||
// ) {
|
// = no need to download
|
||||||
// document
|
return useNative
|
||||||
// .querySelectorAll('.notion-record-icon .notion-emoji')
|
? 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Safari/605.1.15 Notion/2.0.9 Electron/6.1.5'
|
||||||
// .forEach((el) => {
|
: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Notion/2.0.9 Chrome/76.0.3809.146 Electron/6.1.5 Safari/537.36';
|
||||||
// el.outerHTML = `<span style="font-size: 0.9em; position: relative; bottom: 0.1em; right: 0.05em">
|
},
|
||||||
// ${el.getAttribute('alt')}
|
|
||||||
// </span>`;
|
|
||||||
// });
|
|
||||||
// document.querySelectorAll('.notion-emoji').forEach((el) => {
|
|
||||||
// el.outerHTML = `<span>${el.getAttribute('alt')}</span>`;
|
|
||||||
// });
|
|
||||||
// } -- attempt load improvement by using actual emojis instead of pictures
|
|
||||||
// ...breaks changing them again after
|
|
||||||
|
|
||||||
if (store().style !== 'twitter' || tweaked) {
|
|
||||||
document
|
|
||||||
.querySelectorAll('[src*="notion-emojis.s3"]:not(.notion-emoji)')
|
|
||||||
.forEach((el) => el.remove());
|
|
||||||
document.querySelectorAll('.notion-emoji').forEach((el) => {
|
|
||||||
el.style.setProperty(
|
|
||||||
'background',
|
|
||||||
`url(https://emojicdn.elk.sh/${el.getAttribute('alt')}?style=${
|
|
||||||
store().style
|
|
||||||
})`
|
|
||||||
);
|
|
||||||
el.style.setProperty('background-size', 'contain');
|
|
||||||
el.style.setProperty('opacity', '1');
|
|
||||||
});
|
|
||||||
tweaked = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!useNative) {
|
||||||
|
let tweaked = false;
|
||||||
|
|
||||||
|
document.addEventListener('readystatechange', (event) => {
|
||||||
|
if (document.readyState !== 'complete') return false;
|
||||||
|
let queue = [];
|
||||||
|
const observer = new MutationObserver((list, observer) => {
|
||||||
|
if (!queue.length) requestAnimationFrame(process);
|
||||||
|
queue.push(...list);
|
||||||
|
});
|
||||||
|
observer.observe(document.body, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true,
|
||||||
|
characterData: true,
|
||||||
|
});
|
||||||
|
function process() {
|
||||||
|
queue = [];
|
||||||
|
if (store().style !== 'twitter' || tweaked) {
|
||||||
|
document
|
||||||
|
.querySelectorAll(
|
||||||
|
'[src*="notion-emojis.s3"]:not(.notion-emoji)'
|
||||||
|
)
|
||||||
|
.forEach((el) => el.remove());
|
||||||
|
document.querySelectorAll('.notion-emoji').forEach((el) => {
|
||||||
|
el.style.setProperty(
|
||||||
|
'background',
|
||||||
|
`url(https://emojicdn.elk.sh/${el.getAttribute(
|
||||||
|
'alt'
|
||||||
|
)}?style=${store().style})`
|
||||||
|
);
|
||||||
|
el.style.setProperty('background-size', 'contain');
|
||||||
|
el.style.setProperty('opacity', '1');
|
||||||
|
});
|
||||||
|
tweaked = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user