notion-enhancer/mods/custom-inserts/mod.js

65 lines
1.6 KiB
JavaScript

/*
* custom inserts
* (c) 2020 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* under the MIT license
*/
'use strict';
const helpers = require('../../pkg/helpers.js');
module.exports = {
id: 'b4b0aced-2059-43bf-8d1d-ccd757ee5ebb',
tags: ['extension'],
name: 'custom inserts',
desc: 'link files for small client-side tweaks.',
version: '0.1.2',
author: 'dragonwocky',
options: [
{
key: 'css',
label: 'css insert',
type: 'file',
extensions: ['css'],
},
{
key: 'js',
label: 'client-side js insert',
type: 'file',
extensions: ['js'],
},
],
hacks: {
'renderer/preload.js'(store, __exports) {
const fs = require('fs-extra');
document.addEventListener('readystatechange', (event) => {
if (document.readyState !== 'complete') return false;
if (store().css) {
try {
document
.querySelector('head')
.appendChild(
helpers.createElement(
`<style type="text/css">${fs.readFileSync(
store().css
)}</style>`
)
);
} catch (err) {
console.warn('<custom-inserts> invalid css file... unsetting.');
store().css = '';
}
}
if (store().js) {
try {
require(store().js);
} catch (err) {
console.warn('<custom-inserts> invalid js file... unsetting.');
store().js = '';
}
}
});
},
},
};