Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Background-Position Crawler Recipe #59

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
2,273 changes: 216 additions & 2,057 deletions Recipe.min.js

Large diffs are not rendered by default.

532 changes: 274 additions & 258 deletions cssUsage.src.js

Large diffs are not rendered by default.

2,845 changes: 2,845 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
"mocha": "^2.2.5",
"requirejs": "^2.1.18"
}
}
}
2,086 changes: 2,086 additions & 0 deletions src/recipes/WebP.js

Large diffs are not rendered by default.

272 changes: 272 additions & 0 deletions src/recipes/negative-background-position.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
/*
JSAPI RECIPE: WebGL Function Calls
-------------------------------------------------------------
Author: adyoun
Description: Counting the number of times each WebGL function is called
*/

window.functionList =
[
["activeTexture", 0],
["attachShader", 0],
["bindAttribLocation", 0],
["bindBuffer", 0],
["bindFramebuffer", 0],
["bindRenderbuffer", 0],
["bindTexture", 0],
["blendColor", 0],
["blendEquation", 0],
["blendEquationSeparate", 0],
["blendFunc", 0],
["blendFuncSeparate", 0],
["bufferData", 0],
["bufferSubData", 0],
["checkFramebufferStatus", 0],
["clear", 0],
["clearColor", 0],
["clearDepth", 0],
["clearStencil", 0],
["colorMask", 0],
["compileShader", 0],
["copyTexImage2D", 0],
["copyTexSubImage2D", 0],
["createBuffer", 0],
["createByteArray", 0],
["createFloatArray", 0],
["createFramebuffer", 0],
["createIntArray", 0],
["createProgram", 0],
["createRenderbuffer", 0],
["createShader", 0],
["createShortArray", 0],
["createTexture", 0],
["createUnsignedByteArray", 0],
["createUnsignedIntArray", 0],
["createUnsignedShortArray", 0],
["cullFace", 0],
["deleteBuffer", 0],
["deleteFramebuffer", 0],
["deleteProgram", 0],
["deleteRenderbuffer", 0],
["deleteShader", 0],
["deleteTexture", 0],
["depthFunc", 0],
["depthMask", 0],
["depthRange", 0],
["detachShader", 0],
["disable", 0],
["disableVertexAttribArray", 0],
["drawArrays", 0],
["drawElements", 0],
["enable", 0],
["enableVertexAttribArray", 0],
["finish", 0],
["flush", 0],
["framebufferRenderbuffer", 0],
["framebufferTexture2D", 0],
["frontFace", 0],
["generateMipmap", 0],
["getActiveAttrib", 0],
["getActiveUniform", 0],
["getAttachedShaders", 0],
["getAttribLocation", 0],
["getBufferParameter", 0],
["getError", 0],
["getFramebufferAttachmentParameter", 0],
["getProgramInfoLog", 0],
["getProgramParameter", 0],
["getRenderbufferParameter", 0],
["getShaderInfoLog", 0],
["getShaderParameter", 0],
["getShaderSource", 0],
["getTexParameter", 0],
["getUniform", 0],
["getUniformLocation", 0],
["getVertexAttrib", 0],
["isBuffer", 0],
["isBuffergetParameter", 0],
["isFramebuffer", 0],
["isProgram", 0],
["isRenderbuffer", 0],
["isShader", 0],
["isTexture", 0],
["lineWidth", 0],
["linkProgram", 0],
["pixelStorei", 0],
["polygonOffset", 0],
["readPixels", 0],
["renderbufferStorage", 0],
["sampleCoverage", 0],
["scissor", 0],
["shaderSource", 0],
["stencilFunc", 0],
["stencilFuncSeparate", 0],
["stencilMask", 0],
["stencilMaskSeparate", 0],
["stencilOp", 0],
["stencilOpSeparate", 0],
["texImage2D", 0],
["texParameterf", 0],
["texParameteri", 0],
["texSubImage2D", 0],
["uniform1f", 0],
["uniform1fv", 0],
["uniform1i", 0],
["uniform1iv", 0],
["uniform2f", 0],
["uniform2fv", 0],
["uniform2i", 0],
["uniform2iv", 0],
["uniform3f", 0],
["uniform3fv", 0],
["uniform3i", 0],
["uniform3iv", 0],
["uniform4f", 0],
["uniform4fv", 0],
["uniform4i", 0],
["uniform4iv", 0],
["uniformMatrix2fv", 0],
["uniformMatrix3fv", 0],
["uniformMatrix4fv", 0],
["useProgram", 0],
["validateProgram", 0],
["vertexAttrib1f", 0],
["vertexAttrib1fv", 0],
["vertexAttrib2f", 0],
["vertexAttrib2fv", 0],
["vertexAttrib3f", 0],
["vertexAttrib3fv", 0],
["vertexAttrib4f", 0],
["vertexAttrib4fv", 0],
["vertexAttribPointer", 0],
["viewport", 0]
];

