refactor: prettierize all project

This commit is contained in:
Juan José Vílchez 2020-12-05 23:09:06 +01:00
parent 09d74504ea
commit 55edffd4b2
12 changed files with 119 additions and 105 deletions

View File

@ -1,11 +1,11 @@
'use strict';
"use strict";
if (!!window.chrome) {
const target =
document.head
|| document.getElementsByTagName('head')[0]
|| document.body
|| document.getElementsByTagName('body')[0];
document.head ||
document.getElementsByTagName("head")[0] ||
document.body ||
document.getElementsByTagName("body")[0];
// Create logic script
const script = document.createElement("script");
@ -14,4 +14,4 @@ if (!!window.chrome) {
// Inject logic script
if (!!target) target.appendChild(script);
};
}

View File

@ -1,6 +1,6 @@
export const UNTOUCHABLE_SITES = [
'www.aviva.co.uk',
'www.gamemania.be',
'www.guysandstthomas.nhs.uk',
'www.youtube.com',
"www.aviva.co.uk",
"www.gamemania.be",
"www.guysandstthomas.nhs.uk",
"www.youtube.com",
];

View File

@ -1,5 +1,5 @@
import { UNTOUCHABLE_SITES } from './constants.js'
import { getNotRemovableElements, getRemovableElements } from './helpers.js';
import { UNTOUCHABLE_SITES } from "./constants.js";
import { getNotRemovableElements, getRemovableElements } from "./helpers.js";
// Observer
const observer = new MutationObserver((mutations, observer) => {
@ -13,46 +13,60 @@ const observer = new MutationObserver((mutations, observer) => {
// Remover
const doMagic = () => {
// Getting elements
const notRemovable = getNotRemovableElements(document)
.filter(element => !!element);
const removable = getRemovableElements(document)
.filter(element => !!element);
const notRemovable = getNotRemovableElements(document).filter(
(element) => !!element
);
const removable = getRemovableElements(document).filter(
(element) => !!element
);
// Fixing main elements
if (!UNTOUCHABLE_SITES.includes(document.location.host)) {
document.documentElement.style.setProperty('margin-top', 'unset', 'important');
document.documentElement.style.setProperty('overflow', 'unset', 'important');
document.documentElement.style.setProperty('position', 'unset', 'important');
document.body.style.setProperty('overflow', 'unset', 'important');
document.documentElement.style.setProperty(
"margin-top",
"unset",
"important"
);
document.documentElement.style.setProperty(
"overflow",
"unset",
"important"
);
document.documentElement.style.setProperty(
"position",
"unset",
"important"
);
document.body.style.setProperty("overflow", "unset", "important");
}
// Remove irritating all removable elements
removable.forEach(element => {
removable.forEach((element) => {
const isRemovable =
element.tagName.toLowerCase() !== 'body'
&& element.tagName.toLowerCase() !== 'html';
element.tagName.toLowerCase() !== "body" &&
element.tagName.toLowerCase() !== "html";
if (isRemovable) {
const exists =
document.getElementById(element.id)
|| document.getElementsByName(element.name).length > 0
|| document.getElementsByClassName(element.className).length > 0;
document.getElementById(element.id) ||
document.getElementsByName(element.name).length > 0 ||
document.getElementsByClassName(element.className).length > 0;
if (exists) element.remove();
}
});
// Remove irritating styles from elements not removable
notRemovable.forEach(element => {
element.style.setProperty('margin-top', 'unset', 'important');
element.style.setProperty('overflow', 'unset', 'important');
element.style.setProperty('padding-top', 'unset', 'important');
notRemovable.forEach((element) => {
element.style.setProperty("margin-top", "unset", "important");
element.style.setProperty("overflow", "unset", "important");
element.style.setProperty("padding-top", "unset", "important");
// Miscellaneous
element.classList.remove('cli-barmodal-open');
element.classList.remove('cookiesAccepted');
element.classList.remove('cookiewall-active');
element.classList.remove('noScroll');
element.classList.remove("cli-barmodal-open");
element.classList.remove("cookiesAccepted");
element.classList.remove("cookiewall-active");
element.classList.remove("noScroll");
});
};