Last active
August 29, 2015 14:19
-
-
Save adaliabooks/c72b36bc3d85aa5764a3 to your computer and use it in GitHub Desktop.
Adds Basic user search / filter bar to GoG.com forums for use in Mafia Games
This file contains 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 GoG Mafia Search | |
// @namespace https://gist.github.com/adaliabooks/ | |
// @version 0.1 | |
// @description Adds Basic user search / filter bar to GoG.com forums for use in Mafia Games | |
// @author adaliabooks | |
// @match https://gist.github.com/adaliabooks/c72b36bc3d85aa5764a3 | |
// @grant none | |
// @include http://www.gog.com/forum/* | |
// ==/UserScript== | |
jQuery.expr[':'].Contains = function(a, i, m) { | |
return jQuery(a).text().toUpperCase() | |
.indexOf(m[3].toUpperCase()) >= 0; | |
}; | |
function FolderDepthFunction(the_url) | |
{ | |
var the_arr = the_url.split('/'); | |
return the_arr.length; | |
} | |
function RemoveLastDirectoryPartOf(the_url) | |
{ | |
var the_arr = the_url.split('/'); | |
the_arr.pop(); | |
return( the_arr.join('/') ); | |
} | |
function RemoveLastDirIfLonger(the_url, length) | |
{ | |
if (FolderDepthFunction(the_url) > length) | |
{ | |
return RemoveLastDirectoryPartOf(the_url); | |
} | |
else | |
{ | |
return the_url; | |
} | |
} | |
function GetFirstPartOfDirectory(the_url) | |
{ | |
var the_arr = the_url.split('/'); | |
return the_arr[0]; | |
} | |
function addGlobalStyle(css) { | |
var head, style; | |
head = document.getElementsByTagName('head')[0]; | |
if (!head) { return; } | |
style = document.createElement('style'); | |
style.type = 'text/css'; | |
style.innerHTML = css; | |
head.appendChild(style); | |
} | |
addGlobalStyle('#gogSearchBox { background-color: #474747; padding: 15px 17px 0 10px; height: 29px; color: #a1a1a1; font-size: 12px; }'); | |
addGlobalStyle('div.nav_bar_top_h { width: 950px; height: 105px; margin: 0 23px 0 23px; padding: 28px 0 0 0; position: relative;}'); | |
var $filterbar = $( '<div id="gogSearchBox"><p style="display: inline;">Username: </p><input type="text"value="" id="username_box" style="display: inline; margin-right: 10px;"><p style="display:inline;">First Page: </p><input type="text" value="" id="startpage_box" style="display:inline; margin-right: 10px;"><p style="display: inline;">End Page: </p><input type="text" value="" id="endpage_box" style="display: inline; margin-right: 10px;"><a id="filter_go" style="display: inline; margin-right:20px;">Go</a><a id="filter_votes" style="display: inline;">Filter Votes</a></div>' ); | |
$( ".nav_bar_top_h" ).prepend($filterbar); | |
$( "#filter_go" ).on("click", function () { | |
jQuery('.spot_h').remove(); | |
var endpage = parseInt($("#endpage_box").val()); | |
var startpage = parseInt($("#startpage_box").val()); | |
for (var i = endpage; i > startpage; i--) | |
{ | |
var fullURL = window.location.pathname; | |
var threadURL = RemoveLastDirIfLonger(fullURL, 4) + "/page" + i + " .spot_h"; | |
if (!$(".page" + i + "posts").length) | |
{ | |
var $newdiv = $( "<div class='page" + i + "posts'/>" ) | |
} | |
$( ".list_h" ).prepend($newdiv) | |
$( ".page" + i + "posts").load(threadURL, function() { | |
if ($("#username_box").val()) | |
{ | |
$( ".b_u_name" ) | |
.contents() | |
.filter(function() { | |
return this.nodeType === 3; | |
}) | |
.wrap( "<a></a>" ) | |
.end() | |
jQuery('.b_u_name a:not(:Contains(' + $("#username_box").val() + '))').parents('.spot_h').remove(); | |
} | |
}) | |
} | |
}); | |
$( "#filter_votes" ).on("click", function () { | |
jQuery('.spot_h').remove(); | |
var endpage = parseInt($("#endpage_box").val()); | |
var startpage = parseInt($("#startpage_box").val()); | |
for (var i = endpage; i > startpage; i--) | |
{ | |
var fullURL = window.location.pathname; | |
var threadURL = RemoveLastDirIfLonger(fullURL, 4) + "/page" + i + " .spot_h"; | |
if (!$(".page" + i + "posts").length) | |
{ | |
var $newdiv = $( "<div class='page" + i + "posts'/>" ) | |
} | |
$( ".list_h" ).prepend($newdiv) | |
$( ".page" + i + "posts").load(threadURL, function() { | |
jQuery('.post_text_c:not(:has(span.bold:Contains(vote)))').parents('.spot_h').remove(); | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment