Skip to content

Instantly share code, notes, and snippets.

@cfillion
Last active May 11, 2023 21:22
Show Gist options
  • Save cfillion/1ef421d54bb747fa14047d6d65aa8dae to your computer and use it in GitHub Desktop.
Save cfillion/1ef421d54bb747fa14047d6d65aa8dae to your computer and use it in GitHub Desktop.
Show an indicator beside an original poster's post on the REAPER forums https://i.imgur.com/oxUj5Ws.png
// ==UserScript==
// @name Original poster indicator
// @namespace https://cfillion.ca
// @version 1.2
// @author cfillion
// @include https://forum.cockos.com/showthread.php*
// ==/UserScript==
// See also: syntax-highlighting.user.js https://gist.github.com/cfillion/7fd2bfe13465a8a37d28a9f0fd60b13b
function getPosters(doc)
{
return doc.querySelectorAll('.bigusername');
}
let label = document.createElement('span');
label.appendChild(document.createTextNode('OP'));
label.title = 'Original poster';
label.style = `
background-color: #12768c;
border-radius: 3px;
color: white;
cursor: default;
font-size: 12px;
font-weight: bold;
margin-left: 5px;
padding-left: 4px;
padding-right: 4px;
`;
(async() => {
const posters = getPosters(document);
let op = posters[0];
const threadId = document.querySelector('form input[name=searchthreadid]');
const params = new URLSearchParams(window.location.search);
if(threadId && (params.get('page') > 1 || params.has('p'))) {
let response = await fetch(new URL(`showthread.php?t=${threadId.value}`, window.location.href));
const html = await response.text();
let parser = new DOMParser();
let firstPage = parser.parseFromString(html, "text/html");
op = getPosters(firstPage)[0];
}
for(poster of posters) {
if(poster.href == op.href)
poster.parentNode.insertBefore(label.cloneNode(true), poster.nextSibling);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment