Last active
August 29, 2015 14:21
-
-
Save adaliabooks/51d25e123f36f4308bb2 to your computer and use it in GitHub Desktop.
Adds Basic user search / filter bar to GoG.com forums
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 Search | |
// @namespace https://gist.github.com/adaliabooks/ | |
// @version 1.0 | |
// @description Adds Basic user search / filter bar to GoG.com forums | |
// @author adaliabooks | |
// @updateURL https://gist.github.com/adaliabooks/51d25e123f36f4308bb2/raw/ | |
// @downloadURL https://gist.github.com/adaliabooks/51d25e123f36f4308bb2/raw/ | |
// @require https://raw.githubusercontent.com/bartaz/sandbox.js/master/jquery.highlight.js | |
// @grant none | |
// @include http://www.gog.com/forum/* | |
// @include https://www.gog.com/forum/* | |
// ==/UserScript== | |
var versionNumber = "1.0"; | |
var months = { Jan : 0, Feb : 1, Mar : 2, Apr : 3, May : 4, Jun : 5, Jul : 6, Aug : 7, Sep : 8, Oct : 9, Nov : 10, Dec : 11 }; | |
var debugLogger = { | |
debuggingActive : false, | |
debugLog : function (message) | |
{ | |
if(debugLogger.debuggingActive) | |
{ | |
console.log(message); | |
} | |
} | |
}; | |
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 GetLastPartOfDirectory(the_url) | |
{ | |
var the_arr = the_url.split('/'); | |
return the_arr[the_arr.length - 1]; | |
} | |
function FindLastPageNumber() | |
{ | |
return parseInt(jQuery('.n_b_b_nr_last').first().text()); | |
} | |
function MergeArraysRemoveDuplicates(array1, array2) | |
{ | |
var result = array1; | |
array2.forEach(function(value){ | |
if (result.indexOf(value)==-1) result.push(value); | |
}); | |
return result; | |
} | |
function StripNonNumbers(aString) | |
{ | |
return aString.replace(/\D/g,''); | |
} | |
function StripNonNumbersParse(aString) | |
{ | |
return parseInt(aString.replace(/\D/g,'')); | |
} | |
function naturalCompare(a, b) { | |
// thanks to stackoverflow user georg for this function here: http://stackoverflow.com/a/15479354 | |
var ax = [], bx = []; | |
a.replace(/(\d+)|(\D+)/g, function(_, $1, $2) { ax.push([$1 || Infinity, $2 || ""]) }); | |
b.replace(/(\d+)|(\D+)/g, function(_, $1, $2) { bx.push([$1 || Infinity, $2 || ""]) }); | |
while(ax.length && bx.length) { | |
var an = ax.shift(); | |
var bn = bx.shift(); | |
var nn = (an[0] - bn[0]) || an[1].localeCompare(bn[1]); | |
if(nn) return nn; | |
} | |
return ax.length - bx.length; | |
} | |
function checkIsForumPage() | |
{ | |
/* | |
if(window.location.hash) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
*/ | |
if(!$('.n_b_t_main_2').length) | |
{ | |
debugLogger.debugLog('Forum'); | |
return true; | |
} | |
else | |
{ | |
debugLogger.debugLog('Thread'); | |
return false; | |
} | |
} | |
function getNoResultForum() | |
{ | |
debugLogger.debugLog('Forum Search: No Results'); | |
return $('<div class="list_row_odd "><div class="last_update">now</div><div class="babel_h"><div class="babel niebieski_b_odd"></div></div><div class="topic_s" style="width: 642px;"><a href="" class="topic_s_a"><b>Sorry there are no results matching your query.</b> </a> </div><div class="created_by"> <span class="user is-data-pending user--block"><span class="user__avatar-container avatar--small avatar--in-text t_u_avatar_h"> <img class="avatar avatar--small avatar--in-text t_u_avatar_h" src="https://www.gog.com/upload/avatars/2008/07/1215790476123_t.jpg" alt=""> <i class="icon-pointer"></i></span> <span class="user__name ">GOG.com</span> <span class="user__data"> <span class="user__item user__item--header"> <img class="avatar user__header-avatar" alt=""> <span class="user__header-details"> <span class="user__name ">GOG.com</span> </span> <i class="_spinner user__header-spinner is-spinning"></i> </span> <span class="user__item user__item--error"> Sorry, data for given user is currently unavailable. Please, try again later. </span> <a ng-show="user.data.hasSharedWishlist" ng-href="" class="user__item user__item--action ng-hide">View wishlist</a> <a ng-href="" gog-login-required="" class="user__item user__item--action">Start conversation</a> <span ng-show="user.data.isAnonymous" ng-click="user.inviteToFriends(); $event.stopPropagation()" class="user__item user__item--action ng-hide">Invite to friends</span><span ng-show="user.data.isAwaiting" ng-click="user.acceptInvitation(); $event.stopPropagation()" class="user__item user__item--action ng-hide">Accept invitation</span> <span ng-show="user.data.isInvited" class="user__item user__item--status ng-hide">Pending invitation...</span> <span ng-show="!user.data.isFriend" class="user__item user__item--info ng-binding"> <i class="ic icon-friend"></i>User since </span> <span ng-show="user.data.isFriend" class="user__item user__item--info ng-binding ng-hide"> <i class="ic icon-friends user__icon--friend"></i>Friends since </span> </span> </span><!--<div class="t_u_avatar_h"><img src="--><!--" alt="--><!--" width="16" height="16"/></div>--><!--<div class="user_name">--><!----><!--</div>--></div><div class="clear"></div></div>'); | |
} | |
function getNoResultThread() | |
{ | |
debugLogger.debugLog('Thread Search: No Results'); | |
return $('<div id="p_b_1" class="spot_h" style=";"><div class="big_post_h" style=""><div class="big_post_left"></div><div class="big_post_main"><div class="big_user_info"><div class="b_u_info_1"> <span class="user is-data-pending user--block"> <div class="b_p_avatar_h"><span class="user__avatar-container avatar--medium "> <img src="https://images.gog.com/9b1aae00838bf648d83b017801d926f025abf226278d1263e20fd8d0df154445_forum_avatar.jpg" alt="GOG.com" width="49" height="49"><i class="icon-pointer"></i></span> </div> <div class="b_u_name"><a href="http://www.gogwiki.com/wiki/Special:GOGUser/GOG.com" target="_blank">GOG.com</a></div> <div class="b_u_stat">Editor</div> <span class="user__data"> <span class="user__item user__item--header"> <img class="avatar user__header-avatar" alt=""> <span class="user__header-details"> <span class="user__name ">GOG.com</span> </span> <i class="_spinner user__header-spinner is-spinning"></i> </span> <span class="user__item user__item--error"> Sorry, data for given user is currently unavailable. Please, try again later. </span> <a ng-show="user.data.hasSharedWishlist" ng-href="" class="user__item user__item--action ng-hide">View wishlist</a> <a ng-href="" gog-login-required="" class="user__item user__item--action">Start conversation</a> <span ng-show="user.data.isAnonymous" ng-click="user.inviteToFriends(); $event.stopPropagation()" class="user__item user__item--action ng-hide">Invite to friends</span><span ng-show="user.data.isAwaiting" ng-click="user.acceptInvitation(); $event.stopPropagation()" class="user__item user__item--action ng-hide">Accept invitation</span> <span ng-show="user.data.isInvited" class="user__item user__item--status ng-hide">Pending invitation...</span> <span ng-show="!user.data.isFriend" class="user__item user__item--info ng-binding"> <i class="ic icon-friend"></i>User since </span> <span ng-show="user.data.isFriend" class="user__item user__item--info ng-binding ng-hide"> <i class="ic icon-friends user__icon--friend"></i>Friends since </span> </span> </span><div class="clear"></div></div></div><div class="big_post_content "><div class="post_header_h"><div class="post_date">Posted now</div> </div><div class="post_text"><div class="post_text_c news_post"><span class="bold">Sorry, no results have been found to match your search query.</span> </div></div> </div></div><div class="big_post_right"></div><div class="clear"></div></div></div>'); | |
} | |
function getNumberOfResultsForum(number, time) | |
{ | |
return $('<div class="list_row_odd "><div class="last_update">now</div><div class="babel_h"><div class="babel niebieski_b_odd"></div></div><div class="topic_s" style="width: 642px;"><a href="" class="topic_s_a"><b>There are ' + number + ' results, returned in ' + time + ' seconds</b> </a> </div><div class="created_by"> <span class="user is-data-pending user--block"><span class="user__avatar-container avatar--small avatar--in-text t_u_avatar_h"> <img class="avatar avatar--small avatar--in-text t_u_avatar_h" src="https://www.gog.com/upload/avatars/2008/07/1215790476123_t.jpg" alt=""> <i class="icon-pointer"></i></span> <span class="user__name ">GOG.com</span> <span class="user__data"> <span class="user__item user__item--header"> <img class="avatar user__header-avatar" alt=""> <span class="user__header-details"> <span class="user__name ">GOG.com</span> </span> <i class="_spinner user__header-spinner is-spinning"></i> </span> <span class="user__item user__item--error"> Sorry, data for given user is currently unavailable. Please, try again later. </span> <a ng-show="user.data.hasSharedWishlist" ng-href="" class="user__item user__item--action ng-hide">View wishlist</a> <a ng-href="" gog-login-required="" class="user__item user__item--action">Start conversation</a> <span ng-show="user.data.isAnonymous" ng-click="user.inviteToFriends(); $event.stopPropagation()" class="user__item user__item--action ng-hide">Invite to friends</span><span ng-show="user.data.isAwaiting" ng-click="user.acceptInvitation(); $event.stopPropagation()" class="user__item user__item--action ng-hide">Accept invitation</span> <span ng-show="user.data.isInvited" class="user__item user__item--status ng-hide">Pending invitation...</span> <span ng-show="!user.data.isFriend" class="user__item user__item--info ng-binding"> <i class="ic icon-friend"></i>User since </span> <span ng-show="user.data.isFriend" class="user__item user__item--info ng-binding ng-hide"> <i class="ic icon-friends user__icon--friend"></i>Friends since </span> </span> </span><!--<div class="t_u_avatar_h"><img src="--><!--" alt="--><!--" width="16" height="16"/></div>--><!--<div class="user_name">--><!----><!--</div>--></div><div class="clear"></div></div>'); | |
} | |
function getNumberOfResultsThread(number, time) | |
{ | |
return $('<div id="p_b_1" class="spot_h" style=";"><div class="big_post_h" style="padding-bottom: 0px;"><div class="big_post_left" style="height: 35px;"></div><div class="big_post_main"><div class="big_post_content "><div class="post_header_h"><div class="post_date">There are ' + number + ' results, returned in ' + time + ' seconds</div> </div> </div></div><div class="big_post_right" style="height: 36px;"></div><div class="clear"></div></div></div>'); | |
} | |
var ajaxQueue = { | |
maxRequests : 100, | |
currentRequests : 0, | |
requests : [], | |
add : function (URL, callback) { | |
if (this.currentRequests < this.maxRequests) | |
{ | |
$.get(URL, callback); | |
} | |
else | |
{ | |
this.requests.push({ pageURL : URL, callbackFunction : callback}); | |
} | |
} | |
}; | |
$(document).off('ajaxSend'); | |
$(document).off('ajaxComplete'); | |
$(document).ajaxSend(function() { | |
ajaxQueue.currentRequests++; | |
}); | |
$(document).ajaxComplete(function() { | |
ajaxQueue.currentRequests--; | |
if (ajaxQueue.currentRequests < ajaxQueue.maxRequests && ajaxQueue.requests.length > 0) | |
{ | |
request = ajaxQueue.requests.shift(); | |
$.get(request.pageURL, request.callbackFunction); | |
debugLogger.debugLog('AJAX Removed From Queue'); | |
} | |
debugLogger.debugLog('AJAX Complete'); | |
}); | |
function splitSearchTerms() | |
{ | |
var searchText = $("#search_text_box").val(); | |
var orTermsArray = searchText.split(';'); | |
var termsArray = []; | |
for (var i = 0; i < orTermsArray.length; i++) | |
{ | |
termsArray.push(orTermsArray[i].split('&')); | |
} | |
debugLogger.debugLog("Search Term Array: " + termsArray); | |
return termsArray; | |
} | |
function threadSearchBase() | |
{ | |
if ($("#resultsSearch_checkbox").prop('checked')) | |
{ | |
debugLogger.debugLog('Thread Search: Within Results'); | |
threadSearchWithinResults(); | |
} | |
else | |
{ | |
debugLogger.debugLog('Thread Search: Normal Search'); | |
threadSearch(); | |
} | |
} | |
function forumSearchBase() | |
{ | |
if ($("#resultsSearch_checkbox").prop('checked')) | |
{ | |
debugLogger.debugLog('Forum Search: Within Results'); | |
forumSearchWithinResults(); | |
} | |
else | |
{ | |
debugLogger.debugLog('Forum Search: Normal Search'); | |
forumSearch(); | |
} | |
} | |
function threadFilter(array, post, andSearchTerms) | |
{ | |
var result = true; | |
for (var i = 0; i < andSearchTerms.length; i++) | |
{ | |
result &= threadFilterInner(array, post, andSearchTerms[i]); | |
} | |
if (result) | |
{ | |
array[post.id] = post; | |
} | |
} | |
function threadFilterInner(array, post, searchValueUntrimmed) | |
{ | |
var searchValue = searchValueUntrimmed.trim(); | |
debugLogger.debugLog('Thread Search: Post Number ' + post.id); | |
if ($(post).find('.b_u_name:Contains(' + searchValue + ')').length && $("#usernames_checkbox").prop('checked')) | |
{ | |
if ($("#highlight_checkbox").prop('checked')) | |
{ | |
$(post).find('.b_u_name').highlight(searchValue); | |
} | |
return true; | |
} | |
else if ($(post).find('.post_text_c:Contains(' + searchValue + ')').length && $("#posts_checkbox").prop('checked')) | |
{ | |
if ($("#highlight_checkbox").prop('checked')) | |
{ | |
$(post).find('.post_text_c').highlight(searchValue); | |
} | |
return true; | |
} | |
else if ($(post).find('.post_text_c:has(span.bold:Contains(' + searchValue + '))').length && $("#bold_checkbox").prop('checked')) | |
{ | |
if ($("#highlight_checkbox").prop('checked')) | |
{ | |
$(post).find('span.bold').highlight(searchValue); | |
} | |
return true; | |
} | |
} | |
function forumFilter(array, thread, andSearchTerms) | |
{ | |
var result = true; | |
for (var i = 0; i < andSearchTerms.length; i++) | |
{ | |
result &= forumFilterInner(array, thread, andSearchTerms[i]); | |
} | |
if (result) | |
{ | |
var key = $(thread).find('.topic_s a').attr('href'); | |
array[key] = thread; | |
} | |
} | |
function forumFilterInner(array, thread, searchValueUntrimmed) | |
{ | |
var searchValue = searchValueUntrimmed.trim(); | |
debugLogger.debugLog('Forum Search: Thread Name ' + $(thread).find('.topic_s').text()); | |
if ($(thread).find('.user__name:Contains(' + searchValue + ')').length && $("#usernames_checkbox").prop('checked')) | |
{ | |
if ($("#highlight_checkbox").prop('checked')) | |
{ | |
$(thread).find('.user__name').highlight(searchValue); | |
} | |
return true; | |
} | |
else if ($(thread).find('.topic_s:Contains(' + searchValue + ')').length && $("#posts_checkbox").prop('checked')) | |
{ | |
if ($("#highlight_checkbox").prop('checked')) | |
{ | |
$(thread).find('.topic_s').highlight(searchValue); | |
} | |
return true; | |
} | |
} | |
function threadSearch() | |
{ | |
var start = performance.now(); | |
$('.spot_h').remove(); | |
var endpage; | |
if ($("#endpage_box").val()) | |
{ | |
endpage = parseInt($("#endpage_box").val()); | |
} | |
else | |
{ | |
endpage = FindLastPageNumber(); | |
} | |
var startpage; | |
if ($("#startpage_box").val()) | |
{ | |
startpage = parseInt($("#startpage_box").val()); | |
} | |
else | |
{ | |
startpage = 1; | |
} | |
if (endpage > startpage + 500) | |
{ | |
endpage = startpage + 500; | |
} | |
var postsPerPage = 20; | |
var currentPostsOnPage = 0; | |
var currentPage = 1; | |
var selectedPage = 1; | |
var postsArray = {}; | |
var searchTerms = splitSearchTerms(); | |
$(document).off('ajaxStop'); | |
$( document ).ajaxStop(function() { | |
if (!jQuery.isEmptyObject(postsArray)) | |
{ | |
var postsKeys = Object.keys(postsArray); | |
postsKeys.sort(naturalCompare); | |
for (var i = 0; i < postsKeys.length; i++) | |
{ | |
var k = postsKeys[i]; | |
var post = postsArray[k]; | |
if (!$(".page" + currentPage + "posts").length) | |
{ | |
var $newdiv = $( "<div class='page" + currentPage + "posts'/>" ); | |
$( ".list_h" ).append($newdiv); | |
} | |
$(post).appendTo(".page" + currentPage + "posts"); | |
currentPostsOnPage++; | |
if (currentPostsOnPage > postsPerPage) | |
{ | |
currentPostsOnPage = 0; | |
currentPage++; | |
} | |
} | |
var end = performance.now(); | |
var timeTaken = Math.round((end - start) / 1000); | |
var resultPost = getNumberOfResultsThread(postsKeys.length, timeTaken); | |
$(resultPost).prependTo( ".list_h" ); | |
} | |
else | |
{ | |
var noResultPost = getNoResultThread(); | |
$(noResultPost).appendTo( ".list_h" ); | |
} | |
if ($(".quick_post").length) | |
{ | |
$(".list_h").append($(".quick_post")); | |
} | |
}); | |
for (var i = startpage; i < endpage + 1; i++) | |
{ | |
debugLogger.debugLog('PageNumber: ' + i); | |
var fullURL = window.location.pathname; | |
var threadURL = RemoveLastDirIfLonger(fullURL, 4) + "/page" + i; | |
ajaxQueue.add( threadURL, function( data ) { | |
var $page = $(data); | |
$page.find('.big_post_h').parents('.spot_h').each(function( index ) { | |
for (var i = 0; i < searchTerms.length; i++) | |
{ | |
debugLogger.debugLog('Or Search Term: ' + searchTerms[i]); | |
threadFilter(postsArray, this, searchTerms[i]); | |
} | |
}); | |
}); | |
} | |
} | |
function forumSearch() | |
{ | |
var start = performance.now(); | |
$('.list_row_odd').remove(); | |
var endpage; | |
if ($("#endpage_box").val()) | |
{ | |
endpage = parseInt($("#endpage_box").val()); | |
} | |
else | |
{ | |
endpage = FindLastPageNumber(); | |
} | |
var startpage; | |
if ($("#startpage_box").val()) | |
{ | |
startpage = parseInt($("#startpage_box").val()); | |
} | |
else | |
{ | |
startpage = 1; | |
} | |
if (endpage > startpage + 500) | |
{ | |
endpage = startpage + 500; | |
} | |
var postsPerPage = 20; | |
var currentPostsOnPage = 0; | |
var currentPage = 1; | |
var selectedPage = 1; | |
var postsArray = {}; | |
var searchTerms = splitSearchTerms(); | |
$(document).off('ajaxStop'); | |
$( document ).ajaxStop(function() { | |
if (!jQuery.isEmptyObject(postsArray)) | |
{ | |
var postsKeys = Object.keys(postsArray); | |
postsKeys.sort(function (a, b) | |
{ | |
var dateA = parseDate($(postsArray[a]).find(".last_update").text()); | |
var dateB = parseDate($(postsArray[b]).find(".last_update").text()); | |
return dateB - dateA; | |
}); | |
for (var i = 0; i < postsKeys.length; i++) | |
{ | |
var k = postsKeys[i]; | |
var post = postsArray[k]; | |
if (!$(".page" + currentPage + "posts").length) | |
{ | |
var $newdiv = $( "<div class='page" + currentPage + "posts'/>" ); | |
$( "#t_norm > .list_row_h" ).append($newdiv); | |
} | |
$(post).appendTo(".page" + currentPage + "posts"); | |
currentPostsOnPage++; | |
if (currentPostsOnPage > postsPerPage) | |
{ | |
currentPostsOnPage = 0; | |
currentPage++; | |
} | |
} | |
var end = performance.now(); | |
var timeTaken = Math.round((end - start) / 1000); | |
var resultPost = getNumberOfResultsForum(postsKeys.length, timeTaken); | |
$(resultPost).prependTo( "#t_norm > .list_row_h" ); | |
} | |
else | |
{ | |
var noResultPost = getNoResultForum(); | |
$(noResultPost).appendTo( "#t_norm > .list_row_h" ); | |
} | |
}); | |
for (var i = startpage; i < endpage + 1; i++) | |
{ | |
debugLogger.debugLog('Page Number: ' + i); | |
var fullURL = window.location.pathname; | |
var threadURL = RemoveLastDirIfLonger(fullURL, 3) + "/page" + i; | |
ajaxQueue.add( threadURL, function( data ) { | |
var $page = $(data); | |
$page.find('.list_row_odd').each(function( index ) { | |
for (var i = 0; i < searchTerms.length; i++) | |
{ | |
debugLogger.debugLog('Search Term: ' + searchTerms[i]); | |
forumFilter(postsArray, this, searchTerms[i]); | |
} | |
}); | |
}); | |
} | |
} | |
function threadSearchWithinResults() | |
{ | |
var start = performance.now(); | |
var postsPerPage = 20; | |
var currentPostsOnPage = 0; | |
var currentPage = 1; | |
var selectedPage = 1; | |
var postsArray = {}; | |
var searchTerms = splitSearchTerms(); | |
$(document).off('ajaxStop'); | |
$('.big_post_h').parents('.spot_h').each(function( index ) { | |
for (var i = 0; i < searchTerms.length; i++) | |
{ | |
threadFilter(postsArray, this, searchTerms[i]); | |
} | |
}); | |
$('.spot_h').remove(); | |
if (!jQuery.isEmptyObject(postsArray)) | |
{ | |
var postsKeys = Object.keys(postsArray); | |
postsKeys.sort(naturalCompare); | |
for (var i = 0; i < postsKeys.length; i++) | |
{ | |
var k = postsKeys[i]; | |
var post = postsArray[k]; | |
if (!$(".page" + currentPage + "posts").length) | |
{ | |
var $newdiv = $( "<div class='page" + currentPage + "posts'/>" ) | |
$( ".list_h" ).append($newdiv) | |
} | |
$(post).appendTo(".page" + currentPage + "posts"); | |
currentPostsOnPage++; | |
if (currentPostsOnPage > postsPerPage) | |
{ | |
currentPostsOnPage = 0; | |
currentPage++; | |
} | |
} | |
var end = performance.now(); | |
var timeTaken = Math.round((end - start) / 1000); | |
var post = getNumberOfResultsThread(postsKeys.length, timeTaken); | |
$(post).prependTo( ".list_h" ); | |
} | |
else | |
{ | |
var post = getNoResultThread(); | |
$(post).appendTo( ".list_h" ); | |
} | |
if ($(".quick_post").length) | |
{ | |
$(".list_h").append($(".quick_post")); | |
} | |
} | |
function forumSearchWithinResults() | |
{ | |
var start = performance.now(); | |
var postsPerPage = 20; | |
var currentPostsOnPage = 0; | |
var currentPage = 1; | |
var selectedPage = 1; | |
var postsArray = {}; | |
var searchTerms = splitSearchTerms(); | |
$(document).off('ajaxStop'); | |
$('.list_row_odd').each(function( index ) { | |
for (var i = 0; i < searchTerms.length; i++) | |
{ | |
forumFilter(postsArray, this, searchTerms[i]); | |
} | |
}); | |
$('.list_row_odd').remove(); | |
if (!jQuery.isEmptyObject(postsArray)) | |
{ | |
var postsKeys = Object.keys(postsArray); | |
postsKeys.sort(function (a, b) | |
{ | |
var dateA = parseDate($(postsArray[a]).find(".last_update").text()); | |
var dateB = parseDate($(postsArray[b]).find(".last_update").text()); | |
return dateB - dateA; | |
}); | |
for (var i = 0; i < postsKeys.length; i++) | |
{ | |
var k = postsKeys[i]; | |
var post = postsArray[k]; | |
if (!$(".page" + currentPage + "posts").length) | |
{ | |
var $newdiv = $( "<div class='page" + currentPage + "posts'/>" ); | |
$( "#t_norm > .list_row_h" ).append($newdiv); | |
} | |
$(post).appendTo(".page" + currentPage + "posts"); | |
currentPostsOnPage++; | |
if (currentPostsOnPage > postsPerPage) | |
{ | |
currentPostsOnPage = 0; | |
currentPage++; | |
} | |
} | |
var end = performance.now(); | |
var timeTaken = Math.round((end - start) / 1000); | |
var resultPost = getNumberOfResultsForum(postsKeys.length, timeTaken); | |
$(resultPost).prependTo( "#t_norm > .list_row_h" ); | |
} | |
else | |
{ | |
var noResultPost = getNoResultForum(); | |
$(noResultPost).appendTo( "#t_norm > .list_row_h" ); | |
} | |
} | |
function threadReplies() | |
{ | |
$('.spot_h').remove(); | |
var endpage; | |
if ($("#endpage_box").val()) | |
{ | |
endpage = parseInt($("#endpage_box").val()); | |
} | |
else | |
{ | |
endpage = FindLastPageNumber(); | |
} | |
var startpage; | |
if ($("#startpage_box").val()) | |
{ | |
startpage = parseInt($("#startpage_box").val()); | |
} | |
else | |
{ | |
startpage = 1; | |
} | |
if (endpage > startpage + 500) | |
{ | |
endpage = startpage + 500; | |
} | |
var postsPerPage = 20; | |
var currentPostsOnPage = 0; | |
var currentPage = 1; | |
var selectedPage = 1; | |
var postsArray = {}; | |
$(document).off('ajaxStop'); | |
$( document ).ajaxStop(function() { | |
if (!jQuery.isEmptyObject(postsArray)) | |
{ | |
var postsKeys = Object.keys(postsArray); | |
postsKeys.sort(naturalCompare); | |
for (var i = 0; i < postsKeys.length; i++) | |
{ | |
var k = postsKeys[i]; | |
var post = postsArray[k]; | |
if (!$(".page" + currentPage + "posts").length) | |
{ | |
var $newdiv = $( "<div class='page" + currentPage + "posts'/>" ) | |
$( ".list_h" ).append($newdiv) | |
} | |
$(post).appendTo(".page" + currentPage + "posts"); | |
currentPostsOnPage++; | |
if (currentPostsOnPage > postsPerPage) | |
{ | |
currentPostsOnPage = 0; | |
currentPage++; | |
} | |
} | |
} | |
else | |
{ | |
var post = getNoResultThread(); | |
$(post).appendTo( ".list_h" ); | |
} | |
if ($(".quick_post").length) | |
{ | |
$(".list_h").append($(".quick_post")); | |
} | |
}); | |
for (var i = startpage; i < endpage + 1; i++) | |
{ | |
var fullURL = window.location.pathname; | |
var threadURL = RemoveLastDirIfLonger(fullURL, 4) + "/page" + i; | |
ajaxQueue.add( threadURL, function( data ) { | |
var $page = $(data); | |
$page.find('.big_post_h').parents('.spot_h').each(function( index ) { | |
if ($(this).find('.r_t_y').length) | |
{ | |
postsArray[this.id] = this; | |
} | |
}); | |
}); | |
} | |
} | |
function forumReplies() | |
{ | |
window.location.href = "http://www.gog.com/forum/myrecentposts"; | |
} | |
function parseDate(dateString) | |
{ | |
if (dateString.indexOf("now") >= 0) | |
{ | |
return Date.now(); | |
} | |
else if (dateString.indexOf("min") >= 0) | |
{ | |
var mins = StripNonNumbersParse(dateString) * 60000; | |
return new Date(Date.now() - mins); | |
} | |
else if (dateString.indexOf("hrs") >= 0) | |
{ | |
var hrs = StripNonNumbersParse(dateString) * 3600000; | |
return new Date(Date.now() - hrs); | |
} | |
else if (dateString.indexOf("Yesterday") >= 0) | |
{ | |
var today = new Date(); | |
var yesterday = new Date(today); | |
yesterday.setDate(today.getDate() - 1); | |
return yesterday; | |
} | |
else if (dateString.indexOf("days") >= 0) | |
{ | |
var days = StripNonNumbersParse(dateString) | |
var today = new Date(); | |
var date = new Date(today); | |
date.setDate(today.getDate() - days); | |
return date; | |
} | |
else | |
{ | |
var aString = dateString.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g,""); | |
var strArray = aString.split(" "); | |
var month = months[strArray[0]]; | |
var day = strArray[1]; | |
var year = strArray[2]; | |
return new Date(year, month, day); | |
} | |
} | |
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: 45px; color: #a1a1a1; font-size: 12px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; -khtml-border-radius: 10px; border-bottom: #aaa 1px solid; border-top: #aaa 1px solid; margin-bottom: 10px;}'); | |
addGlobalStyle('div.nav_bar_top_h { width: 950px; height: 141px; margin: 0 23px 0 23px; padding: 28px 0 0 0; position: relative;}'); | |
addGlobalStyle('#filter_go { display: inline; float: right; background: #aaa; color: #ececec; padding: 4px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 5px; -khtml-border-radius: 10px; }'); | |
addGlobalStyle('#find_replies_button { display: inline; position: absolute; right: 60px; margin: 2px; }'); | |
addGlobalStyle('.highlight { background-color: #FFFF88; color: #000; }'); | |
var $filterbar = $( '<div id="gogSearchBox"><div><p style="display: inline;">Search: </p><input type="text"value="" id="search_text_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: 50px;"><a id="find_replies_button"><div title="Show Replies" class="r_t_y"></div></a><a title="Search" id="filter_go">Go</a></div><div style="padding: 10px 0px 0px 10px;"><input type="checkbox" id="posts_checkbox" value="True" checked style="display: inline; margin-right: 5px;"> <p style="display: inline; margin-right: 20px;">Posts</p><input type="checkbox" id="usernames_checkbox" value="True" style="display: inline; margin-right: 5px;" checked><p style="display: inline; margin-right: 20px;">Usernames</p><input type="checkbox" id="bold_checkbox" value="True" style="display: inline; margin-right: 5px;"><p style="display: inline; margin-right: 20px;">Bold</p><p id="version" style="display: inline; float: right; font-size: 75%; margin-top: 2px;">' + versionNumber + '</p><input type="checkbox" id="resultsSearch_checkbox" value="True" style="display: inline; float: right;margin-right: 26px;"><p style="display: inline; float: right;margin-right: 5px;font-style: italic;">Search Within Results</p><input type="checkbox" id="highlight_checkbox" value="True" style="display: inline; float: right;margin-right: 10px;"><p style="display: inline; float: right;margin-right: 5px;font-style: italic;">Highlight Results</p></div></div>' ); | |
$( ".nav_bar_top_h" ).prepend($filterbar); | |
if (checkIsForumPage()) | |
{ | |
$( "#filter_go" ).on("click", forumSearchBase); | |
$('#search_text_box, #endpage_box, #startpage_box').bind("enterKey", forumSearchBase); | |
$('#search_text_box, #endpage_box, #startpage_box').keyup(function(e){ | |
if(e.keyCode == 13) | |
{ | |
$(this).trigger("enterKey"); | |
} | |
}); | |
$( "#find_replies_button" ).on("click", forumReplies); | |
} | |
else | |
{ | |
$( "#filter_go" ).on("click", threadSearchBase); | |
$('#search_text_box, #endpage_box, #startpage_box').bind("enterKey", threadSearchBase); | |
$('#search_text_box, #endpage_box, #startpage_box').keyup(function(e){ | |
if(e.keyCode == 13) | |
{ | |
$(this).trigger("enterKey"); | |
} | |
}); | |
$( "#find_replies_button" ).on("click", threadReplies); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment