Skip to content

Instantly share code, notes, and snippets.

@MorningZ
Last active October 9, 2018 18:34
Show Gist options
  • Save MorningZ/13bbe2391b7ae9cf6ebf3e4c7e292e3f to your computer and use it in GitHub Desktop.
Save MorningZ/13bbe2391b7ae9cf6ebf3e4c7e292e3f to your computer and use it in GitHub Desktop.
Cleans up the "Active Threads" page of FocusRS.org. Pick and choose what threads to show/hide. Also changes the search in the navbar to use Google instead of the crappy vBulletin one.
/*
==========================
Compatible with:
==========================
- Desktop versions of Chrome, Firefox and Safari
==========================
Purpose:
==========================
Uses JavaScript to hide/ignore threads of your choosing on FocusRS.org's
"Active Topics" screen (http://www.focusrs.org/index.php?pageid=active_topics)
Also rewrites the "Navbar Search" to use Google instead with the option to search on either thread title or thread contents.
NOTES:
- There is a LOT of existing code on the forum, mainly a lot of 3rd party ads and tracking. Once in a while that code will interfere with this code below.
- If you get a message from Google search saying "unusual activity", just choose the "I am not a Robot" checkbox that it presents and you'll be good from there.
- I've personally been using this code for about 7 months now (as of mid October 2018)
on Chrome on both Mac and Windows and it has worked pretty solidly.
==========================
Directions:
==========================
Chrome:
- Install Extensions (JavaScript for websites: http://bit.ly/1Xa0YZx)
- Navigate to the site: http://www.focusrs.org/index.php?pageid=active_topics
- Open the Custom JavaScript extension by clicking the "cjs" button in extension area of Chrome
- Check "enable cjs for this host"
- Paste the text from the "Javascript" area below into the big text area. You can also hit the "Raw" button on the top right and just copy the whole entire block of text, comments included.
- Click "Save" in the bottom left, the page will reload with the code running against it
Firefox (sorry, a bit more complex):
- Install Greasemonkey (https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/)
- Click the Add-on icon for Greasemonkey, it's a picture of a monkey's head, choose "Manage User Scripts"
- Click on "New User Script" along the top
- Name: RS - Ignore
- Namespace: (leave empty!!)
- Includes: http://www.focusrs.org/* (<--- very important to have it just like this with the "*")
- Click "OK", at the first open line, paste in the text from the "Javascript" section later down this file
- Here is where Greasemonkey is a pain in the ass, when you paste that text in you may get prompted about /
"unsafe blah blah", you have to type "Allow Paste" like it says and press enter. Once you do that,
remove that text and re-paste my code from below
- Click "Save" and close the tab that Greasemonkey opened
- Go back to the tab where the site was and refresh, if you don't see any change, go back to
"Manage Script" in Greasemonkey and make sure the script properly got pasted in (it took me two
tries when I put these directions together)
Safari:
- Follow this: https://developer.apple.com/library/archive/documentation/Tools/Conceptual/SafariExtensionGuide/InjectingScripts/InjectingScripts.html
*/
/*==========================
Javascript portion:
Documentation: https://gist.github.com/MorningZ/13bbe2391b7ae9cf6ebf3e4c7e292e3f
==========================*/
/* Start of Copy/Paste */
var MZ = { "Log": true, "NotificationSecs": 5 };
MZ.Init = function() {
setTimeout(function() {
// Hide the Google+ button
$("#___plusone_0").css("display", "none");
// Fix the broken Active Topics link
$("a.navtab[href$='?pageid=active_topics']").each(function() {
$(this).attr("href", $(this).attr("href").replace("pageid=active_topics", "page=active_topics"));
});
}, 1500);
// Remap the nav search
$(".navbar_search input[type='text']").val("").attr("placeholder", " Google Search");
$(".navbar_search").submit(function(e) {
var txt = $.trim($(this).find("input[type='text']").val());
switch($(".MZ_SearchType").val() || "") {
case "title":
window.open('https://www.google.com/search?q=site%3Afocusrs.org+intitle%3A"' + encodeURIComponent(txt) + '"', "focus_rs_search"); break;
default:
window.open("https://www.google.com/search?q=site%3Afocusrs.org+" + encodeURIComponent(txt), "focus_rs_search");
}
return false;
});
$("#globalsearch").css("width", "450px").find("> *").css("width", "450px");
$('<select class="MZ_SearchType"><option value="title">Search Title</option><option value="post">Search Title+Post</option></select>').insertBefore($(".navbar_search input[type='text']"));
// Only do this on Active Topics page
if (!window.location.href.endsWith("active_topics")) { return; }
MZ.Log = function(txt) { if (MZ.Log && console && console.log) { console.log(txt); } };
MZ.Set = function(key, val) { localStorage[key] = val; };
MZ.Get = function(key) { return localStorage[key] || null; };
MZ.HideLinks = function() {
var arr = MZ.IDs() || [];
var $rows = $(".cmps_middle tr.vba_module").each(function() {
$(this).find("a").each(function() {
var hit = $(this).attr("href").match(/^.+\/forum\/\d+[-].+\/(\d+)[-].+[.]html$/);
if (hit && hit.length == 2 && $.inArray(hit[1], arr) > -1) {
$(this).closest(".vba_module").css("display", "none").css("background-color", "#cacaca").addClass("MZ_Row MZ_Hidden");
return false; // Exit loop
}
});
});
};
// A collection of Thread ID's that are hidden. Stored in local storage.
MZ.IDs = function() {
var arr = MZ.Get("ids");
return (arr === null) ? [] : JSON.parse(arr);
};
// Add action links to "Recent Threads" header
MZ.AddLinks = function() {
var $rows_all = $("tr.vba_module");
var $rows_hidden = $("tr.vba_module.MZ_Row");
if ($(".MZ_Showing").length === 0) {
var h = ['>> Recent Threads'];
h.push(' / Showing: <span class="MZ_Showing">' + ($rows_all.length - $rows_hidden.length) + "</span>");
h.push(' / Hiding: <span class="MZ_Hiding">' + $rows_hidden.length + "</span>");
h.push(' <a href="#" class="MZ_Link MZ_ClearAll" style="color: yellow; margin-left: 10px;">[ Clear All Hidden ]</a>');
h.push(' <a href="#" class="MZ_Link MZ_ShowAll" style="color: yellow; margin-left: 10px;">[ View All Threads ]</a>');
h.push(' <a href="#" class="MZ_Link MZ_Help" style="color: yellow; margin-left: 10px;">?</a>');
$(".cmps_middle .collapse .blockhead strong:first").html(h.join(''));
}
else { // Just update counts
$(".MZ_Showing").text("" + ($rows_all.length - $rows_hidden.length));
$(".MZ_Hiding").text("" + $rows_hidden.length);
if ($rows_hidden.length === 0) { $(".MZ_HideAll").toggleClass("MZ_ShowAll MZ_HideAll").text('[ View All threads ]'); }
}
};
// Adds an [x] to each item to hide/unhide
MZ.AddBtns = function() {
$("tr.vba_module td:nth-child(3) div").each(function() {
$(this).prepend('<a href="#" class="MZ_HideLink" style="color: blue; text-decoration: none;" title="Click to hide this thread">[X]</a>');
});
};
MZ.Log("FocusRS Cleanup: " + typeof(Storage));
MZ.Log("-- jQuery version: " + $.fn.jquery);
var arr = MZ.IDs() || [];
MZ.Log("Saved IDs:"); MZ.Log(arr);
// **********************************************
//
// Events (tailored to old/new versions of jQuery
//
// **********************************************
switch ($.fn.jquery) {
case "1.4.2":
// Hide Link button on the items
$(".MZ_HideLink").live("click", function(e) {
var arr = MZ.IDs() || []; var $item = $(this).closest("tr.vba_module"); var showingHidden = ($(".MZ_HideAll").length > 0);
if ($item.hasClass("MZ_Row")) { // is already hidden
$item.css("display", "table-row").css("background-color", "inherit").removeClass("MZ_Row MZ_Hidden").find("a").each(function() {
var hit = $(this).attr("href").match(/^.+\/forum\/\d+[-].+\/(\d+)[-].+[.]html$/);
if (hit && hit.length == 2) {
for(var i = arr.length-1; i--;){
if (arr[i] === hit[1]) { arr.splice(i, 1); }
}
MZ.Set("ids", JSON.stringify(arr));
return false; // Exit out of loop
}
});
}
else { // hide this row
$item.css("background-color", "#cacaca").addClass("MZ_Row").find("a").each(function() {
var hit = $(this).attr("href").match(/^.+\/forum\/\d+[-].+\/(\d+)[-].+[.]html$/);
if (hit && hit.length == 2) {
arr.push(hit[1]);
MZ.Set("ids", JSON.stringify(arr));
return false; // Exit out of loop
}
});
if (!showingHidden) { $item.css("display", "none").addClass("MZ_Hidden"); }
}
MZ.AddLinks();
return false;
});
// View All / Hide All / Clear All
$(".MZ_ShowAll").live("click", function(e) {
$("tr.vba_module.MZ_Row").css("display", "table-row").removeClass("MZ_Hidden");
$(this).toggleClass("MZ_ShowAll MZ_HideAll").text('[ Re-Hide Threads ]');
return false;
});
$(".MZ_HideAll").live("click", function(e) {
$("tr.vba_module.MZ_Row").css("display", "none").addClass("MZ_Hidden");
$(this).toggleClass("MZ_ShowAll MZ_HideAll").text('[ View All Threads ]');
return false;
});
$(".MZ_ClearAll").live("click", function(e) {
/*
kango.ui.notifications.show('Notification title', 'Notification text', 'http://kangoextensions.com/images/logos/kango.png', function() {
kango.console.log('Notification click');
});
*/
if (confirm('Reset ignore thread list?')) {
$(".MZ_Row").css("display", "table-row").css("background-color", "inherit").removeClass("MZ_Row MZ_Hidden");
MZ.Set("ids", null);
MZ.AddLinks();
return false;
}
return false;
});
$(".MZ_Help").live("click", function(e) {
alert('Code last updated:\n' + 'July 1st, 2017\nhttps://www.focusrs.org/forum/13-off-topic/104418-interested-browser-extension-tones-down-site-noise.html');
return false;
});
break;
default: // Newer
// Hide Link button on the items
$(document).on("click", ".MZ_HideLink", function(e) {
var arr = MZ.IDs() || []; var $item = $(this).closest("tr.vba_module"); var showingHidden = ($(".MZ_HideAll").length > 0);
if ($item.hasClass("MZ_Row")) { // is already hidden
$item.css("display", "table-row").css("background-color", "inherit").removeClass("MZ_Row MZ_Hidden").find("a").each(function() {
var hit = $(this).attr("href").match(/^.+\/forum\/\d+[-].+\/(\d+)[-].+[.]html$/);
if (hit && hit.length == 2) {
for(var i = arr.length-1; i--;){
if (arr[i] === hit[1]) { arr.splice(i, 1); }
}
MZ.Set("ids", JSON.stringify(arr));
return false; // Exit out of loop
}
});
}
else { // hide this row
$item.css("background-color", "#cacaca").addClass("MZ_Row").find("a").each(function() {
var hit = $(this).attr("href").match(/^.+\/forum\/\d+[-].+\/(\d+)[-].+[.]html$/);
if (hit && hit.length == 2) {
arr.push(hit[1]);
MZ.Set("ids", JSON.stringify(arr));
return false; // Exit out of loop
}
});
if (!showingHidden) { $item.css("display", "none").addClass("MZ_Hidden"); }
}
MZ.AddLinks();
return false;
});
// View All / Hide All / Clear All
$(document).on("click", ".MZ_ShowAll", function(e) {
$("tr.vba_module.MZ_Row").css("display", "table-row").css("background-color", "inherit").removeClass("MZ_Hidden");
$(this).toggleClass("MZ_ShowAll MZ_HideAll").text('[ Re-Hide Threads ]');
return false;
});
$(document).on("click", ".MZ_HideAll", function(e) {
$("tr.vba_module.MZ_Row").css("display", "none").addClass("MZ_Hidden");
$(this).toggleClass("MZ_ShowAll MZ_HideAll").text('[ View All Threads ]');
return false;
});
$(document).on("click", ".MZ_ClearAll", function(e) {
/*
kango.ui.notifications.show('Notification title', 'Notification text', 'http://kangoextensions.com/images/logos/kango.png', function() {
kango.console.log('Notification click');
});
*/
if (confirm('Reset ignore thread list?')) {
$(".MZ_Row").css("display", "table-row").removeClass("MZ_Row MZ_Hidden");
MZ.Set("ids", null);
MZ.AddLinks();
return false;
}
return false;
});
$(document).on("click", ".MZ_Help", function(e) {
alert('Code last updated:\n' + 'April 4th 8 am EST');
return false;
});
}
// Initial hiding of links
MZ.HideLinks();
// Add buttons to each item to hide it
MZ.AddBtns();
// Decorates the top of the table with stats and actions
MZ.AddLinks();
}();
/* End of Copy/Paste */
@MorningZ
Copy link
Author

MorningZ commented Feb 9, 2018

gist_rs_01_not_installed

gist_rs_02_filtered

gist_rs_03_view_all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment