// ==UserScript== // @name NeoGAF - Hide Forum Threads Mobile // @namespace ThreadFilter // @description Hides threads in Vbulletin boards. // @require http://code.jquery.com/jquery-latest.min.js // @require http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js // @include http://m.neogaf.com/* // @version 0.2 // @downloadURL https://update.greasyfork.icu/scripts/7242/NeoGAF%20-%20Hide%20Forum%20Threads%20Mobile.user.js // @updateURL https://update.greasyfork.icu/scripts/7242/NeoGAF%20-%20Hide%20Forum%20Threads%20Mobile.meta.js // ==/UserScript== var sThreadTitle; nShownCount = 0; nOriginalPageCount = GetNextPage(); nPageCount = nOriginalPageCount; nAdditionalThreadCount = 0; $(document).ready(function() { IgnoreList = GetListFromLocalStorage('IgnoreList'); if (IsMobile()) { //$('#jumpToLogIn').after("
"); $('#jumpToLogIn').after("Show Unignored OnlyShow Ignored OnlyShow All"); $('#ShowUnignored').click(function() { localStorage.setItem('ThreadFilter','Unignored'); UpdateThreads();}); $('#ShowIgnored').click(function() { localStorage.setItem('ThreadFilter','Ignored'); UpdateThreads();}); $('#ShowAll').click(function() { localStorage.setItem('ThreadFilter','All'); UpdateThreads();}); $(".listItemAnchor").each(function( index ) { nThreadID = $(this).attr('href').replace('showthread.php?t=',''); $(this).attr('id',nThreadID); $(this).parent().on("swiperight",{param1: nThreadID, param2: 'IgnoreList', param3: UpdateThreads},IgnoreItem); $(this).parent().on("swipeleft",{param1: nThreadID, param2: 'IgnoreList', param3: UpdateThreads},IgnoreItem); //$(this).parent().on("swiperight",SwipeHandler); //$(this).parent().on("swipeleft",SwipeHandler); //return; //$(this).append("
" + sIgnoreText + ""); }); //$('div.listItem').on("swiperight",function (event) { IgnoreThread($(this).find('.listItemAnchor').attr('href').replace('showthread.php?t=',''));}); //$('div.listItem').on("swipeleft",function (event) { IgnoreThread($(this).find('.listItemAnchor').attr('href').replace('showthread.php?t=',''));}); //$('div.listItem').on("swiperight",{param1: $(this).find('.listItemAnchor').attr('href').replace('showthread.php?t=',''), param2: 'IgnoreList', param3: UpdateThreads},IgnoreItem); } else { 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); var sControlPanel = ""; $('.large-button:first').parent().append(" "); $('.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; if (IsMobile()) { $(".listItemAnchor").each(function(index) { nThreadID = $(this).attr('href').replace('showthread.php?t=',''); //sThreadTitle = $(this).find('.listItemTitle')[0].text(); console.log(sThreadTitle); if (CheckThreadHidden(nThreadID,sThreadTitle)) $(this).hide(); else { nShownCount++; $(this).show(); } }); } else { $('#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 <= 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 = CheckThreadFilterValue(localStorage.getItem("ThreadFilter")); 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 = "

"; sWordFilter += "Add New Word: 
Plain Text (* supported)Regular Expression


"; sWordFilter += "
"; return sWordFilter; } function CreateIgnoredUserTab() { sIgnoredUserTab = "
"; return sIgnoredUserTab; } function CreateSettingsOptions() { sCreateSettings = "Search additional pages for threads"; return sCreateSettings; } function OpenFilterCP() { UpdateListing('WordListing', 'WordList'); UpdateListing('RecentlyIgnoredListing', 'IgnoreList'); UpdateListing('IgnoredUserListing', 'IgnoredUserList'); $('#tabs').tabs(); $('#tabs').dialog(); $('#tabs').bind('dialogclose', function(event) { UpdateThreads();}); $('#tabs').dialog({ title: "Filter Control Panel"}); $("#tabs").dialog("option", "width", $("#tabs").dialog( "option", "width" ) + 200); } function UpdateListing(sListingDiv, sListName) { $('#' + sListingDiv).empty(); CurrentList = GetListFromLocalStorage(sListName); if (sListName == 'IgnoreList' || sListName == 'IgnoredUserList') CurrentList.reverse(); var sListingText; if (sListName == 'IgnoredUserList') sColumnHeadings = 'Username'; else if (sListName == 'IgnoreList') sColumnHeadings = 'Title'; else if (sListName == 'WordList') sColumnHeadings = 'WordType'; sListingText = '' + sColumnHeadings + ''; jQuery.each(CurrentList,function (index) { if (sListName == 'IgnoredUserList') sListingText += ''; else if (sListName == 'IgnoreList') sListingText += ''; else if (sListName == 'WordList') sListingText += ''; }); sListingText += '
 
' + this.Username + '
' + this.Title + '
' + this.Word + '
' + this.Type + '
'; $('#' + sListingDiv).append(sListingText); jQuery.each(CurrentList,function (index) { if (sListName == 'IgnoredUserList') $('#RemoveIgnoredUser' + this.ID).click({sCurrentID: this.ID, sListName: 'IgnoredUserList', sListDiv: 'IgnoredUserListing'}, RemoveIgnored); else if (sListName == 'IgnoreList') $('#RemoveRecentlyIgnored' + this.ID).click({sCurrentID: this.ID, sListName: 'IgnoreList', sListDiv: 'RecentlyIgnoredListing'}, RemoveIgnored); else if (sListName == 'WordList') $('#RemoveWord' + index).click({sCurrentID: this.Word, sListName: 'WordList', sListDiv: 'WordListing'}, RemoveIgnored); }); } function RemoveIgnored(event) { IgnoreList = GetListFromLocalStorage(event.data.sListName); nCurrentIndex = containsObject(event.data.sCurrentID,IgnoreList); IgnoreList.splice(nCurrentIndex,1); localStorage.setItem(event.data.sListName, JSON.stringify(IgnoreList)); UpdateListing(event.data.sListDiv,event.data.sListName); } function containsObject(id, list) { var i; for (i = 0; i < list.length; i++) { if (list[i].ID == id || list[i].Word == id) { return i; } } return -1; } function GetNextPage() { var str = window.location.href; var res = str.match("page=[0-9]+"); if (res) return parseInt(res[0].replace("page=","")) + 1; else return 2; } function GetListFromLocalStorage(sListName) { return localStorage.getItem(sListName) ? JSON.parse(localStorage.getItem(sListName)) : []; } function IsMobile() { return window.location.href.indexOf('m.neogaf') != -1 ? true : false; }