var functionMap = new Map();

for (var i = 0; i < window.functionList.length; i++)
{

WebGLRenderingContext.prototype["_" + window.functionList[i][0]] = WebGLRenderingContext.prototype[window.functionList[i][0]];

WebGLRenderingContext.prototype[window.functionList[i][0]] = function() {
var index = functionMap.get(arguments.callee);
window.functionList[index][1] = window.functionList[index][1] + 1;

switch(arguments.length)
{
case 0:
return this["_" + window.functionList[index][0]]();
case 1:
return this["_" + window.functionList[index][0]](arguments[0]);
case 2:
return this["_" + window.functionList[index][0]](arguments[0], arguments[1]);
case 3:
return this["_" + window.functionList[index][0]](arguments[0], arguments[1], arguments[2]);
case 4:
return this["_" + window.functionList[index][0]](arguments[0], arguments[1], arguments[2], arguments[3]);
case 5:
return this["_" + window.functionList[index][0]](arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]);
case 6:
return this["_" + window.functionList[index][0]](arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]);
case 7:
return this["_" + window.functionList[index][0]](arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6]);
case 8:
return this["_" + window.functionList[index][0]](arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7]);
case 9:
return this["_" + window.functionList[index][0]](arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], arguments[8]);
}
}

functionMap.set(WebGLRenderingContext.prototype[window.functionList[i][0]], i);
}

window.getContextCounter = 0;

HTMLCanvasElement.prototype._getContext = HTMLCanvasElement.prototype.getContext;
HTMLCanvasElement.prototype.getContext = function (a) {
var lowerCase = a.toLowerCase();
if (lowerCase.includes("webgl"))
{
window.getContextCounter = window.getContextCounter + 1;
}
return this._getContext(a);
};


var getParameterMap = new Map();
window.getParameterCounter = 0;
WebGLRenderingContext.prototype._getParameter = WebGLRenderingContext.prototype.getParameter;
WebGLRenderingContext.prototype.getParameter = function (a) {
if (getParameterMap.get(a) != undefined)
{
getParameterMap.set(a, getParameterMap.get(a) + 1);
}
else
{
getParameterMap.set(a, 1);
}

window.getParameterCounter = window.getParameterCounter + 1

return this._getParameter(a);
}

void function () {
document.addEventListener('DOMContentLoaded', function () {
console.log("Logging");
var results = {};
var recipeName = "WebGL_Function_Counter";
results[recipeName] = results[recipeName] || { href: location.href, };

for (var i = 0; i < window.functionList.length; i++)
{
results[recipeName][window.functionList[i][0]] = results[recipeName][window.functionList[i][0]] || {count: window.functionList[i][1]};
}

/*
var k = Object.keys(getParameterMap);
for (var i = 0; i < k.length; i++) {
results[recipeName]["getParameterParameter" + k[i]] = results[recipeName]["getParameterParameter" + k[i]] || {count: getParameterMap.get(k[i])};
}
*/

/*
for (const key in getParameterMap) {
results[recipeName]["getParameterParameter" + key] = results[recipeName]["getParameterParameter" + key] || {count: getParameterMap.get(key)};
}
*/

for (var [key, value] of getParameterMap) {
results[recipeName]["getParameterParameter" + key] = results[recipeName]["getParameterParameter" + key] || {count: value};
}

results[recipeName]["getContext"] = results[recipeName]["getContext"] || {count: window.getContextCounter};
results[recipeName]["getParameter"] = results[recipeName]["getParameter"] || {count: window.getParameterCounter};

appendResults(results);

// Add it to the document dom
function appendResults(results) {
if (window.debugCSSUsage) console.log("Trying to append");
var output = document.createElement('script');
output.id = "css-usage-tsv-results";
output.textContent = JSON.stringify(results);
output.type = 'text/plain';
document.querySelector('head').appendChild(output);
var successfulAppend = checkAppend();
}

function checkAppend() {
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");
}
else {
if (window.debugCSSUsage) console.log("Element successfully found");
}
}

});
}();
23 changes: 23 additions & 0 deletions tests/recipes/negative-background-position.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Negative Background Position Test</title>
<link type="text/css" href="../test-page/style.css" media="all" rel="stylesheet" />
<style>
.neg_bgp {
color: red;
background-position: bottom -10px right;
position: fixed;
}
</style>
<script src="../../Recipe.min.js"></script>
</head>
<body>
<div class="wrapper">
<h1>Negative Background Position Test</h1>
<div id="nested-div" class="neg_bgp" height="300" width = "300">
<p>Here's some text</p>
</div>
</div>
</body>
</html>