Created
January 17, 2020 19:06
-
-
Save Kein/5dc004162ae377a8f536e6a3b5851597 to your computer and use it in GitHub Desktop.
Highlights your own topics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Highlighter | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Highlights threads posted by you | |
// @author Kein | |
// @match *://steamcommunity.com/*/*/discussions/ | |
// @match *://steamcommunity.com/*/*/*/?fp=* | |
// @match *://steamcommunity.com/app/*/tradingforum/ | |
// @match *://steamcommunity.com/app/*/tradingforum/?fp=* | |
// @match https://steamcommunity.com/*/*/discussions/*/ | |
// @match https://steamcommunity.com/*/*/discussions/*/?fp=* | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Login check | |
const isLoggedIn = g_steamID != false && g_steamID.length > 15; | |
if (!isLoggedIn) | |
return; | |
// Customizable | |
const bgColor = "#e0db518f"; | |
// Static fetch | |
let user = document.getElementById("account_pulldown").innerText; | |
let target = document.getElementsByClassName("forum_topics"); | |
target = target == null || target == undefined ? null : target[0]; | |
if (!target || !user) | |
return; | |
lightTopics([].slice.call(target.children), user, bgColor); | |
setObserver(target, user, bgColor); | |
function setObserver(tObject, uName, color) | |
{ | |
const observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if (mutation.type === 'childList') | |
{ | |
lightTopics([].slice.call(tObject.children), uName, color); | |
} | |
}); | |
}); | |
observer.observe(tObject, { childList: true }); | |
} | |
function lightTopics(topics, uName, color) | |
{ | |
for (let i = topics.length - 1; i >= 0; i--) | |
{ | |
let u = topics[i].querySelector(".forum_topic_op").innerText; | |
if (u.localeCompare(uName, undefined, {sensitivity: 'accent'}) === 0) | |
topics[i].style.backgroundColor = color; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment