Skip to content

Commit bac6e3b

Browse files
committed
Added type option to styles.getAllSelectors()
1 parent 0e93c41 commit bac6e3b

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

chatgpt-widescreen/chromium/extension/lib/styles.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
window.styles = {
44

5-
getAllSelectors(obj) { // used in this.tweaks.styles for spam selectors
6-
return Object.values(obj).flatMap(val => typeof val == 'object' ? this.getAllSelectors(val) : val) },
5+
getAllSelectors(obj, { type } = {}) { // used in this.tweaks.styles for spam selectors
6+
const selectors = Object.values(obj).flatMap(val =>
7+
typeof val == 'object' ? this.getAllSelectors(val, { type }) : val)
8+
return type == 'css' ? selectors.filter(sel => !sel.startsWith('//'))
9+
: type == 'xpath' ? selectors.filter(sel => sel.startsWith('//'))
10+
: /* no type */ selectors
11+
},
712

813
get outerDivSelector() { // requires env.site
914
return env.site == 'chatgpt' ? 'div.text-base > div'

chatgpt-widescreen/chromium/extension/lib/sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ window.sync = {
6262

6363
spamBlock() { // requires env.site + sites
6464
const selectors = sites[env.site]?.selectors?.spam ; if (!selectors) return
65-
styles.getAllSelectors(selectors).filter(sel => sel.startsWith('//')).forEach(sel => {
65+
styles.getAllSelectors(selectors, { type: 'xpath' }).forEach(sel => {
6666
try {
6767
const result = document.evaluate(sel, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
6868
for (let i = 0 ; i < result.snapshotLength ; i++)

chatgpt-widescreen/firefox/extension/lib/styles.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
window.styles = {
44

5-
getAllSelectors(obj) { // used in this.tweaks.styles for spam selectors
6-
return Object.values(obj).flatMap(val => typeof val == 'object' ? this.getAllSelectors(val) : val) },
5+
getAllSelectors(obj, { type } = {}) { // used in this.tweaks.styles for spam selectors
6+
const selectors = Object.values(obj).flatMap(val =>
7+
typeof val == 'object' ? this.getAllSelectors(val, { type }) : val)
8+
return type == 'css' ? selectors.filter(sel => !sel.startsWith('//'))
9+
: type == 'xpath' ? selectors.filter(sel => sel.startsWith('//'))
10+
: /* no type */ selectors
11+
},
712

813
get outerDivSelector() { // requires env.site
914
return env.site == 'chatgpt' ? 'div.text-base > div'

chatgpt-widescreen/firefox/extension/lib/sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ window.sync = {
6262

6363
spamBlock() { // requires env.site + sites
6464
const selectors = sites[env.site]?.selectors?.spam ; if (!selectors) return
65-
styles.getAllSelectors(selectors).filter(sel => sel.startsWith('//')).forEach(sel => {
65+
styles.getAllSelectors(selectors, { type: 'xpath' }).forEach(sel => {
6666
try {
6767
const result = document.evaluate(sel, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
6868
for (let i = 0 ; i < result.snapshotLength ; i++)

0 commit comments

Comments
 (0)