I am working on addon which can swap columns (divs). This is archieved by 1) analysing divs positions and 2) analysing styles. Before I can apply new (absolute) position of the divs, I must to remove the classes which give the position:absolute, left: …, right: …, top: … or bottom: … positions and float: being set to “non-none”. So I need to analyse the classes or even div’s id.
The code looks like this:
var selectors = "div.fauxcolumn-right-outer;div.fauxcolumn-center-outer"
var selectors = selectors.split(";");
var searches = [];
var targets = [];
for ( var k in selectors )
{
if ( (k % 2) == 0 )
searches.push(selectors[k]);
else
targets.push(selectors[k]);
}
for ( var k in searches )
{
var search, target;
search = $(searches[k]);
if ( search.length )
target = $(targets[k]);
if ( !search.length || !target.length )
continue;
var s_css_arr = search.prop("className").split(" ");
var t_css_arr = target.prop("className").split(" ");
var className = s_css_arr[0];
const hasClass = new RegExp(String.raw`\.${ className }(?:[^\w-]|$)`);
const rules = [ ];
Array.prototype.forEach.call(document.styleSheets,
({ rules, }) => rules && Array.prototype.forEach.call(rules,
rule => hasClass.test(rule.selectorText) && rules.push(rule)
)
);