From 4bd3a8904505ab8d237d01a7b2b12c8fe3053e64 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 5 Oct 2019 19:58:54 +0200 Subject: [PATCH] fix for/if spacing --- 3D/Loader/ObjLoader.js | 6 +- Log/Logger.js | 2 +- .../Browser/BrowserNotification.js | 4 +- Model/Action/Dom/Popup.js | 12 +- Model/Action/Utils/DataCollector.js | 2 +- Model/Message/FormValidation.js | 2 +- UI/Component/AdvancedInput.js | 2 +- UI/Input/Voice/VoiceManager.js | 2 +- UI/UIManager.js | 4 +- Utils/Debug.js | 113 ++++++++++++++++++ 10 files changed, 131 insertions(+), 18 deletions(-) create mode 100644 Utils/Debug.js diff --git a/3D/Loader/ObjLoader.js b/3D/Loader/ObjLoader.js index b5f3ca1..1bda43c 100644 --- a/3D/Loader/ObjLoader.js +++ b/3D/Loader/ObjLoader.js @@ -314,11 +314,11 @@ { let state = this.createParserState(); - if(text.indexOf('\r\n') !== -1) { + if (text.indexOf('\r\n') !== -1) { text = text.replace(/\r\n/g, '/n'); } - if(text.indexOf('\\\n') !== -1) { + if (text.indexOf('\\\n') !== -1) { text = text.replace(/\\\n/g, ''); } @@ -330,7 +330,7 @@ result = [], trimLeft = (typeof ''.trimLeft === 'function'); - for(let i = 0, l = lines.length; i < l; i++) { + for (let i = 0, l = lines.length; i < l; i++) { line = lines[i]; line = trimLeft ? line.trimLeft() : line.trim(); lineLength = line.length; diff --git a/Log/Logger.js b/Log/Logger.js index 0bc3439..2ab8fe8 100644 --- a/Log/Logger.js +++ b/Log/Logger.js @@ -39,7 +39,7 @@ export class Logger { */ static getInstance (verbose = true, ui = true, remote = false) { - if(!Logger.instance) { + if (!Logger.instance) { Logger.instance = new Logger(verbose, ui, remote); } diff --git a/Message/Notification/Browser/BrowserNotification.js b/Message/Notification/Browser/BrowserNotification.js index 86eb488..8f02f4f 100644 --- a/Message/Notification/Browser/BrowserNotification.js +++ b/Message/Notification/Browser/BrowserNotification.js @@ -43,9 +43,9 @@ export class BrowserNotification { const self = this; /** global: Notification */ - if(Notification.permission !== 'granted' && Notification.permission !== 'denied') { + if (Notification.permission !== 'granted' && Notification.permission !== 'denied') { Notification.requestPermission(function(permission) { - if(permission === 'granted') { + if (permission === 'granted') { let msg = new jsOMS.Message.Notification.NotificationMessage(); self.send(msg); diff --git a/Model/Action/Dom/Popup.js b/Model/Action/Dom/Popup.js index 0cb0b93..e62f670 100644 --- a/Model/Action/Dom/Popup.js +++ b/Model/Action/Dom/Popup.js @@ -13,21 +13,21 @@ export function popupButtonAction (action, callback, id) const popup = action.base === 'self' ? (action.selector === '' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector); - for(let i in popup) { + for (let i in popup) { /** global: HTMLElement */ - if(!popup.hasOwnProperty(i) || !popup[i] || !(popup[i] instanceof HTMLElement)) { + if (!popup.hasOwnProperty(i) || !popup[i] || !(popup[i] instanceof HTMLElement)) { continue; } const clone = document.importNode(popup[i].content, true); const dim = document.getElementById('dim'); - if(dim) { + if (dim) { document.getElementById('dim').classList.remove('vh'); } - for(let j in clone) { - if(!clone.hasOwnProperty(j) || !(clone[j] instanceof HTMLElement)) { + for (let j in clone) { + if (!clone.hasOwnProperty(j) || !(clone[j] instanceof HTMLElement)) { continue; } @@ -38,7 +38,7 @@ export function popupButtonAction (action, callback, id) let e = document.getElementById(popup[i].id.substr(0, popup[i].id.length - 4)); - if(!e) { + if (!e) { continue; } diff --git a/Model/Action/Utils/DataCollector.js b/Model/Action/Utils/DataCollector.js index 3d44e9d..626bc09 100644 --- a/Model/Action/Utils/DataCollector.js +++ b/Model/Action/Utils/DataCollector.js @@ -20,7 +20,7 @@ export function dataCollectionAction (action, callback) elements = document.querySelectorAll(action.collect[selector]); for (let e in elements) { - if(!elements.hasOwnProperty(e)) { + if (!elements.hasOwnProperty(e)) { continue; } diff --git a/Model/Message/FormValidation.js b/Model/Message/FormValidation.js index ad39c08..2d8dc15 100644 --- a/Model/Message/FormValidation.js +++ b/Model/Message/FormValidation.js @@ -8,7 +8,7 @@ export function formValidationMessage (data) { const form = document.getElementById(data.form); - if(!form) { + if (!form) { return; } diff --git a/UI/Component/AdvancedInput.js b/UI/Component/AdvancedInput.js index 666090b..78f0b31 100644 --- a/UI/Component/AdvancedInput.js +++ b/UI/Component/AdvancedInput.js @@ -133,7 +133,7 @@ export class AdvancedInput { self.dataListBody.removeChild(self.dataListBody.firstChild); } - for(let i = 0; i < dataLength; ++i) { + for (let i = 0; i < dataLength; ++i) { // set readable value const newRow = self.dataTpl.content.cloneNode(true); let fields = newRow.querySelectorAll('[data-tpl-text]'); diff --git a/UI/Input/Voice/VoiceManager.js b/UI/Input/Voice/VoiceManager.js index dc8768b..e737d30 100644 --- a/UI/Input/Voice/VoiceManager.js +++ b/UI/Input/Voice/VoiceManager.js @@ -1,7 +1,7 @@ import { Logger } from '../../../Log/Logger.js'; /** - * Form manager class. + * Voice manager class. * * @copyright Dennis Eichhorn * @license OMS License 1.0 diff --git a/UI/UIManager.js b/UI/UIManager.js index 5f99bfd..73ec470 100644 --- a/UI/UIManager.js +++ b/UI/UIManager.js @@ -36,7 +36,7 @@ export class UIManager { this.domObserver = new MutationObserver(function(mutations) { const length = mutations.length; - for(let i = 0; i < length; ++i) { + for (let i = 0; i < length; ++i) { self.app.eventManager.trigger(mutations[i].target.id + '-' + mutations[i].type, 0, mutations[i]); } }); @@ -64,7 +64,7 @@ export class UIManager { const tag = document.getElementById(id); this.generalUI.bind(tag); - if(!tag) { + if (!tag) { return; } diff --git a/Utils/Debug.js b/Utils/Debug.js new file mode 100644 index 0000000..3c53e59 --- /dev/null +++ b/Utils/Debug.js @@ -0,0 +1,113 @@ +var visited = []; +var findings = {}; +var cssSelectors = {}, + cssSelectorsLength = 0; +const cssFiles = ['http://127.0.0.1/cssOMS/styles.css']; +const cssFilesLength = cssFiles.length; +const domain = window.location.hostname; +const pageLimit = 10; + +var cssRequest = new XMLHttpRequest(); +cssRequest.onreadystatechange = function() +{ + if (cssRequest.readyState == 4 && cssRequest.status == 200) { + const cssText = this.responseText; + const result = cssText.match(/[a-zA-Z0-9\ :>~\.\"'#,\[\]=\-\(\)\*]+{/g), + resultLength = result.length; + + for (let i = 1; i < resultLength; ++i) { + let sel = result[i].substring(0, result[i].length - 1).trimLeft().trimRight().trimRight(); + if (!cssSelectors.hasOwnProperty(sel)) { + cssSelectors[sel] = 0; + ++cssSelectorsLength; + } + } + } +} + +for (let i = 0; i < cssFilesLength; ++i) { + cssRequest.open('GET', cssFiles[i], true); + cssRequest.send(); +} + +validatePage = function(url) +{ + if (visited.includes(url) || visited.length > pageLimit - 1) { + return; + } + + // mark url as visited + visited.push(url); + findings[url] = {}; + + // web request + var webRequest = new XMLHttpRequest(); + webRequest.onreadystatechange = function() + { + if (webRequest.readyState == 4 && webRequest.status == 200) { + // replace content + document.open(); + document.write(this.responseText); + document.close(); + + // analyze img alt attribute + let imgAlt = document.querySelectorAll('img:not([alt]), img[alt=""], img[alt=" "]'); + findings[url]['img_alt'] = imgAlt.length; + + // analyze img src + let imgSrc = document.querySelectorAll('img:not([src]), img[src=""], img[src=" "]'); + findings[url]['img_src'] = imgSrc.length; + + // analyze empty link + let aHref = document.querySelectorAll('a:not([alt]), a[href=""], a[href=" "], a[href="#"]'); + findings[url]['href_empty'] = aHref.length; + + // analyze inline on* function + let onFunction = document.querySelectorAll('[onafterprint], [onbeforeprint], [onbeforeunload], [onerror], [onhaschange], [onload], [onmessage], [onoffline], [ononline], [onpagehide], [onpageshow], [onpopstate], [onredo], [onresize], [onstorage], [onundo], [onunload], [onblur], [onchage], [oncontextmenu], [onfocus], [onformchange], [onforminput], [oninput], [oninvalid], [onreset], [onselect], [onsubmit], [onkeydown], [onkeypress], [onkeyup], [onclick], [ondblclick], [ondrag], [ondragend], [ondragenter], [ondragleave], [ondragover], [ondragstart], [ondrop], [onmousedown], [onmousemove], [onmouseout], [onmouseover], [onmouseup], [onmousewheel], [onscroll], [onabort], [oncanplay], [oncanplaythrough], [ondurationchange], [onemptied], [onended], [onerror], [onloadeddata], [onloadedmetadata], [onloadstart], [onpause], [onplay], [onplaying], [onprogress], [onratechange], [onreadystatechange], [onseeked], [onseeking], [onstalled], [onsuspend], [ontimeupdate], [onvolumechange], [onwaiting]'); + findings[url]['js_on'] = onFunction.length; + + // analyze missing form element attributes + let formElements = document.querySelectorAll('input:not([id]), input[type=""], select:not([id]), textarea:not([id]), label:not([for]), label[for=""], label[for=" "], input:not([name]), select:not([name]), textarea:not([name]), form:not([id]), form:not([action]), form[action=""], form[action=" "], form[action="#"]'); + findings[url]['form_elements'] = formElements.length; + + // analyze invalid container-children relationship (e.g. empty containers, invalid children) + let invalidContainerChildren = document.querySelectorAll(':not(tr) > td, :not(tr) > th, colgroup *:not(col), :not(colgroup) > col, tr > :not(td):not(th), optgroup > :not(option), :not(select) > option, :not(fieldset) > legend, select > :not(option):not(optgroup), :not(select):not(optgroup) > option, table > *:not(thead):not(tfoot):not(tbody):not(tr):not(colgroup):not(caption)'); + findings[url]['invalid_container_children'] = invalidContainerChildren.length; + + // has inline styles + let hasInlineStyles = document.querySelectorAll('*[style]'); + findings[url]['form_elements'] = hasInlineStyles.length; + + // analyze css usage + let cssFound; + for (let i in cssSelectors) { + try { + cssFound = document.querySelectorAll(i.replace(/:hover|:active/gi, '')); + cssSelectors[i] = cssFound === null ? 0 : cssFound.length + } catch (e) {} + } + + // check other pages + let links = document.querySelectorAll('a'), + linkLength = links.length; + + for (let i = 0; i < linkLength; ++i) { + if (visited.includes(links[i].href) || + (!links[i].href.startsWith('/') && links[i].href.startsWith('http') && !links[i].href.includes(domain)) + ) { + continue; + } + + validatePage(links[i].href); + } + } + }; + + webRequest.open('GET', url, true); + webRequest.send(); +}; + +validatePage(location.href); + +console.table(findings); +console.table(cssSelectors); \ No newline at end of file