// ==UserScript== // @name NeoGAF - Hide Forum Threads // @namespace ThreadFilter // @description Hides threads on NeoGAF.com // @require http://code.jquery.com/jquery-latest.min.js // @require http://code.jquery.com/ui/1.11.2/jquery-ui.min.js // @include http://www.neogaf.com/forum/forumdisplay.php?f=* // @version 0.4 // @downloadURL none // ==/UserScript== var sThreadTitle; nShownCount = 0; nOriginalPageCount = GetNextPage(); nPageCount = nOriginalPageCount; nAdditionalThreadCount = 0; $(document).ready(function() { IgnoreList = GetListFromLocalStorage('IgnoreList'); var sHideThreadStyle = 'margin-left: -11px; margin-top: -38px;'; var sHideThreadStyle2 = 'padding-left:10px; margin-left:-45px; margin-top:-2px;'; var sRemoveStyle = ''; $("body").append(""); $("body").append(sRemoveStyle); $('.large-button:first').parent().append(" "); var sControlPanel = "
"; $('.large-button:first').parent().append(sControlPanel); $('.large-button:first').parent().append($('Filter CP')); $('#ThreadFilter').change(UpdateThreads); $('#OpenFilterCP').click(OpenFilterCP); $('#AddWordButton').click(AddToWordFilter); $('#AddIgnoredUserButton').click(AddToIgnoredUserList); $('#SearchAdditional').change(function() { localStorage.setItem('SearchAdditional', this.checked); }); $("td[id*='td_threadstatusicon_']").each(function( index,value ) { AddHideLink(this);}); document.getElementById("ThreadFilter").value = CheckThreadFilterValue(localStorage.getItem("ThreadFilter")); if (localStorage.getItem("SearchAdditional")) $("#SearchAdditional").attr("checked", localStorage.getItem("SearchAdditional") == "true" ? true : false); else localStorage.setItem("SearchAdditional", "true"); UpdateThreads(); }); function UpdateThreads() { nShownCount = 0; $('#ThreadFilter').blur(); localStorage.setItem('ThreadFilter',document.getElementById("ThreadFilter").value); $("td[id*=td_threadstatusicon_]").each(function(index) { nThreadID = $(this).attr('id').replace('td_threadstatusicon_',''); sThreadTitle = $('#thread_title_' + nThreadID).text(); sUserID = $(this).siblings().find('a[href*="member.php?u="]')[0].href.replace("http://www.neogaf.com/forum/member.php?u=",""); if (CheckThreadHidden(nThreadID,sThreadTitle,sUserID)) $(this).parent().hide(); else { nShownCount++; $(this).parent().show(); } }); if (localStorage.getItem("SearchAdditional") == "true") { GetAdditionalThreads(); } } function GetAdditionalThreads() { if (nShownCount < 40 && nPageCount <= (parseInt(nOriginalPageCount) + 5)) { var jqxhr = $.get(window.location.href + "&order=desc&page=" + nPageCount, ProcessAdditionalThread) .done(function() { nPageCount ++; GetAdditionalThreads(); }); } } function ProcessAdditionalThread(data) { var lastThread = $("td[id*='td_threadstatusicon_']").last(); $(data).find("td[id*='td_threadstatusicon_']").each(function(index, value) { nThreadID = $(this).attr('id').replace('td_threadstatusicon_',''); sThreadTitle = $(data).find('#thread_title_' + nThreadID).text(); sUserID = $(this).siblings().find('a[href*="member.php?u="]')[0].href.replace("http://www.neogaf.com/forum/member.php?u=",""); nAdditionalThreadCount = nAdditionalThreadCount + 1; if (!CheckThreadHidden(nThreadID, sThreadTitle, sUserID) && nShownCount < 40) { $(lastThread).parent().after($(this).parent().clone().wrap('').parent().html()); AddHideLink($("td[id*=td_threadstatusicon_" + nThreadID + "]")); nShownCount++; } }); } function CheckThreadFilterValue(sFilterValue) { if (sFilterValue != "Unignored" && sFilterValue != "Ignored" && sFilterValue != "All") sFilterValue = "Unignored"; return sFilterValue; } function IgnoreItem(event) { var nCurrentID = event.data.param1; var sList = event.data.param2; var addItem = {}; addItem.ID = nCurrentID; if (sList == "IgnoreList") addItem.Title = $('#thread_title_' + nCurrentID).text(); else if (sList == "IgnoredUserList") addItem.Username = $('a[href="member.php?u=' + nCurrentID + '"]').attr("title"); CurrentList = GetListFromLocalStorage(sList); nFoundIndex = containsObject(nCurrentID,CurrentList); if (nFoundIndex == -1) CurrentList.push(addItem); else CurrentList.splice(nFoundIndex,1); localStorage.setItem(sList, JSON.stringify(CurrentList)); if (event.data.param3) event.data.param3(); return 0; } function AddHideLink(currentThread) { nThreadID = $(currentThread).attr('id').replace('td_threadstatusicon_',''); MemberLink = $(currentThread).siblings().find('a[href*="member.php?u="]')[0]; nUserID = MemberLink.href.replace("http://www.neogaf.com/forum/member.php?u=",""); var RemoveUserLinks = $('a[id*=RemoveUser' + nUserID + ']').toArray(); sUserIDReference = (RemoveUserLinks.length > 0) ? nUserID + RemoveUserLinks.length : nUserID; //if (RemoveUserLinks.length > 0) // console.log('multiple references to ' + nUserID); $(MemberLink).before("Remove User"); $('#RemoveUser' + sUserIDReference).click({param1: nUserID, param2: 'IgnoredUserList', param3: UpdateThreads}, IgnoreItem); if ($(currentThread).has("a[id*='RemoveThread" + nThreadID + "']").length == 0) { $('', { id: "RemoveThread" + nThreadID }).appendTo(currentThread); $('#RemoveThread' + nThreadID).click({param1: nThreadID, param2: 'IgnoreList', param3: UpdateThreads}, IgnoreItem); } } function CheckThreadHidden(nThreadID, sThreadTitle,sUserID) { var sThreadFilterVal = $('#ThreadFilter').val(); var bWordFilterApplies = false; var bUserFilterApplies = false; IgnoreList = GetListFromLocalStorage('IgnoreList'); nThreadIndex = containsObject(nThreadID,IgnoreList); var bThreadIgnored = (nThreadIndex == -1) ? false : true; if (bThreadIgnored && sThreadFilterVal == 'Unignored' ) { return true; } else { bWordFilterApplies = WordFilterApplies(sThreadTitle); if (bWordFilterApplies && sThreadFilterVal == 'Unignored') { return true; } else { bUserFilterApplies = containsObject(sUserID,GetListFromLocalStorage('IgnoredUserList')) != -1 ? true : false; if (bUserFilterApplies && sThreadFilterVal == 'Unignored') { return true; } else if (!bThreadIgnored && !bWordFilterApplies && !bUserFilterApplies && sThreadFilterVal == 'Ignored') { return true; } } } return false; } function WordFilterApplies(sThreadTitle) { var bFilterApplies = false; WordList = GetListFromLocalStorage('WordList'); jQuery.each(WordList,function (index) { if (this.Type == 'plaintext') { sFragments = this.Word.split('*'); bMatchesPattern = true; jQuery.each(sFragments, function(index) { if (sThreadTitle.toLowerCase().indexOf(this.toLowerCase()) == -1) { bMatchesPattern = false; } }); if (bMatchesPattern === true) { bFilterApplies = true; return 0; } } else if (this.Type == 'regularexpression') { sRegExMatches = sThreadTitle.match(this.Word); if (sRegExMatches) { bFilterApplies = true; return 0; } } }); return bFilterApplies; } function AddToWordFilter(event) { newWord = $('#AddWordText').val(); var addWord = {}; addWord.Word = newWord; addWord.Type = $('input[name*=AddWordType]:checked').val(); WordList = GetListFromLocalStorage('WordList'); nWordIndex = containsObject(addWord.Word, WordList); if (nWordIndex == -1) { WordList.push(addWord); } localStorage.setItem('WordList', JSON.stringify(WordList)); $('#AddWordText').val(''); UpdateListing('WordListing', 'WordList'); } function AddToIgnoredUserList(event) { newIgnoredUserText = $('#AddIgnoredUserText').val(); var addIgnoredUser = {}; addIgnoredUser.Username = newIgnoredUser; IgnoredUserList = GetListFromLocalStorage('IgnoredUserList'); nIgnoredUserIndex = containsObject(addIgnoredUser.Username, IgnoredUserList); if (nIgnoredUserIndex == -1) { IgnoredUserList.push(addIgnoredUser); } localStorage.setItem('IgnoredUserList', JSON.stringify(IgnoredUserList)); $('#AddIgnoredUserText').val(''); UpdateListing('IgnoredUserListing', 'IgnoredUserList'); } function CreateWordFilter() { sWordFilter = "
' + this.Word + ' | ' + this.Type + ' |