Skip to content

Commit

Permalink
fix: formatting 2: electric bogaloo
Browse files Browse the repository at this point in the history
  • Loading branch information
KraXen72 committed Jun 29, 2022
1 parent a5b535f commit 6c3c1c6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
56 changes: 28 additions & 28 deletions src/settingsui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class SettingElem {

updateKey: 'value' | 'checked' | '';

#wrapper: HTMLElement | false
#wrapper: HTMLElement | false;

constructor(props: RenderReadySetting) {
/** @type {Object} save the props from constructor to this class (instance) */
Expand All @@ -125,7 +125,7 @@ class SettingElem {
/** @type {String} is the key to get checked when writing an update, for checkboxes it's checked, for selects its value etc.*/
this.updateKey = '';

this.#wrapper = false
this.#wrapper = false;

// /** @type {Number | String} (only for 'sel' type) if Number, parseInt before assigning to Container */

Expand Down Expand Up @@ -213,16 +213,16 @@ class SettingElem {
if (this.props.key === 'menuTimer') toggleSettingCSS(styleSettingsCSS.menuTimer, this.props.key, value);
} else if (callback === 'userscript') {
if ('userscriptReference' in this.props) {
const userscript = this.props.userscriptReference
const userscript = this.props.userscriptReference;

if (value && !userscript.hasRan) {
userscript.load()
userscript.load();
} else if (!value) {
if (this.props.instant && typeof userscript.unload === "function") {
userscript.unload()
if (this.props.instant && typeof userscript.unload === 'function') {
userscript.unload();
} else {
elem.querySelector(".setting-desc-new").textContent = `REFRESH PAGE TO SEE CHANGES`
target.setAttribute("disabled", '')
elem.querySelector('.setting-desc-new').textContent = 'REFRESH PAGE TO SEE CHANGES';
target.setAttribute('disabled', '');
}
}
ipcRenderer.send('logMainConsole', `userscript: recieved an update for ${userscript.name}: ${value}`);
Expand All @@ -243,28 +243,28 @@ class SettingElem {
* this initializes the element and its eventlisteners.
*/
get elem() {
if (this.#wrapper !== false) {
return this.#wrapper //returnt he element if already initialized
} else {
// i only create the element after .elem is called so i don't pollute the dom with virutal elements when making settings
const wrapper = createElement('div', {
class: ['setting', 'settName', `safety-${this.props.safety}`, this.props.type],
id: `settingElem-${this.props.key}`,
innerHTML: this.HTML
});
if (this.#wrapper !== false) return this.#wrapper; // returnt he element if already initialized

if (this.type === 'sel') wrapper.querySelector('select').value = this.props.value;
if (typeof this.props.callback === 'undefined') this.props.callback = 'normal'; // default callback

// @ts-ignore
wrapper[this.updateMethod] = () => {
this.update({ elem: wrapper, callback: this.props.callback });
};
// i only create the element after .elem is called so i don't pollute the dom with virutal elements when making settings
const wrapper = createElement('div', {
class: ['setting', 'settName', `safety-${this.props.safety}`, this.props.type],
id: `settingElem-${this.props.key}`,
innerHTML: this.HTML
});

this.#wrapper = wrapper
return wrapper; // return the element
}
if (this.type === 'sel') wrapper.querySelector('select').value = this.props.value;
if (typeof this.props.callback === 'undefined') this.props.callback = 'normal'; // default callback

// @ts-ignore
wrapper[this.updateMethod] = () => {
this.update({ elem: wrapper, callback: this.props.callback });
};

this.#wrapper = wrapper;
return wrapper; // return the element
}

}

// i am insane for making this
Expand Down Expand Up @@ -357,7 +357,7 @@ export function renderSettings() {
callback: 'userscript'
};
if (userscript.meta) { // render custom metadata if provided in userscrsipt.exported
const thisMeta = userscript.meta
const thisMeta = userscript.meta;
Object.assign(obj, {
title: 'name' in thisMeta && thisMeta.name ? thisMeta.name : userscript.name,
desc: `${'desc' in thisMeta && thisMeta.desc ? thisMeta.desc.slice(0, 60) : ''}
Expand All @@ -366,7 +366,7 @@ export function renderSettings() {
${'src' in thisMeta && thisMeta.src ? ` &#8226; <a target="_blank" href="${thisMeta.src}">source</a>` : ''}`
});
}
if (userscript.unload) { obj.instant = true }
if (userscript.unload) obj.instant = true;

return obj;
});
Expand Down
9 changes: 4 additions & 5 deletions src/userscripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Userscript implements IUserscriptInstance {

#initialized: boolean;

hasRan: boolean
hasRan: boolean;

#hadToTransform: boolean;

Expand All @@ -55,8 +55,8 @@ class Userscript implements IUserscriptInstance {
const metaParser = require('userscript-meta');

let chunk: (string[] | string) = this.rawContent.split('\n');
const startLine = chunk.findIndex(l => l.includes('// ==UserScript=='));
const endLine = chunk.findIndex(l => l.includes('// ==/UserScript=='));
const startLine = chunk.findIndex(line => line.includes('// ==UserScript=='));
const endLine = chunk.findIndex(line => line.includes('// ==/UserScript=='));
strippedConsole.log(chunk, startLine, endLine);
chunk = chunk.slice(startLine, endLine + 1).join('\n');

Expand Down Expand Up @@ -119,7 +119,7 @@ class Userscript implements IUserscriptInstance {
// more stuff to be added here later
if ('unload' in exported) this.unload = exported.unload;
}

strippedConsole.log(`%c[cs]${this.#hadToTransform ? '%c[esbuilt]' : '%c[strict]'} %cran %c'${this.name.toString()}' `,
'color: lightblue; font-weight: bold;', this.#hadToTransform ? 'color: orange' : 'color: #62dd4f',
'color: white;', 'color: lightgreen;');
Expand All @@ -132,7 +132,6 @@ class Userscript implements IUserscriptInstance {
}



/*
* TODO metadtada won't show when script is not enabled, because it doesen't run and return anything...
* TODO run script on turn on
Expand Down

0 comments on commit 6c3c1c6

Please sign in to comment.