// ==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://*neogaf.com/forum/forumdisplay.php?f=* // @version 0.7 // @downloadURL none // ==/UserScript== var sThreadTitle; currentVisibleThreads = []; nShownCount = 0; nOriginalPageCount = GetNextPage(); nPageCount = nOriginalPageCount; nAdditionalThreadCount = 0; $(document).ready(function() { CheckCloudSync(); CheckExpiredThreads(); CreateStyles(); CreateFilter(); CreateControlPanel(); CreateEventHandlers(); SetOptions(); UpdateHideLinks(); UpdateThreads(); }); function CreateStyles() { $("body").append(""); if (localStorage.getItem("HideLinkStyle") != "HideShow") $("body").append(GetRemoveStyle()); } function CreateFilter() { $('.large-button:first').parent().append(" "); } function GetRemoveStyle() { var HideThreadStyle = 'margin-left: -11px; margin-top: -38px;'; var HideThreadStyle2 = 'padding-left:10px; margin-left:-45px; margin-top:-2px;'; RemoveStyle = ''; return RemoveStyle; } function UpdateHideLinks() { $("td[id*='td_threadstatusicon_']").each(function( index,value ) { AddHideLink(this);}); } function CreateEventHandlers() { $('#ThreadFilter').change(function() { UpdateThreads(); UpdateHideLinks();}); $('#OpenFilterCP').click(OpenFilterCP); $('#AddWordButton').click(AddToWordFilter); $('#AddIgnoredUserButton').click(AddToIgnoredUserList); $('input[name="HideLinkStyle"]').change(function () { localStorage.setItem('HideLinkStyle', this.value); RemoveHideLinks(); SaveLastUpdate();}); $('#SearchAdditional').change(function() { localStorage.setItem('SearchAdditional', this.checked); SaveLastUpdate();}); $('#CloudSync').change(function() { localStorage.setItem('CloudSync', this.checked); ShowCloudSyncOptions(this); }); $('#CloudSyncFrequency').change(function() { localStorage.setItem('CloudSyncFrequency', this.value); SaveLastUpdate(); }); $('#CloudSyncKey').change(function() {CloudKeyChanged(this.value);}); $('#GenerateCloudSyncKey').click(GenerateCloudSyncKey); $('#ThreadExpiration').change(function() { localStorage.setItem('ThreadExpiration', this.checked); if (localStorage.getItem('ExpirationDays') == null) {localStorage.setItem('ExpirationDays',30); document.getElementById("ExpirationDays").value = localStorage.getItem("ExpirationDays");} $('#ThreadExpirationOptions').toggle(); SaveLastUpdate(); }); $('#ExpirationDays').change(function() {localStorage.setItem('ExpirationDays', this.value);}); } function RemoveHideLinks() { $("a[id*='RemoveThread']").remove(); $("a[id*='RemoveUser']").remove(); $("#RemoveStyle").remove(); if (localStorage.getItem("HideLinkStyle") != "HideShow") $("body").append(GetRemoveStyle()); } function SetOptions() { document.getElementById("ThreadFilter").value = CheckThreadFilterValue(localStorage.getItem("ThreadFilter")); if (localStorage.getItem("CloudSyncKey")) document.getElementById("CloudSyncKey").value = localStorage.getItem("CloudSyncKey"); if (!localStorage.getItem("HideLinkStyle")) localStorage.setItem("HideLinkStyle","X"); if (localStorage.getItem("ExpirationDays")) document.getElementById("ExpirationDays").value = localStorage.getItem("ExpirationDays"); CheckSettingOption("SearchAdditional"); CheckSettingOption("CloudSync"); CheckSettingOption("HideLinkStyle"); CheckSettingOption("ThreadExpiration"); $('#ThreadExpirationOptions').css('display',$('#ThreadExpiration').prop('checked') ? 'block' : 'none'); } function UpdateThreads() { nShownCount = 0; $('#ThreadFilter').blur(); localStorage.setItem('ThreadFilter',document.getElementById("ThreadFilter").value); currentVisibleThreads = []; $("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 { currentVisibleThreads.push(nThreadID); nShownCount++; $(this).parent().show(); } }); if (localStorage.getItem("SearchAdditional") == "true") { nPageCount = nOriginalPageCount; 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 && $.inArray(nThreadID,currentVisibleThreads) == -1) { $(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; addItem.AddDate = new Date(); 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); containsObject(nCurrentID,CurrentList,addItem); //if (nFoundIndex == -1) // CurrentList.push(addItem); // else // CurrentList.splice(nFoundIndex,1); localStorage.setItem(sList, JSON.stringify(CurrentList)); if (event.data.param3) event.data.param3(); AddHideLink(event.data.param4); SaveLastUpdate(); CheckCloudUpdateNeeded(); return 0; } function AddHideLink(currentThread) { IgnoreList = GetListFromLocalStorage('IgnoreList'); IgnoredUserList = GetListFromLocalStorage('IgnoredUserList'); 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 bThreadIgnored = (containsObject(nThreadID,IgnoreList) == -1) ? false : true; var bUserIgnored = (containsObject(nUserID,IgnoredUserList) == -1) ? false : true; var sThreadFilterVal = $('#ThreadFilter').val(); if (sThreadFilterVal == 'Unignored') { ThreadIgnoreText = "Hide"; UserIgnoreText = "Remove"; } else { ThreadIgnoreText = bThreadIgnored ? "Show" : "Hide"; UserIgnoreText = bUserIgnored ? "Restore" : "Remove"; } if ($(currentThread).has("a[id*='RemoveThread" + nThreadID + "']").length == 0) { var RemoveUserLinks = $('a[id*=RemoveUser' + nUserID + ']').toArray(); sUserIDReference = (RemoveUserLinks.length > 0) ? nUserID + RemoveUserLinks.length : nUserID; if (localStorage.getItem("HideLinkStyle") == "HideShow") $(MemberLink).after("
" + UserIgnoreText + " User"); else $(MemberLink).before("" + UserIgnoreText + " User"); $('#RemoveUser' + sUserIDReference).click({param1: nUserID, param2: 'IgnoredUserList', param3: UpdateThreads, param4: currentThread}, IgnoreItem); $('', { id: "RemoveThread" + nThreadID, text: ThreadIgnoreText }).appendTo(currentThread); $('#RemoveThread' + nThreadID).click({param1: nThreadID, param2: 'IgnoreList', param3: UpdateThreads, param4: currentThread}, IgnoreItem); } else { $('#RemoveThread' + nThreadID).text(ThreadIgnoreText); $('a[id*=RemoveUser' + nUserID).text(UserIgnoreText + " User"); } } 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) { CurrentArea = GetCurrentArea(); var bFilterApplies = false; WordList = GetListFromLocalStorage('WordList'); jQuery.each(WordList,function (index) { if (this.Area == null || this.Area == 'All' || this.Area == CurrentArea) { 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 GetCurrentArea() { CurrentLocation = window.location.href; if (CurrentLocation.indexOf("f=3") != -1 || CurrentLocation.indexOf("f=20") != -1) return "Off-Topic"; else if (CurrentLocation.indexOf("f=2") != -1 || CurrentLocation.indexOf("f=8") != -1) return "Gaming"; } function AddToWordFilter(event) { newWord = $('#AddWordText').val(); var addWord = {}; addWord.Word = newWord; addWord.Type = $('input[name*=AddWordType]:checked').val(); addWord.Area = $('input[name*=AddWordArea]:checked').val(); WordList = GetListFromLocalStorage('WordList'); nWordIndex = containsObject(addWord.Word, WordList); if (nWordIndex == -1) { WordList.push(addWord); } localStorage.setItem('WordList', JSON.stringify(WordList)); $('#AddWordText').val(''); $('input[name="AddWordArea"][value="All"]').prop('checked', true); UpdateListing('WordListing', 'WordList'); localStorage.setItem("LastUpdate",new Date()); CheckCloudUpdateNeeded(); } 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'); localStorage.setItem("LastUpdate",new Date()); CheckCloudUpdateNeeded(); } function CreateControlPanel() { var sControlPanel = "

