diff --git a/Recipe.min.js b/Recipe.min.js index 5566a06..f758d4f 100644 --- a/Recipe.min.js +++ b/Recipe.min.js @@ -437,63 +437,63 @@ function getPatternUsage(results, domClasses, cssClasses) { return results; } -void function() { - - window.HtmlUsage = {}; - - // This function has been added to the elementAnalyzers in - // CSSUsage.js under onready() - // is an HTMLElement passed in by elementAnalyzers - window.HtmlUsage.GetNodeName = function (element) { - - // If the browser doesn't recognize the element - throw it away - if(element instanceof HTMLUnknownElement) { - return; - } - - var node = element.nodeName; - - var tags = HtmlUsageResults.tags || (HtmlUsageResults.tags = {}); - var tag = tags[node] || (tags[node] = 0); - tags[node]++; - - GetAttributes(element, node); - } - - function GetAttributes(element, node) { - for(var i = 0; i < element.attributes.length; i++) { - var att = element.attributes[i]; - - if(IsValidAttribute(element, att.nodeName)) { - var attributes = HtmlUsageResults.attributes || (HtmlUsageResults.attributes = {}); - var attribute = attributes[att.nodeName] || (attributes[att.nodeName] = {}); - var attributeTag = attribute[node] || (attribute[node] = {count: 0}); - attributeTag.count++; - } - } - } - - function IsValidAttribute(element, attname) { - // We need to convert className - if(attname == "class") { - attname = "className"; - } - - if(attname == "classname") { - return false; - } - - // Only keep attributes that are not data - if(attname.indexOf('data-') != -1) { - return false; - } - - if(typeof(element[attname]) == "undefined") { - return false; - } - - return true; - } +void function() { + + window.HtmlUsage = {}; + + // This function has been added to the elementAnalyzers in + // CSSUsage.js under onready() + // is an HTMLElement passed in by elementAnalyzers + window.HtmlUsage.GetNodeName = function (element) { + + // If the browser doesn't recognize the element - throw it away + if(element instanceof HTMLUnknownElement) { + return; + } + + var node = element.nodeName; + + var tags = HtmlUsageResults.tags || (HtmlUsageResults.tags = {}); + var tag = tags[node] || (tags[node] = 0); + tags[node]++; + + GetAttributes(element, node); + } + + function GetAttributes(element, node) { + for(var i = 0; i < element.attributes.length; i++) { + var att = element.attributes[i]; + + if(IsValidAttribute(element, att.nodeName)) { + var attributes = HtmlUsageResults.attributes || (HtmlUsageResults.attributes = {}); + var attribute = attributes[att.nodeName] || (attributes[att.nodeName] = {}); + var attributeTag = attribute[node] || (attribute[node] = {count: 0}); + attributeTag.count++; + } + } + } + + function IsValidAttribute(element, attname) { + // We need to convert className + if(attname == "class") { + attname = "className"; + } + + if(attname == "classname") { + return false; + } + + // Only keep attributes that are not data + if(attname.indexOf('data-') != -1) { + return false; + } + + if(typeof(element[attname]) == "undefined") { + return false; + } + + return true; + } }(); void function() { try { @@ -1541,322 +1541,269 @@ void function() { try { } catch (ex) { /* do something maybe */ throw ex; } }(); /* - RECIPE: object_fit_object_position - ------------------------------------------------------------- - Author: joevery - Description: Get count of how many times object-fit and object-position CSS properties are used on websites and classify by HTML tag. -*/ -void function() { - window.CSSUsage.StyleWalker.recipesToRun.push( - function object_fit_object_position(element, results) - { - // Need this to ensure no errors on html and head tags when running the code below. - if (!element.CSSUsage) return; - - if (element.CSSUsage["object-fit"]) - { - // Allows counting of number of HTML tags using object-fit CSS property on page. - results["object-fit"] = results["object-fit"] || { count: 0, }; - results["object-fit"].count++; - - // Classify count by HTML tag. - var nodeName = element.nodeName; - results["object-fit"][nodeName] = results["object-fit"][nodeName] || { count: 0, }; - results["object-fit"][nodeName].count++; - } - - if (element.CSSUsage["object-position"]) - { - // Allows counting of number of HTML tags using object-position CSS property on page. - results["object-position"] = results["object-position"] || { count: 0, }; - results["object-position"].count++; - - // Classify count by HTML tag. - var nodeName = element.nodeName; - results["object-position"][nodeName] = results["object-position"][nodeName] || { count: 0, }; - results["object-position"][nodeName].count++; - } - - return results; - }); -}(); - -/* - RECIPE: object_fit_onvideo + RECIPE: svg_css-transform_preserve-3d ------------------------------------------------------------- Author: joevery - Description: Get count of how many times object-fit CSS property is used on a video element on websites. + Description: Get count of svg elements on page along with how many contain the transform CSS property and the transform-style CSS property with value preserve-3d in their namespace. + In addition, we want to classify the number of elements that have either of these CSS properties applied by the HTML tags they are applied to. */ void function() { window.CSSUsage.StyleWalker.recipesToRun.push( - function object_fit_onvideo(element, results) + function svg_css_transform_preserve_3d(element, results) { var nodeName = element.nodeName; - if (nodeName == "VIDEO") - { - if (element.CSSUsage["object-fit"]) - { - var key = "VIDEO" + "_" + "object-fit"; - results[key] = results[key] || { count: 0, }; - results[key].count++; - } - } - return results; - }); -}(); - -/* - RECIPE: position-sticky_ancestry-tree - ------------------------------------------------------------- - Author: joevery - Description: Get count of how many times position CSS property with value sticky are used on websites and classify by HTML tag. -*/ -void function() { - window.CSSUsage.StyleWalker.recipesToRun.push( - function position_sticky_ancestry_tree(element, results) - { - // Need this to ensure no errors on html and head tags when running the code below. - if (!element.CSSUsage) return; - - if (element.CSSUsage["position"] == "sticky") + if (nodeName == "svg") { - var nodeName = element.nodeName; - - var ancestryTreeArray = [nodeName]; + results["svg"] = results["svg"] || { count: 0, }; + results["svg"].count++; - var currentParent = element.parentElement; + var elementsToCheck = [element]; + var level = 0; - while (currentParent) + while (elementsToCheck.length > 0) { - ancestryTreeArray.push(currentParent.nodeName); - currentParent = currentParent.parentElement; + var children = []; + + for (var i = 0; i < elementsToCheck.length; ++i) + { + var e = elementsToCheck[i]; + + // We want to skip nested svg elements and do them later, but of course do the one we just found. + if (e.nodeName != "svg" || level == 0) + { + // If no CSS on element, then don't do what is inside if statement, otherwise it will hit error. + if (e.CSSUsage) + { + if (e.CSSUsage["transform"]) + { + var tNodeName = e.nodeName; + var tValues = e.CSSUsage["transform"]; + + results["svg"]["transform"] = results["svg"]["transform"] || { count: 0, }; + results["svg"]["transform"].count++; + + for (i = 0; i < tValues.length; ++i) + { + results["svg"]["transform"][tValues[i]] = results["svg"]["transform"][tValues[i]] || { count: 0, }; + results["svg"]["transform"][tValues[i]].count++; + + results["svg"]["transform"][tValues[i]][tNodeName] = results["svg"]["transform"][tValues[i]][tNodeName] || { count: 0, }; + results["svg"]["transform"][tValues[i]][tNodeName].count++; + } + } + + // We have to check for the transform-style property first before checking its values, otherwise it will hit error. + var transformStyle = e.CSSUsage["transform-style"]; + if (transformStyle) + { + if (transformStyle.valuesArray.includes("preserve-3d")) + { + var tsNodeName = e.nodeName; + + results["svg"]["transform-style_preserve-3d"] = results["svg"]["transform-style_preserve-3d"] || { count: 0, }; + results["svg"]["transform-style_preserve-3d"].count++; + + results["svg"]["transform-style_preserve-3d"][tsNodeName] = results["svg"]["transform-style_preserve-3d"][tsNodeName] || { count: 0, }; + results["svg"]["transform-style_preserve-3d"][tsNodeName].count++; + } + } + } + + // Need to convert children HTML collection to array to combine with other children found. + children = children.concat(Array.from(e.children)); + } + } + ++level; + elementsToCheck = children; } - - var ancestryTree = ancestryTreeArray.join("-"); - - results["sticky"] = results["sticky"] || { count: 0, }; - results["sticky"].count++; - - results["sticky"][nodeName] = results["sticky"][nodeName] || { count: 0, }; - results["sticky"][nodeName].count++; - - results["sticky"][nodeName][ancestryTree] = results["sticky"][nodeName][ancestryTree] || { count: 0, }; - results["sticky"][nodeName][ancestryTree].count++; } return results; }); }(); -/* - RECIPE: z-index on static flex items - ------------------------------------------------------------- - Author: Francois Remy - Description: Get count of flex items who should create a stacking context but do not really -*/ - -void function() { - - window.CSSUsage.StyleWalker.recipesToRun.push( function zstaticflex(/*HTML DOM Element*/ element, results) { - if(!element.parentElement) return; - - // the problem happens if the element is a flex item with static position and non-auto z-index - if(getComputedStyle(element.parentElement).display != 'flex') return results; - if(getComputedStyle(element).position != 'static') return results; - if(getComputedStyle(element).zIndex != 'auto') { - results.likely = 1; - } - - // the problem might happen if z-index could ever be non-auto - if(element.CSSUsage["z-index"] && element.CSSUsage["z-index"].valuesArray.length > 0) { - results.possible = 1; - } - - }); -}(); - -// -// This file is only here to create the TSV -// necessary to collect the data from the crawler -// -void function() { - - /* String hash function - /* credits goes to http://erlycoder.com/49/javascript-hash-functions-to-convert-string-into-integer-hash- */ - const hashCodeOf = (str) => { - var hash = 5381; var char = 0; - for (var i = 0; i < str.length; i++) { - char = str.charCodeAt(i); - hash = ((hash << 5) + hash) + char; - } - return hash; - } - - var ua = navigator.userAgent; - var uaName = ua.indexOf('Edge')>=0 ? 'EDGE' :ua.indexOf('Chrome')>=0 ? 'CHROME' : 'FIREFOX'; - window.INSTRUMENTATION_RESULTS = { - UA: uaName, - UASTRING: ua, - UASTRING_HASH: hashCodeOf(ua), - URL: location.href, - TIMESTAMP: Date.now(), - css: {/* see CSSUsageResults */}, - html: {/* see HtmlUsageResults */}, - dom: {}, - scripts: {/* "bootstrap.js": 1 */}, - }; - window.INSTRUMENTATION_RESULTS_TSV = []; - - /* make the script work in the context of a webview */ - try { - var console = window.console || (window.console={log:function(){},warn:function(){},error:function(){}}); - console.unsafeLog = console.log; - console.log = function() { - try { - this.unsafeLog.apply(this,arguments); - } catch(ex) { - // ignore - } - }; - } catch (ex) { - // we tried... - } -}(); - -window.onCSSUsageResults = function onCSSUsageResults(CSSUsageResults) { - // Collect the results (css) - INSTRUMENTATION_RESULTS.css = CSSUsageResults; - INSTRUMENTATION_RESULTS.html = HtmlUsageResults; - INSTRUMENTATION_RESULTS.recipe = RecipeResults; - - // Convert it to a more efficient format - INSTRUMENTATION_RESULTS_TSV = convertToTSV(INSTRUMENTATION_RESULTS); - - // Remove tabs and new lines from the data - for(var i = INSTRUMENTATION_RESULTS_TSV.length; i--;) { - var row = INSTRUMENTATION_RESULTS_TSV[i]; - for(var j = row.length; j--;) { - row[j] = (''+row[j]).replace(/(\s|\r|\n)+/g, ' '); - } - } - - // Convert into one signle tsv file - var tsvString = INSTRUMENTATION_RESULTS_TSV.map((row) => (row.join('\t'))).join('\n'); - appendTSV(tsvString); - - // Add it to the document dom - function appendTSV(content) { - if(window.debugCSSUsage) console.log("Trying to append"); - var output = document.createElement('script'); - output.id = "css-usage-tsv-results"; - output.textContent = tsvString; - output.type = 'text/plain'; - document.querySelector('head').appendChild(output); - var successfulAppend = checkAppend(); - } - - function checkAppend() { - if(window.debugCSSUsage) if(window.debugCSSUsage) console.log("Checking append"); - var elem = document.getElementById('css-usage-tsv-results'); - if(elem === null) { - if(window.debugCSSUsage) console.log("Element not appended"); - if(window.debugCSSUsage) console.log("Trying to append again"); - appendTSV(); - } - else { - if(window.debugCSSUsage) console.log("Element successfully found"); - } - } - - /** convert the instrumentation results to a spreadsheet for analysis */ - function convertToTSV(INSTRUMENTATION_RESULTS) { - if(window.debugCSSUsage) console.log("Converting to TSV"); - - var VALUE_COLUMN = 4; - var finishedRows = []; - var currentRowTemplate = [ - INSTRUMENTATION_RESULTS.UA, - INSTRUMENTATION_RESULTS.UASTRING_HASH, - INSTRUMENTATION_RESULTS.URL, - INSTRUMENTATION_RESULTS.TIMESTAMP, - 0 - ]; - - currentRowTemplate.push('ua'); - convertToTSV({identifier: INSTRUMENTATION_RESULTS.UASTRING}); - currentRowTemplate.pop(); - - - - - - - - - - - currentRowTemplate.push('recipe'); - convertToTSV(INSTRUMENTATION_RESULTS['recipe']); - currentRowTemplate.pop(); - - var l = finishedRows[0].length; - finishedRows.sort((a,b) => { - for(var i = VALUE_COLUMN+1; ib[i]) return +1; - } - return 0; - }); - - return finishedRows; - - /** helper function doing the actual conversion */ - function convertToTSV(object) { - if(object==null || object==undefined || typeof object == 'number' || typeof object == 'string') { - finishedRows.push(new Row(currentRowTemplate, ''+object)); - } else { - for(var key in object) { - if({}.hasOwnProperty.call(object,key)) { - currentRowTemplate.push(key); - convertToTSV(object[key]); - currentRowTemplate.pop(); - } - } - } - } - - /** constructor for a row of our table */ - function Row(currentRowTemplate, value) { - - // Initialize an empty row with enough columns - var row = [ - /*UANAME: edge */'', - /*UASTRING: mozilla/5.0 (...) */'', - /*URL: http://.../... */'', - /*TIMESTAMP: 1445622257303 */'', - /*VALUE: 0|1|... */'', - /*DATATYPE: css|dom|html... */'', - /*SUBTYPE: props|types|api|... */'', - /*NAME: font-size|querySelector|... */'', - /*CONTEXT: count|values|... */'', - /*SUBCONTEXT: px|em|... */'', - /*... */'', - /*... */'', - ]; - - // Copy the column values from the template - for(var i = currentRowTemplate.length; i--;) { - row[i] = currentRowTemplate[i]; - } - - // Add the value to the row - row[VALUE_COLUMN] = value; - - return row; - } - - } +// +// This file is only here to create the TSV +// necessary to collect the data from the crawler +// +void function() { + + /* String hash function + /* credits goes to http://erlycoder.com/49/javascript-hash-functions-to-convert-string-into-integer-hash- */ + const hashCodeOf = (str) => { + var hash = 5381; var char = 0; + for (var i = 0; i < str.length; i++) { + char = str.charCodeAt(i); + hash = ((hash << 5) + hash) + char; + } + return hash; + } + + var ua = navigator.userAgent; + var uaName = ua.indexOf('Edge')>=0 ? 'EDGE' :ua.indexOf('Chrome')>=0 ? 'CHROME' : 'FIREFOX'; + window.INSTRUMENTATION_RESULTS = { + UA: uaName, + UASTRING: ua, + UASTRING_HASH: hashCodeOf(ua), + URL: location.href, + TIMESTAMP: Date.now(), + css: {/* see CSSUsageResults */}, + html: {/* see HtmlUsageResults */}, + dom: {}, + scripts: {/* "bootstrap.js": 1 */}, + }; + window.INSTRUMENTATION_RESULTS_TSV = []; + + /* make the script work in the context of a webview */ + try { + var console = window.console || (window.console={log:function(){},warn:function(){},error:function(){}}); + console.unsafeLog = console.log; + console.log = function() { + try { + this.unsafeLog.apply(this,arguments); + } catch(ex) { + // ignore + } + }; + } catch (ex) { + // we tried... + } +}(); + +window.onCSSUsageResults = function onCSSUsageResults(CSSUsageResults) { + // Collect the results (css) + INSTRUMENTATION_RESULTS.css = CSSUsageResults; + INSTRUMENTATION_RESULTS.html = HtmlUsageResults; + INSTRUMENTATION_RESULTS.recipe = RecipeResults; + + // Convert it to a more efficient format + INSTRUMENTATION_RESULTS_TSV = convertToTSV(INSTRUMENTATION_RESULTS); + + // Remove tabs and new lines from the data + for(var i = INSTRUMENTATION_RESULTS_TSV.length; i--;) { + var row = INSTRUMENTATION_RESULTS_TSV[i]; + for(var j = row.length; j--;) { + row[j] = (''+row[j]).replace(/(\s|\r|\n)+/g, ' '); + } + } + + // Convert into one signle tsv file + var tsvString = INSTRUMENTATION_RESULTS_TSV.map((row) => (row.join('\t'))).join('\n'); + appendTSV(tsvString); + + // Add it to the document dom + function appendTSV(content) { + if(window.debugCSSUsage) console.log("Trying to append"); + var output = document.createElement('script'); + output.id = "css-usage-tsv-results"; + output.textContent = tsvString; + output.type = 'text/plain'; + document.querySelector('head').appendChild(output); + var successfulAppend = checkAppend(); + } + + function checkAppend() { + if(window.debugCSSUsage) if(window.debugCSSUsage) console.log("Checking append"); + var elem = document.getElementById('css-usage-tsv-results'); + if(elem === null) { + if(window.debugCSSUsage) console.log("Element not appended"); + if(window.debugCSSUsage) console.log("Trying to append again"); + appendTSV(); + } + else { + if(window.debugCSSUsage) console.log("Element successfully found"); + } + } + + /** convert the instrumentation results to a spreadsheet for analysis */ + function convertToTSV(INSTRUMENTATION_RESULTS) { + if(window.debugCSSUsage) console.log("Converting to TSV"); + + var VALUE_COLUMN = 4; + var finishedRows = []; + var currentRowTemplate = [ + INSTRUMENTATION_RESULTS.UA, + INSTRUMENTATION_RESULTS.UASTRING_HASH, + INSTRUMENTATION_RESULTS.URL, + INSTRUMENTATION_RESULTS.TIMESTAMP, + 0 + ]; + + currentRowTemplate.push('ua'); + convertToTSV({identifier: INSTRUMENTATION_RESULTS.UASTRING}); + currentRowTemplate.pop(); + + + + + + + + + + + currentRowTemplate.push('recipe'); + convertToTSV(INSTRUMENTATION_RESULTS['recipe']); + currentRowTemplate.pop(); + + var l = finishedRows[0].length; + finishedRows.sort((a,b) => { + for(var i = VALUE_COLUMN+1; ib[i]) return +1; + } + return 0; + }); + + return finishedRows; + + /** helper function doing the actual conversion */ + function convertToTSV(object) { + if(object==null || object==undefined || typeof object == 'number' || typeof object == 'string') { + finishedRows.push(new Row(currentRowTemplate, ''+object)); + } else { + for(var key in object) { + if({}.hasOwnProperty.call(object,key)) { + currentRowTemplate.push(key); + convertToTSV(object[key]); + currentRowTemplate.pop(); + } + } + } + } + + /** constructor for a row of our table */ + function Row(currentRowTemplate, value) { + + // Initialize an empty row with enough columns + var row = [ + /*UANAME: edge */'', + /*UASTRING: mozilla/5.0 (...) */'', + /*URL: http://.../... */'', + /*TIMESTAMP: 1445622257303 */'', + /*VALUE: 0|1|... */'', + /*DATATYPE: css|dom|html... */'', + /*SUBTYPE: props|types|api|... */'', + /*NAME: font-size|querySelector|... */'', + /*CONTEXT: count|values|... */'', + /*SUBCONTEXT: px|em|... */'', + /*... */'', + /*... */'', + ]; + + // Copy the column values from the template + for(var i = currentRowTemplate.length; i--;) { + row[i] = currentRowTemplate[i]; + } + + // Add the value to the row + row[VALUE_COLUMN] = value; + + return row; + } + + } }; // // Execution scheduler: diff --git a/cssUsage.src.js b/cssUsage.src.js index b4c776e..0776040 100644 --- a/cssUsage.src.js +++ b/cssUsage.src.js @@ -1541,141 +1541,88 @@ void function() { try { } catch (ex) { /* do something maybe */ throw ex; } }(); /* - RECIPE: object_fit_object_position + RECIPE: svg_css-transform_preserve-3d ------------------------------------------------------------- Author: joevery - Description: Get count of how many times object-fit and object-position CSS properties are used on websites and classify by HTML tag. + Description: Get count of svg elements on page along with how many contain the transform CSS property and the transform-style CSS property with value preserve-3d in their namespace. + In addition, we want to classify the number of elements that have either of these CSS properties applied by the HTML tags they are applied to. */ void function() { window.CSSUsage.StyleWalker.recipesToRun.push( - function object_fit_object_position(element, results) - { - // Need this to ensure no errors on html and head tags when running the code below. - if (!element.CSSUsage) return; - - if (element.CSSUsage["object-fit"]) - { - // Allows counting of number of HTML tags using object-fit CSS property on page. - results["object-fit"] = results["object-fit"] || { count: 0, }; - results["object-fit"].count++; - - // Classify count by HTML tag. - var nodeName = element.nodeName; - results["object-fit"][nodeName] = results["object-fit"][nodeName] || { count: 0, }; - results["object-fit"][nodeName].count++; - } - - if (element.CSSUsage["object-position"]) - { - // Allows counting of number of HTML tags using object-position CSS property on page. - results["object-position"] = results["object-position"] || { count: 0, }; - results["object-position"].count++; - - // Classify count by HTML tag. - var nodeName = element.nodeName; - results["object-position"][nodeName] = results["object-position"][nodeName] || { count: 0, }; - results["object-position"][nodeName].count++; - } - - return results; - }); -}(); - -/* - RECIPE: object_fit_onvideo - ------------------------------------------------------------- - Author: joevery - Description: Get count of how many times object-fit CSS property is used on a video element on websites. -*/ -void function() { - window.CSSUsage.StyleWalker.recipesToRun.push( - function object_fit_onvideo(element, results) + function svg_css_transform_preserve_3d(element, results) { var nodeName = element.nodeName; - if (nodeName == "VIDEO") + if (nodeName == "svg") { - if (element.CSSUsage["object-fit"]) - { - var key = "VIDEO" + "_" + "object-fit"; - results[key] = results[key] || { count: 0, }; - results[key].count++; - } - } - return results; - }); -}(); + results["svg"] = results["svg"] || { count: 0, }; + results["svg"].count++; -/* - RECIPE: position-sticky_ancestry-tree - ------------------------------------------------------------- - Author: joevery - Description: Get count of how many times position CSS property with value sticky are used on websites and classify by HTML tag. -*/ -void function() { - window.CSSUsage.StyleWalker.recipesToRun.push( - function position_sticky_ancestry_tree(element, results) - { - // Need this to ensure no errors on html and head tags when running the code below. - if (!element.CSSUsage) return; + var elementsToCheck = [element]; + var level = 0; - if (element.CSSUsage["position"] == "sticky") - { - var nodeName = element.nodeName; - - var ancestryTreeArray = [nodeName]; - - var currentParent = element.parentElement; - - while (currentParent) + while (elementsToCheck.length > 0) { - ancestryTreeArray.push(currentParent.nodeName); - currentParent = currentParent.parentElement; + var children = []; + + for (var i = 0; i < elementsToCheck.length; ++i) + { + var e = elementsToCheck[i]; + + // We want to skip nested svg elements and do them later, but of course do the one we just found. + if (e.nodeName != "svg" || level == 0) + { + // If no CSS on element, then don't do what is inside if statement, otherwise it will hit error. + if (e.CSSUsage) + { + if (e.CSSUsage["transform"]) + { + var tNodeName = e.nodeName; + var tValues = e.CSSUsage["transform"]; + + results["svg"]["transform"] = results["svg"]["transform"] || { count: 0, }; + results["svg"]["transform"].count++; + + for (i = 0; i < tValues.length; ++i) + { + results["svg"]["transform"][tValues[i]] = results["svg"]["transform"][tValues[i]] || { count: 0, }; + results["svg"]["transform"][tValues[i]].count++; + + results["svg"]["transform"][tValues[i]][tNodeName] = results["svg"]["transform"][tValues[i]][tNodeName] || { count: 0, }; + results["svg"]["transform"][tValues[i]][tNodeName].count++; + } + } + + // We have to check for the transform-style property first before checking its values, otherwise it will hit error. + var transformStyle = e.CSSUsage["transform-style"]; + if (transformStyle) + { + if (transformStyle.valuesArray.includes("preserve-3d")) + { + var tsNodeName = e.nodeName; + + results["svg"]["transform-style_preserve-3d"] = results["svg"]["transform-style_preserve-3d"] || { count: 0, }; + results["svg"]["transform-style_preserve-3d"].count++; + + results["svg"]["transform-style_preserve-3d"][tsNodeName] = results["svg"]["transform-style_preserve-3d"][tsNodeName] || { count: 0, }; + results["svg"]["transform-style_preserve-3d"][tsNodeName].count++; + } + } + } + + // Need to convert children HTML collection to array to combine with other children found. + children = children.concat(Array.from(e.children)); + } + } + ++level; + elementsToCheck = children; } - - var ancestryTree = ancestryTreeArray.join("-"); - - results["sticky"] = results["sticky"] || { count: 0, }; - results["sticky"].count++; - - results["sticky"][nodeName] = results["sticky"][nodeName] || { count: 0, }; - results["sticky"][nodeName].count++; - - results["sticky"][nodeName][ancestryTree] = results["sticky"][nodeName][ancestryTree] || { count: 0, }; - results["sticky"][nodeName][ancestryTree].count++; } return results; }); }(); -/* - RECIPE: z-index on static flex items - ------------------------------------------------------------- - Author: Francois Remy - Description: Get count of flex items who should create a stacking context but do not really -*/ - -void function() { - - window.CSSUsage.StyleWalker.recipesToRun.push( function zstaticflex(/*HTML DOM Element*/ element, results) { - if(!element.parentElement) return; - - // the problem happens if the element is a flex item with static position and non-auto z-index - if(getComputedStyle(element.parentElement).display != 'flex') return results; - if(getComputedStyle(element).position != 'static') return results; - if(getComputedStyle(element).zIndex != 'auto') { - results.likely = 1; - } - - // the problem might happen if z-index could ever be non-auto - if(element.CSSUsage["z-index"] && element.CSSUsage["z-index"].valuesArray.length > 0) { - results.possible = 1; - } - - }); -}(); - // // This file is only here to create the TSV // necessary to collect the data from the crawler diff --git a/src/recipes/object-fit-onvideo.js b/src/recipes/object-fit-onvideo.js deleted file mode 100644 index b23cae6..0000000 --- a/src/recipes/object-fit-onvideo.js +++ /dev/null @@ -1,24 +0,0 @@ -/* - RECIPE: object_fit_onvideo - ------------------------------------------------------------- - Author: joevery - Description: Get count of how many times object-fit CSS property is used on a video element on websites. -*/ -void function() { - window.CSSUsage.StyleWalker.recipesToRun.push( - function object_fit_onvideo(element, results) - { - var nodeName = element.nodeName; - - if (nodeName == "VIDEO") - { - if (element.CSSUsage["object-fit"]) - { - var key = "VIDEO" + "_" + "object-fit"; - results[key] = results[key] || { count: 0, }; - results[key].count++; - } - } - return results; - }); -}(); diff --git a/src/recipes/object-fit_object-position.js b/src/recipes/object-fit_object-position.js deleted file mode 100644 index 15b6e9e..0000000 --- a/src/recipes/object-fit_object-position.js +++ /dev/null @@ -1,40 +0,0 @@ -/* - RECIPE: object_fit_object_position - ------------------------------------------------------------- - Author: joevery - Description: Get count of how many times object-fit and object-position CSS properties are used on websites and classify by HTML tag. -*/ -void function() { - window.CSSUsage.StyleWalker.recipesToRun.push( - function object_fit_object_position(element, results) - { - // Need this to ensure no errors on html and head tags when running the code below. - if (!element.CSSUsage) return; - - if (element.CSSUsage["object-fit"]) - { - // Allows counting of number of HTML tags using object-fit CSS property on page. - results["object-fit"] = results["object-fit"] || { count: 0, }; - results["object-fit"].count++; - - // Classify count by HTML tag. - var nodeName = element.nodeName; - results["object-fit"][nodeName] = results["object-fit"][nodeName] || { count: 0, }; - results["object-fit"][nodeName].count++; - } - - if (element.CSSUsage["object-position"]) - { - // Allows counting of number of HTML tags using object-position CSS property on page. - results["object-position"] = results["object-position"] || { count: 0, }; - results["object-position"].count++; - - // Classify count by HTML tag. - var nodeName = element.nodeName; - results["object-position"][nodeName] = results["object-position"][nodeName] || { count: 0, }; - results["object-position"][nodeName].count++; - } - - return results; - }); -}(); diff --git a/src/recipes/position-sticky_ancestry-tree.js b/src/recipes/position-sticky_ancestry-tree.js deleted file mode 100644 index da38465..0000000 --- a/src/recipes/position-sticky_ancestry-tree.js +++ /dev/null @@ -1,42 +0,0 @@ -/* - RECIPE: position-sticky_ancestry-tree - ------------------------------------------------------------- - Author: joevery - Description: Get count of how many times position CSS property with value sticky are used on websites and classify by HTML tag. -*/ -void function() { - window.CSSUsage.StyleWalker.recipesToRun.push( - function position_sticky_ancestry_tree(element, results) - { - // Need this to ensure no errors on html and head tags when running the code below. - if (!element.CSSUsage) return; - - if (element.CSSUsage["position"] == "sticky") - { - var nodeName = element.nodeName; - - var ancestryTreeArray = [nodeName]; - - var currentParent = element.parentElement; - - while (currentParent) - { - ancestryTreeArray.push(currentParent.nodeName); - currentParent = currentParent.parentElement; - } - - var ancestryTree = ancestryTreeArray.join("-"); - - results["sticky"] = results["sticky"] || { count: 0, }; - results["sticky"].count++; - - results["sticky"][nodeName] = results["sticky"][nodeName] || { count: 0, }; - results["sticky"][nodeName].count++; - - results["sticky"][nodeName][ancestryTree] = results["sticky"][nodeName][ancestryTree] || { count: 0, }; - results["sticky"][nodeName][ancestryTree].count++; - } - - return results; - }); -}(); diff --git a/src/recipes/svg_css-transform_preserve-3d.js b/src/recipes/svg_css-transform_preserve-3d.js new file mode 100644 index 0000000..b4361c3 --- /dev/null +++ b/src/recipes/svg_css-transform_preserve-3d.js @@ -0,0 +1,82 @@ +/* + RECIPE: svg_css-transform_preserve-3d + ------------------------------------------------------------- + Author: joevery + Description: Get count of svg elements on page along with how many contain the transform CSS property and the transform-style CSS property with value preserve-3d in their namespace. + In addition, we want to classify the number of elements that have either of these CSS properties applied by the HTML tags they are applied to. +*/ +void function() { + window.CSSUsage.StyleWalker.recipesToRun.push( + function svg_css_transform_preserve_3d(element, results) + { + var nodeName = element.nodeName; + + if (nodeName == "svg") + { + results["svg"] = results["svg"] || { count: 0, }; + results["svg"].count++; + + var elementsToCheck = [element]; + var level = 0; + + while (elementsToCheck.length > 0) + { + var children = []; + + for (var i = 0; i < elementsToCheck.length; ++i) + { + var e = elementsToCheck[i]; + + // We want to skip nested svg elements and do them later, but of course do the one we just found. + if (e.nodeName != "svg" || level == 0) + { + // If no CSS on element, then don't do what is inside if statement, otherwise it will hit error. + if (e.CSSUsage) + { + if (e.CSSUsage["transform"]) + { + var tNodeName = e.nodeName; + var tValues = e.CSSUsage["transform"]; + + results["svg"]["transform"] = results["svg"]["transform"] || { count: 0, }; + results["svg"]["transform"].count++; + + for (i = 0; i < tValues.length; ++i) + { + results["svg"]["transform"][tValues[i]] = results["svg"]["transform"][tValues[i]] || { count: 0, }; + results["svg"]["transform"][tValues[i]].count++; + + results["svg"]["transform"][tValues[i]][tNodeName] = results["svg"]["transform"][tValues[i]][tNodeName] || { count: 0, }; + results["svg"]["transform"][tValues[i]][tNodeName].count++; + } + } + + // We have to check for the transform-style property first before checking its values, otherwise it will hit error. + var transformStyle = e.CSSUsage["transform-style"]; + if (transformStyle) + { + if (transformStyle.valuesArray.includes("preserve-3d")) + { + var tsNodeName = e.nodeName; + + results["svg"]["transform-style_preserve-3d"] = results["svg"]["transform-style_preserve-3d"] || { count: 0, }; + results["svg"]["transform-style_preserve-3d"].count++; + + results["svg"]["transform-style_preserve-3d"][tsNodeName] = results["svg"]["transform-style_preserve-3d"][tsNodeName] || { count: 0, }; + results["svg"]["transform-style_preserve-3d"][tsNodeName].count++; + } + } + } + + // Need to convert children HTML collection to array to combine with other children found. + children = children.concat(Array.from(e.children)); + } + } + ++level; + elementsToCheck = children; + } + } + + return results; + }); +}(); diff --git a/src/recipes/zstaticflex.js b/src/recipes/zstaticflex.js deleted file mode 100644 index 31ebec7..0000000 --- a/src/recipes/zstaticflex.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - RECIPE: z-index on static flex items - ------------------------------------------------------------- - Author: Francois Remy - Description: Get count of flex items who should create a stacking context but do not really -*/ - -void function() { - - window.CSSUsage.StyleWalker.recipesToRun.push( function zstaticflex(/*HTML DOM Element*/ element, results) { - if(!element.parentElement) return; - - // the problem happens if the element is a flex item with static position and non-auto z-index - if(getComputedStyle(element.parentElement).display != 'flex') return results; - if(getComputedStyle(element).position != 'static') return results; - if(getComputedStyle(element).zIndex != 'auto') { - results.likely = 1; - } - - // the problem might happen if z-index could ever be non-auto - if(element.CSSUsage["z-index"] && element.CSSUsage["z-index"].valuesArray.length > 0) { - results.possible = 1; - } - - }); -}(); diff --git a/tests/recipes/object-fit-onvideo.html b/tests/recipes/object-fit-onvideo.html deleted file mode 100644 index 52e968e..0000000 --- a/tests/recipes/object-fit-onvideo.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - Object fit on video element test - - - - - -
-

Object fit on video element test

-
- -
-
- - \ No newline at end of file diff --git a/tests/recipes/object-fit_object-position.html b/tests/recipes/object-fit_object-position.html deleted file mode 100644 index 7a95633..0000000 --- a/tests/recipes/object-fit_object-position.html +++ /dev/null @@ -1,35 +0,0 @@ - - - - Object fit and object position test - - - - - -
-

Object fit and object position test

-
- - -
-
- - -
-
- - - -
-
- - \ No newline at end of file diff --git a/tests/recipes/position-sticky_ancestry-tree.html b/tests/recipes/position-sticky_ancestry-tree.html deleted file mode 100644 index a47867e..0000000 --- a/tests/recipes/position-sticky_ancestry-tree.html +++ /dev/null @@ -1,106 +0,0 @@ - - - - Position-sticky ancestry tree test - - - - -
-
-
A-sticky-label
-
Andrew W.K.
-
Apparat
-
Arcade Fire
-
At The Drive-In
-
Aziz Ansari
-
Andrew W.K.
-
Apparat
-
Arcade Fire
-
At The Drive-In
-
Aziz Ansari
-
-
-
C
-
Chromeo
-
Common
-
Converge
-
Crystal Castles
-
Cursive
-
Chromeo
-
Common
-
Converge
-
Crystal Castles
-
Cursive
-
-
-
E
-
Explosions In The Sky
-
Explosions In The Sky
-
Explosions In The Sky
-
Explosions In The Sky
-
Explosions In The Sky
-
Explosions In The Sky
-
Explosions In The Sky
-
Explosions In The Sky
-
Explosions In The Sky
-
Explosions In The Sky
-
Explosions In The Sky
-
-
-
T
-
Ted Leo & The Pharmacists
-
T-Pain
-
Thrice
-
TV On The Radio
-
Two Gallants
-
Ted Leo & The Pharmacists
-
T-Pain
-
Thrice
-
TV On The Radio
-
Two Gallants
-
Ted Leo & The Pharmacists
-
T-Pain
-
Thrice
-
TV On The Radio
-
Two Gallants
-
-
- - \ No newline at end of file diff --git a/tests/recipes/svg_css-transform_preserve-3d.html b/tests/recipes/svg_css-transform_preserve-3d.html new file mode 100644 index 0000000..4b0aff0 --- /dev/null +++ b/tests/recipes/svg_css-transform_preserve-3d.html @@ -0,0 +1,36 @@ + + + + SVG CSS transform and preserve-3d test + + + + + + + + YAY!!!!!!!!!!! + + + + + + + + + + \ No newline at end of file