Skip to content

Commit

Permalink
Fix(temp): Remove color and shake from powermode
Browse files Browse the repository at this point in the history
  • Loading branch information
plibither8 committed Jul 2, 2019
1 parent 5331bb4 commit 8cca625
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 32 deletions.
52 changes: 33 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const mainSection = getHtmlElement('section.main');
const historySection = getHtmlElement('section.history');
const settingsSection = getHtmlElement('section.settings');
let rawText;
let isPowerModeEventListenerSet = false; // Boolean to prevent multiple eventlisteners
const activeModals = []; // Array of active modals
let saveHistory; // Settings.saveHistory Boolean
let cursorLastPosition; // Settings.cursorLastPosition Boolean
Expand Down Expand Up @@ -284,34 +285,44 @@ const setSettings = (key, value) => {
PowerModeColor: false,
PowerModeShake: false
};
} else {
settings[key] = value;
}

settings[key] = value;

syncStorageSet('settings', JSON.stringify(settings));
};

/**
* Main settings handler function
*/
const settingsControl = () => {

const setEventListenersToSettings = () => {
const settingsItems = document.querySelectorAll('section.settings .item');

for (const item of settingsItems) {
item.addEventListener('click', () => {
settingsControl(item.dataset.setting);
})
}
}

const settingsControl = (keyName = undefined) => {
const settings = getSettings();
const settingsItems = document.querySelectorAll('section.settings .item');

[...settingsItems].forEach(item => {
const key = item.getAttribute('data-setting');
for (const item of settingsItems) {
const key = item.dataset.setting;
const value = settings[key];

// Toggle class on item and change switch style
removeClass(item, value ? 'off' : 'on');
addClass(item, value ? 'on' : 'off');

// Using addEventListener does not work properly for some reason
item.addEventListener('click', () => {
if (key === keyName) {
setSettings(key, !value);
settingsControl();
});
});
}
}

applySettings();
};
Expand All @@ -328,17 +339,20 @@ const applySettings = () => {
cursorLastPosition = settings.cursorLastPosition;
// Toggle modes with Cmd/Ctrl + return key
returnKeyToggle = settings.returnKeyToggle;
// // Colored POWER MODE
// POWERMODE.colorful = settings.PowerModeColor;
// // Shake on POWER MODE
// POWERMODE.shake = settings.PowerModeShake;
// Enable POWER MODE
if (settings.enablePowerMode) {
textarea.addEventListener('input', POWERMODE, false);
} else {
textarea.removeEventListener('input', POWERMODE, false);
if (settings.enablePowerMode && !isPowerModeEventListenerSet) {
textarea.addEventListener('input', POWERMODE);
isPowerModeEventListenerSet = true;
}

// Colored POWER MODE
POWERMODE.colorful = settings.PowerModeColor;
// Shake on POWER MODE
POWERMODE.shake = settings.PowerModeShake;
if (!settings.enablePowerMode && isPowerModeEventListenerSet) {
textarea.removeEventListener('input', POWERMODE);
isPowerModeEventListenerSet = false;
}
};

/**
Expand Down Expand Up @@ -486,6 +500,7 @@ const initiate = () => {
/**
* First things first: Set and apply settings
*/
setEventListenersToSettings();
setSettings();
settingsControl();

Expand Down Expand Up @@ -559,7 +574,7 @@ const initiate = () => {
closeModal(historySection);
}, false);
getHtmlElement('#settings').addEventListener('click', () => {
openModal(settingsSection, settingsControl);
openModal(settingsSection);
}, false);
getHtmlElement('#closeSettings').addEventListener('click', () => {
closeModal(settingsSection);
Expand Down Expand Up @@ -632,7 +647,6 @@ const initiate = () => {
for (const [key, value] of Object.entries(items)) {
localStorage.setItem(key, value);
}

initiate();
}
});
Expand Down
24 changes: 12 additions & 12 deletions src/pug/includes/body.pug
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,24 @@
.switch.flex
.box

.item.flex(data-setting='PowerModeColor')
//- .item.flex(data-setting='PowerModeColor')
.main.flex
label Colored POWER MODE
p Add colors to particles from POWER MODE (if enabled)
//- .main.flex
//- label Colored POWER MODE
//- p Add colors to particles from POWER MODE (if enabled)
.switch.flex
.box
//- .switch.flex
//- .box
.item.flex(data-setting='PowerModeShake')
//- .item.flex(data-setting='PowerModeShake')
.main.flex
label Shake on POWER MODE
p If POWER MODE is enabled, entire screen will "shake" when typing
//- .main.flex
//- label Shake on POWER MODE
//- p If POWER MODE is enabled, entire screen will "shake" when typing
.switch.flex
.box
//- .switch.flex
//- .box
section.bar.flex.noselect
Expand Down
1 change: 0 additions & 1 deletion src/pug/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ html(lang='en')
include ./includes/body.pug

script(src="activate-power-mode.js")
script(src="index.js")

0 comments on commit 8cca625

Please sign in to comment.