"; $('.large-button:first').parent().append(sControlPanel); $('.large-button:first').parent().append($('Filter CP')); } function CreateWordFilter() { sWordFilter = "
"; sWordFilter += "Add New Word: 
"; sWordFilter += "
Type - Plain Text (* supported)Regular Expression

"; sWordFilter += "
Area - All Gaming Off-Topic
"; sWordFilter += "


"; sWordFilter += "
"; return sWordFilter; } function CreateIgnoredUserTab() { sIgnoredUserTab = "
"; return sIgnoredUserTab; } function CreateSettingsOptions() { sCreateSettings = "Hide Link Style
X Hide/Show"; sCreateSettings += "

"; sCreateSettings += "Search additional pages for threads"; sCreateSettings += "
"; sCreateSettings += "Thread Expiration"; sCreateSettings += ""; sCreateSettings += "
"; sCreateSettings += "Cloud sync"; sCreateSettings += "
"; return sCreateSettings; } function CheckSettingOption(sSetting) { if (sSetting == "HideLinkStyle") $('input[name="HideLinkStyle"][value="' + localStorage.getItem(sSetting) + '"]').prop('checked', true); else { if (localStorage.getItem(sSetting)) $("#" + sSetting).attr("checked", localStorage.getItem(sSetting) == "true" ? true : false); else if (sSetting != "CloudSync" && sSetting != "ThreadExpiration") localStorage.setItem(sSetting, "true"); } } function OpenFilterCP() { UpdateListing('WordListing', 'WordList'); UpdateListing('RecentlyIgnoredListing', 'IgnoreList'); UpdateListing('IgnoredUserListing', 'IgnoredUserList'); ShowCloudSyncOptions(); $('#tabs').tabs(); $('#tabs').dialog(); $('#tabs').bind('dialogclose', function(event) { CheckExpiredThreads(); UpdateThreads(); UpdateHideLinks(); }); $('#tabs').dialog({ title: "Filter Control Panel"}); $("#tabs").dialog("option", "width", '60%'); } 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 = 'WordTypeArea'; 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 + '' + (this.Area != null ? this.Area : 'All') + '
'; $('#' + 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); localStorage.setItem("LastUpdate",new Date()); CheckCloudUpdateNeeded(); } function containsObject(id, list, addItem) { if (list.length > 0) { if (list[0].hasOwnProperty('ID')) return binaryIndexOf(id,list,addItem); else { for (var i = 0; i < list.length; i++) if (list[i].ID == id || list[i].Word == id) return i; } } else if (typeof addItem === 'object') list.splice(0, 0, addItem); return -1; } function binaryIndexOf(id,list,addItem) { 'use strict'; var minIndex = 0; var maxIndex = list.length - 1; var currentIndex; var currentElement; if (localStorage.getItem("IgnoredThreadsSorted") != "true") { list = list.sort(sortByID); localStorage.setItem("IgnoreList",JSON.stringify(list)); localStorage.setItem("IgnoredThreadsSorted","true"); } if ((parseInt(id) < parseInt(list[minIndex].ID) || parseInt(id) > parseInt(list[maxIndex].ID)) && typeof addItem === 'undefined') return -1; while (minIndex <= maxIndex) { currentIndex = (minIndex + maxIndex) / 2 | 0; currentElement = list[currentIndex].ID; if (parseInt(currentElement) < parseInt(id)) { minIndex = currentIndex + 1; } else if (parseInt(currentElement) > parseInt(id)) { maxIndex = currentIndex - 1; } else { if (typeof addItem === 'undefined') return currentIndex; else { list.splice(currentIndex,1); //localStorage.setItem('IgnoreList', JSON.stringify(list)); writeignored(list); return currentIndex; } } } if (typeof addItem === 'undefined') return -1; else { //console.log(minIndex + ' - ' + maxIndex + ' - ' + addItem.ID + ' - ' + addItem.Title); list.splice(minIndex, 0, addItem); //localStorage.setItem('IgnoreList', JSON.stringify(list)); } } function writeignored(list) { for (var i = 0; i < list.length; i++) console.log(list[i].ID); } function sortByID(a, b) { return a.ID - b.ID; } 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 CheckExpiredThreads() { if (localStorage.getItem("ThreadExpiration") == "true") { if (!localStorage.getItem("LastExpirationCheck")) localStorage.setItem("LastExpirationCheck",new Date()); var checkexpirationdate = new Date(localStorage.getItem("LastExpirationCheck")); checkexpirationdate.setDate(checkexpirationdate.getDate() + 1); if (new Date() >= checkexpirationdate) { var madechange = false; var expirationdays = parseInt(localStorage.getItem("ExpirationDays")); var threadexpiration; ignoreList = GetListFromLocalStorage('IgnoreList'); for (i = 0; i < ignoreList.length; i++) { if (typeof ignoreList[i].AddDate === 'undefined') { ignoreList[i].AddDate = new Date(); madechange = true; } else { threadexpiration = new Date(ignoreList[i].AddDate); threadexpiration.setDate(threadexpiration.getDate() + expirationdays); if (new Date() >= threadexpiration) { ignoreList.splice(i,1); madechange = true; } } } if (madechange == true) { localStorage.setItem("IgnoreList",JSON.stringify(ignoreList)); SaveLastUpdate(); CheckCloudUpdateNeeded(); } localStorage.setItem("LastExpirationCheck",new Date()); } } } var Type = "POST"; var URL; var URLPrefix = "http://ec2-54-149-209-12.us-west-2.compute.amazonaws.com/HideThreads/api/HideThreads/"; var Data = {}; var ContentType = "application/json; charset=utf-8"; var DataType = "json"; function CheckCloudSync() { if (localStorage.getItem("CloudSync") == "true" && localStorage.getItem("CloudSyncKey")) { CheckCloudUpdateNeeded(); if (localStorage.getItem("CloudSyncFrequency") != 'Instant') setInterval(CheckCloudUpdateNeeded, 1000 * 60); } } function GetCloudSyncDateSucceeded(result) { if (!localStorage.getItem("CloudSyncFrequency")) localStorage.setItem("CloudSyncFrequency","5"); currentDate = new Date(); if (localStorage.getItem("CloudSyncFrequency") != 'Instant') { nextDate = new Date(localStorage.getItem("CloudSyncDate")); nextDate.setTime(nextDate.getTime() + parseInt(localStorage.getItem("CloudSyncFrequency")) * 60 * 1000); } else nextDate = currentDate; date2 = localStorage.getItem("CloudSyncDate") ? new Date(localStorage.getItem("CloudSyncDate")) : new Date(); date1 = new Date(result); //console.log(date1 + ' - ' + date2); if (result != 'None') { CloudKeyFound(); if (!result || (result && localStorage.getItem("CloudSyncDate") && date2 > date1) || (currentDate >= nextDate && new Date(localStorage.getItem("LastUpdate")) > new Date(localStorage.getItem("CloudSyncDate")))) SendInfoToCloud(new Date()); else if (!localStorage.getItem("CloudSyncDate") || (result && localStorage.getItem("CloudSyncDate") && date1 > date2)) GetInfoFromCloud(); } else if (localStorage.getItem("CloudSyncKey")) CloudKeyNotFound(); } function ShowCloudSyncOptions() { $('#CloudSyncOptions').css('display',$('#CloudSync').prop('checked') ? 'block' : 'none'); if (!localStorage.getItem('CloudSyncFrequency')) localStorage.setItem('CloudSyncFrequency','5'); $('#CloudSyncFrequency').val(localStorage.getItem('CloudSyncFrequency')); } function GetInfoFromCloud() { URL = "GetHideForumThreadsInfoNew?Key=" + localStorage.getItem("CloudSyncKey"); Data = ""; CallService(GetHideForumThreadsInfo); } function GetHideForumThreadsInfo(result) { if (result.CloudSyncDate != null) { localStorage.setItem("CloudSyncDate",result.CloudSyncDate); localStorage.setItem("SearchAdditional",result.SearchAdditional); localStorage.setItem("ThreadFilter",result.ThreadFilter); localStorage.setItem("IgnoredThreadsSorted",result.IgnoredThreadsSorted); localStorage.setItem("ThreadExpiration",result.ThreadExpiration); localStorage.setItem("ExpirationDays",result.ExpirationDays); localStorage.setItem("LastExpirationCheck",result.LastExpirationCheck); localStorage.setItem("IgnoredUserList",result.IgnoredUserList); localStorage.setItem("IgnoreList",result.IgnoreList); localStorage.setItem("WordList",result.WordList); localStorage.setItem("HideLinkStyle",result.HideLinkStyle); console.log("info received from cloud"); SetOptions(); RemoveHideLinks(); CloudKeyFound(); } else CloudKeyNotFound(); } function SaveLastUpdate() { localStorage.setItem("LastUpdate",new Date()); } function CloudKeyChanged(CurrentKey) { localStorage.setItem("CloudSyncKey",CurrentKey); if (CurrentKey != '') GetInfoFromCloud(); else CloudKeyNotFound(); } function CloudKeyFound() { $('#CloudKeyNotFoundMessage').hide(); ShowLastCloudUpdate(); } function CloudKeyNotFound() { $('#CloudKeyNotFoundMessage').show(); $('#LastCloudUpdate').hide(); } function ShowLastCloudUpdate() { document.getElementById("LastCloudUpdateTime").innerHTML = localStorage.getItem("CloudSyncDate"); $('#LastCloudUpdate').show(); } function GenerateCloudSyncKey() { localStorage.setItem("CloudSyncKey","None"); SendInfoToCloud(new Date()); } function SendInfoToCloud(currentDate) { localStorage.setItem("CloudSyncDate",currentDate); $.ajax({ url: URLPrefix + "UpdateHideForumThreadsInfoNew", type: "POST", data: {Key:localStorage.getItem("CloudSyncKey"), CloudSyncDate: currentDate, SearchAdditional: localStorage.getItem("SearchAdditional") ? localStorage.getItem("SearchAdditional") : "", ThreadFilter: localStorage.getItem("ThreadFilter") ? localStorage.getItem("ThreadFilter") : "", IgnoredThreadsSorted: localStorage.getItem("IgnoredThreadsSorted") ? localStorage.getItem("IgnoredThreadsSorted") : "", ThreadExpiration: localStorage.getItem("ThreadExpiration") ? localStorage.getItem("ThreadExpiration") : "", ExpirationDays: localStorage.getItem("ExpirationDays") ? localStorage.getItem("ExpirationDays") : "", LastExpirationCheck: localStorage.getItem("LastExpirationCheck") ? localStorage.getItem("LastExpirationCheck") : "", IgnoredUserList: localStorage.getItem("IgnoredUserList") ? localStorage.getItem("IgnoredUserList") : "[]", IgnoreList: localStorage.getItem("IgnoreList") ? localStorage.getItem("IgnoreList") : "[]", WordList: localStorage.getItem("WordList") ? localStorage.getItem("WordList") : "[]", HideLinkStyle: localStorage.getItem("HideLinkStyle") ? localStorage.getItem("HideLinkStyle") : "X", Username: GetUsername()}, success: Success, dataType: "json", error: ServiceFailed }); } function GetUsername() { Username = $('#usercptools').text().replace('Welcome ',''); UsernamePattern = new RegExp("([A-Za-z0-9]+)"); FoundUsername = UsernamePattern.exec(Username); if (FoundUsername != null) return FoundUsername[0].toString(); else return "None"; } function Success(result) { localStorage.setItem("CloudSyncKey", result); document.getElementById("CloudSyncKey").value = localStorage.getItem("CloudSyncKey"); CloudKeyFound(); console.log("info sent to cloud"); } function CheckCloudUpdateNeeded() { if (localStorage.getItem("CloudSync") == "true" && localStorage.getItem("CloudSyncKey")) { URL = "GetCloudSyncDate?Key=" + localStorage.getItem("CloudSyncKey"); CallService(GetCloudSyncDateSucceeded); } } // Function to call WCF Service function CallService(succeededcallback) { $.ajax({ type: Type, //GET or POST or PUT or DELETE verb url: URLPrefix + URL, // Location of the service contentType: ContentType, // content type sent to server dataType: DataType, //Expected data format from server data: Data, processdata: true, //True or False success: function(msg) {//On Successful service call indirectCaller(succeededcallback,msg); }, error: ServiceFailed// When Service call fails }); } function ServiceFailed(xhr) { console.log('error - ' + xhr.responseText); if (xhr.responseText) { var err = xhr.responseText; if (err) error(err); else error({ Message: "Unknown server error." }) } return; } function indirectCaller(f,msg) { // Call `caller`, who will in turn call `f` f(msg); }