@@ -42,6 +42,9 @@ document.addEventListener('DOMContentLoaded', function() {
4242 * @param {string } stylesheetId - The ID of the stylesheet from which to delete the rules.
4343 */
4444function deleteCSSRules ( selectorText , stylesheetId ) {
45+ // Modify the selector to include the new condition
46+ const modifiedSelectorText = `body:not(.elementor-editor-active) ${ selectorText } ` ;
47+
4548 // Find the specified stylesheet by ID
4649 const styleSheet = [ ...document . styleSheets ] . find (
4750 sheet => sheet . ownerNode . id === stylesheetId
@@ -58,7 +61,7 @@ function deleteCSSRules(selectorText, stylesheetId) {
5861
5962 // Since deleting a rule shifts subsequent rules' indices, iterate backwards
6063 for ( let i = rules . length - 1 ; i >= 0 ; i -- ) {
61- if ( rules [ i ] . selectorText === selectorText ) {
64+ if ( rules [ i ] . selectorText === modifiedSelectorText ) {
6265 // Log the rule that is about to be deleted
6366 debugPrint ( `Deleting CSS rule: ${ rules [ i ] . cssText } ` ) ;
6467 // Delete the rule
@@ -68,7 +71,7 @@ function deleteCSSRules(selectorText, stylesheetId) {
6871 }
6972
7073 if ( ! found ) {
71- console . warn ( `No CSS rule found for selector "${ selectorText } " in stylesheet with ID "${ stylesheetId } ".` ) ;
74+ console . warn ( `No CSS rule found for selector "${ modifiedSelectorText } " in stylesheet with ID "${ stylesheetId } ".` ) ;
7275 }
7376}
7477
@@ -83,6 +86,9 @@ function deleteCSSRules(selectorText, stylesheetId) {
8386 * @param {string } ruleContent - The content of the CSS rule to add.
8487 */
8588function addCSSRules ( selectorText , stylesheetId , ruleContent ) {
89+ // Modify the selector to include the new condition
90+ const modifiedSelectorText = `body:not(.elementor-editor-active) ${ selectorText } ` ;
91+
8692 // Find the specified stylesheet by ID
8793 const styleSheet = [ ...document . styleSheets ] . find (
8894 sheet => sheet . ownerNode . id === stylesheetId
@@ -95,16 +101,16 @@ function addCSSRules(selectorText, stylesheetId, ruleContent) {
95101
96102 // Check if a rule with the given selector already exists
97103 const existingRuleIndex = Array . from ( styleSheet . cssRules ) . findIndex (
98- rule => rule . selectorText === selectorText
104+ rule => rule . selectorText === modifiedSelectorText
99105 ) ;
100106
101107 // If the rule does not already exist, add it
102108 if ( existingRuleIndex === - 1 ) {
103- const fullRule = `${ selectorText } { ${ ruleContent } }` ;
109+ const fullRule = `${ modifiedSelectorText } { ${ ruleContent } }` ;
104110 styleSheet . insertRule ( fullRule , styleSheet . cssRules . length ) ;
105111 debugPrint ( `Added new CSS rule: ${ fullRule } ` ) ;
106112 } else {
107- debugPrint ( `CSS rule for selector "${ selectorText } " already exists. No action taken.` ) ;
113+ debugPrint ( `CSS rule for selector "${ modifiedSelectorText } " already exists. No action taken.` ) ;
108114 }
109115}
110116
0 commit comments