Skip to content

Commit

Permalink
Moved attributes and CSS to main package
Browse files Browse the repository at this point in the history
  • Loading branch information
Jyyjy committed Aug 20, 2024
1 parent bda79c6 commit 4eec2ff
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 183 deletions.
43 changes: 43 additions & 0 deletions build/UserALEWebExtension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ function packageLog(e, detailFcn) {
sessionId: config$1.sessionId,
httpSessionId: config$1.httpSessionId,
browserSessionId: config$1.browserSessionId,
attributes: buildAttrs(e),
style: buildCSS(e),
};
for (const func of Object.values(cbHandlers)) {
if (typeof func === "function") {
Expand Down Expand Up @@ -855,6 +857,47 @@ function detectBrowser() {
version: browserInfo ? browserInfo.version : "",
};
}
/**
* Builds an object containing attributes of an element.
* Attempts to parse all attribute values as JSON text.
* @param {Event} e Event from which the target element's attributes should be extracted.
* @return {Record<string, any>} Object with element attributes as key-value pairs.
*/
function buildAttrs(e) {
const attributes = {};
const attributeBlackList = ["style"];
if (e.target && e.target instanceof Element) {
for (const attr of e.target.attributes) {
if (attributeBlackList.includes(attr.name))
continue;
let val = attr.value;
try {
val = JSON.parse(val);
}
catch (error) {
// Ignore parsing errors, fallback to raw string value
}
attributes[attr.name] = val;
}
}
return attributes;
}
/**
* Builds an object containing all CSS properties of an element.
* @param {Event} e Event from which the target element's properties should be extracted.
* @return {Record<string, string>} Object with all CSS properties as key-value pairs.
*/
function buildCSS(e) {
const properties = {};
if (e.target && e.target instanceof HTMLElement) {
const styleObj = e.target.style;
for (let i = 0; i < styleObj.length; i++) {
const prop = styleObj[i];
properties[prop] = styleObj.getPropertyValue(prop);
}
}
return properties;
}

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down
43 changes: 43 additions & 0 deletions build/UserALEWebExtension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ function packageLog(e, detailFcn) {
sessionId: config$1.sessionId,
httpSessionId: config$1.httpSessionId,
browserSessionId: config$1.browserSessionId,
attributes: buildAttrs(e),
style: buildCSS(e),
};
for (const func of Object.values(cbHandlers)) {
if (typeof func === "function") {
Expand Down Expand Up @@ -802,6 +804,47 @@ function detectBrowser() {
version: browserInfo ? browserInfo.version : "",
};
}
/**
* Builds an object containing attributes of an element.
* Attempts to parse all attribute values as JSON text.
* @param {Event} e Event from which the target element's attributes should be extracted.
* @return {Record<string, any>} Object with element attributes as key-value pairs.
*/
function buildAttrs(e) {
const attributes = {};
const attributeBlackList = ["style"];
if (e.target && e.target instanceof Element) {
for (const attr of e.target.attributes) {
if (attributeBlackList.includes(attr.name))
continue;
let val = attr.value;
try {
val = JSON.parse(val);
}
catch (error) {
// Ignore parsing errors, fallback to raw string value
}
attributes[attr.name] = val;
}
}
return attributes;
}
/**
* Builds an object containing all CSS properties of an element.
* @param {Event} e Event from which the target element's properties should be extracted.
* @return {Record<string, string>} Object with all CSS properties as key-value pairs.
*/
function buildCSS(e) {
const properties = {};
if (e.target && e.target instanceof HTMLElement) {
const styleObj = e.target.style;
for (let i = 0; i < styleObj.length; i++) {
const prop = styleObj[i];
properties[prop] = styleObj.getPropertyValue(prop);
}
}
return properties;
}

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down
43 changes: 43 additions & 0 deletions build/UserALEWebExtension/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,8 @@ function packageLog(e, detailFcn) {
sessionId: config$1.sessionId,
httpSessionId: config$1.httpSessionId,
browserSessionId: config$1.browserSessionId,
attributes: buildAttrs(e),
style: buildCSS(e),
};
for (const func of Object.values(cbHandlers)) {
if (typeof func === "function") {
Expand Down Expand Up @@ -802,6 +804,47 @@ function detectBrowser() {
version: browserInfo ? browserInfo.version : "",
};
}
/**
* Builds an object containing attributes of an element.
* Attempts to parse all attribute values as JSON text.
* @param {Event} e Event from which the target element's attributes should be extracted.
* @return {Record<string, any>} Object with element attributes as key-value pairs.
*/
function buildAttrs(e) {
const attributes = {};
const attributeBlackList = ["style"];
if (e.target && e.target instanceof Element) {
for (const attr of e.target.attributes) {
if (attributeBlackList.includes(attr.name))
continue;
let val = attr.value;
try {
val = JSON.parse(val);
}
catch (error) {
// Ignore parsing errors, fallback to raw string value
}
attributes[attr.name] = val;
}
}
return attributes;
}
/**
* Builds an object containing all CSS properties of an element.
* @param {Event} e Event from which the target element's properties should be extracted.
* @return {Record<string, string>} Object with all CSS properties as key-value pairs.
*/
function buildCSS(e) {
const properties = {};
if (e.target && e.target instanceof HTMLElement) {
const styleObj = e.target.style;
for (let i = 0; i < styleObj.length; i++) {
const prop = styleObj[i];
properties[prop] = styleObj.getPropertyValue(prop);
}
}
return properties;
}

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down
13 changes: 13 additions & 0 deletions build/packageLogs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,16 @@ export declare function detectBrowser(): {
browser: string;
version: string | null;
};
/**
* Builds an object containing attributes of an element.
* Attempts to parse all attribute values as JSON text.
* @param {Event} e Event from which the target element's attributes should be extracted.
* @return {Record<string, any>} Object with element attributes as key-value pairs.
*/
export declare function buildAttrs(e: Event): Record<string, any>;
/**
* Builds an object containing all CSS properties of an element.
* @param {Event} e Event from which the target element's properties should be extracted.
* @return {Record<string, string>} Object with all CSS properties as key-value pairs.
*/
export declare function buildCSS(e: Event): Record<string, string>;
43 changes: 43 additions & 0 deletions build/userale-2.4.0.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/userale-2.4.0.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 4eec2ff

Please sign in to comment.