Skip to content

Commit

Permalink
Merge pull request #256 from csfloat/feature/profile-comment-warning
Browse files Browse the repository at this point in the history
Shows Warning if Creating a Profile Comment with Trigger Words
  • Loading branch information
Step7750 authored Sep 24, 2024
2 parents f40190c + a5e77bb commit fc0fe31
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
5 changes: 5 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
"matches": ["*://*.steamcommunity.com/*/tradeoffers/*"],
"js": ["src/lib/page_scripts/trade_offers.js"],
"css": ["src/global.css"]
},
{
"matches": ["*://*.steamcommunity.com/id/*", "*://*.steamcommunity.com/profiles/*"],
"js": ["src/lib/page_scripts/profile.js"],
"css": ["src/global.css"]
}
],
"background": {
Expand Down
70 changes: 70 additions & 0 deletions src/lib/components/profile/comment_warning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {css, html} from 'lit';

import {CustomElement, InjectAfter, InjectionMode} from '../injectors';
import {FloatElement} from '../custom';
import '../common/ui/steam-button';
import {state} from 'lit/decorators.js';
import {Observe} from '../../utils/observers';

@CustomElement()
@InjectAfter('.commentthread_area .commentthread_header', InjectionMode.ONCE)
export class CommentWarning extends FloatElement {
@state()
show = false;

static styles = [
...FloatElement.styles,
css`
.container {
background-color: rgba(235, 87, 87, 0.05);
color: #de6667;
border-radius: 6px;
padding: 8px;
margin: 5px;
font-size: 14px;
}
`,
];

private getRawCommentBoxText(): string {
const elems = document.getElementsByClassName('commentthread_textarea');
if (elems.length === 0) {
return '';
}

const elem = elems[0] as HTMLTextAreaElement;
return elem.value || '';
}

async connectedCallback() {
super.connectedCallback();

Observe(
() => {
return this.getRawCommentBoxText();
},
() => {
this.refreshWarningApplicable();
}
);
}

refreshWarningApplicable() {
const text = this.getRawCommentBoxText();
const words = new Set(text.toLowerCase().split(' '));

const hasTriggerWord = ['buy', 'sell', 'bought', 'sold', 'csfloat'].some((e) => words.has(e));
this.show = hasTriggerWord;
}

render() {
if (!this.show) {
return html``;
}

return html`<div class="container">
<b>WARNING:</b> Commenting on profiles with words relating to buying and selling CS2 items
<b>WILL</b> result in a Steam community ban!
</div>`;
}
}
6 changes: 6 additions & 0 deletions src/lib/page_scripts/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {init} from './utils';
import '../components/profile/comment_warning';

init('src/lib/page_scripts/profile.js', main);

async function main() {}

0 comments on commit fc0fe31

Please sign in to comment.