Skip to content

Instantly share code, notes, and snippets.

@Kein
Last active January 18, 2020 04:43
Show Gist options
  • Save Kein/40d5beb1d234716d8b588e0fbd353a61 to your computer and use it in GitHub Desktop.
Save Kein/40d5beb1d234716d8b588e0fbd353a61 to your computer and use it in GitHub Desktop.
Quickreply on ctrl+Enter + autodelete on bump + no delete confirmations
// ==UserScript==
// @name QuickReply
// @version 0.0.1
// @description Quick reply on Steam forums
// @author Kein
// @match *://steamcommunity.com/app/*/tradingforum/*/*
// @match *://steamcommunity.com/groups/*/discussions/*
// @match *://steamcommunity.com/app/*/discussions/*/*/*
// @match *://steamcommunity.com/workshop/discussions/*/*/*
// @grant none
// @run-at document-end
// ==/UserScript==
(function(){
'use strict';
const isLoggedIn = g_steamID != false && g_steamID.length > 15;
if (!isLoggedIn)
return;
const inputForm = document.querySelector("textarea[placeholder*='reply']");
const submitButton = document.querySelector(".btn_green_white_innerfade.btn_small");
const lastComment = document.querySelector('.commentthread_comment:last-child');
const authorNode = lastComment ? lastComment.querySelector('.commentthread_comment_author bdi') : undefined;
const nnHolder = document.getElementById('account_pulldown');
let delay = null;
// Setting up fake can_moderate flag to bypass confirmation
// The only other way would be writing your own function or patching existing
if (g_rgForumTopics != null && g_rgForumTopics != undefined)
{
let topicKey = Object.keys(g_rgForumTopics)[0];
if (document.URL.indexOf(topicKey) >= 0)
g_rgForumTopics[topicKey].m_rgForumData.permissions.can_moderate = 1;
}
if (inputForm && submitButton)
inputForm.onkeydown = ctrlEnter;
// Funcs
function ctrlEnter(e)
{
if (e.ctrlKey && (e.keyCode == 10 || e.keyCode == 13))
{
submitButton.click();
let txt = inputForm.value.trim();
let bump = (txt.indexOf('bump') > -1 && txt.length < 6);
if (bump && lastComment && isLoggedIn && authorNode && nnHolder
&& nnHolder.textContent.trim().localeCompare(authorNode.innerText.trim(), undefined, {sensitivity: 'accent'}) === 0)
{
delay = bumpMode(lastComment);
}
}
}
function bumpMode(commentObj)
{
let commentID = commentObj.id.replace('comment_', '');
let forumID = Object.keys(g_rgCommentThreads)[0];
let d = setInterval(delayedDelete, 800, forumID, commentID);
return d;
}
function delayedDelete(forumID, commentID)
{
if (g_rgCommentThreads[forumID].m_bLoading != true)
{
window.CCommentThread.DeleteComment(forumID, commentID);
clearInterval(delay);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment