/*! // ==UserScript== // @name SteamGifts Tinkerer, Featuring Refined Ostensible Gain // @namespace https://github.com/bberenz/sgtfrog // @description SteamGifts.com user controlled enchancements // @icon https://raw.githubusercontent.com/bberenz/sgtfrog/master/keroro.gif // @include *://*.steamgifts.com/* // @version 1.4 // @downloadURL https://raw.githubusercontent.com/bberenz/sgtfrog/master/sgtfrog.user.js // @updateURL https://raw.githubusercontent.com/bberenz/sgtfrog/master/sgtfrog.meta.js // @require https://code.jquery.com/jquery-1.12.3.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/showdown/1.7.6/showdown.min.js // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // ==/UserScript== */ (function() { var $document = $(document), $window = $(window) urlBase = location.origin; if ($(".nav__sits").length) { console.warn("[RIBBIT] User is not logged in, cannot run script."); throw new Error("No lilypad."); } // Variables // var frogVars = { //Site related general: { fixedElms: { key: "fixedElms", value: GM_getValue("fixedElms", 6), query: "Set fixed elements:", set: { type: "square", options: ["Header", "Sidebar", "Footer"] } }, loadLists: { key: "loadLists", value: GM_getValue("loadLists", 15), query: "Continuously load:", set: { type: "square", options: ["Giveaways", "Discussions", "Comments", "General Content"] } }, searchNav: { key: "searchNav", value: GM_getValue("searchNav", 0), query: "Show the giveaway search bar in the top navigation?", set: { type: "circle", options: ["Yes", "No"] } }, pointInvl: { key: "pointInvl", value: GM_getValue("pointInvl", 0), query: "Regularly update header values (points, messages, etc.)?", set: { type: "number", options: ["Seconds"], about: "Value in seconds, enter 0 to disable. (Minimum 15 seconds)" } } }, //Giveaway lists related lists: { _name: "Giveaway Listings", gridView: { key: "gridView", value: GM_getValue("gridView", 0), query: "Show giveaways in a grid view?", set: { type: "circle", options: ["Yes", "No"] } }, featuredGA: { key: "featuredGA", value: GM_getValue("featuredGA", 2), query: "Show featured giveaways section?", set: { type: "circle", options: ["Yes", "Expanded", "No"] } }, hideEntry: { key: "hideEntry", value: GM_getValue("hideEntry", 1), query: "Hide entered giveaways?", set: { type: "circle", options: ["Yes", "No"] } }, oneHide: { key: "oneHide", value: GM_getValue("oneHide", 0), query: "Skip confirmation when hiding games?", set: { type: "circle", options: ["Yes", "No"] } }, winPercent: { key: "winPercent", value: GM_getValue("winPercent", 1), query: "Show giveaway win percentage?", set: { type: "circle", options: ["Yes", "No"] } }, moreFilters: { key: "moreFilters", value: GM_getValue("moreFilters", 1), query: "Show giveaway filtering?", set: { type: "circle", options: ["Yes", "No"] } }, moreCopies: { key: "moreCopies", value: GM_getValue("moreCopies", 1), query: "Make multiple copy giveaways stand out?", set: { type: "circle", options: ["Yes", "No"] }, sub: { moreCopyBold: { key: "moreCopyBold", value: GM_getValue("moreCopyBold", 1), query: "Bold text:", set: { type: "circle", options: ["Yes", "No"] } }, moreCopyLabel: { key: "moreCopyLabel", value: JSON.parse(GM_getValue("moreCopyLabel", '{"Foreground": "", "Background": ""}')), query: "Text color:", set: { type: "text", options: ["Foreground", "Background"], about: 'Enter value as hexadecimal color, leave blank for defaults.' } } } }, newBadges: { key: "newBadges", value: GM_getValue("newBadges", 1), query: "Show additional giveaway badges?", set: { type: "circle", options: ["Yes", "No"] } }, colorBadge: { key: "colorBadge", value: GM_getValue("colorBadge", 1), query: "Recolor standard giveaway badges?", set: { type: "circle", options: ["Yes", "No"] } }, sideMine: { key: "sideMine", value: GM_getValue("sideMine", 0), query: "Hide 'My Giveaways' in the sidebar? (Still available under nav dropdown)", set: { type: "circle", options: ["Yes", "No"] } }, activeTalk: { key: "activeTalk", value: GM_getValue("activeTalk", 2), query: "Show the 'Active Discussions' section?", set: { type: "circle", options: ["Yes", "Sidebar", "No"] }, sub: { activeTalkSide: { key: "activeTalkSide", value: GM_getValue("activeTalkSide", 2), query: "Sections shown in sidebar:", set: { type: "square", options: ["Discussions", "Deals"], about: "Only applies if 'Sidebar' option is selected" } } } } }, //Giveaway page related detail: { _name: "Giveaway Pages", trainCars: { key: "trainCars", value: GM_getValue("trainCars", 1), query: "Show a train extractor on linked giveaways?", set: { type: "circle", options: ["Yes", "No"] } }, searchSame: { key: "searchSame", value: GM_getValue("searchSame", 1), query: "Show buttons to quickly search for similar giveaways?", set: { type: "circle", options: ["Yes", "No"] } }, realEnd: { key: "realEnd", value: GM_getValue("realEnd", 0), query: "Show actual end time on giveaway page?", set: { type: "circle", options: ["Yes", "No"] } }, allGroup: { key: "allGroup", value: GM_getValue("allGroup", 0), query: "Show all groups on giveaway pages?", set: { type: "circle", options: ["Yes", "No"] } } }, //Comment thread related threads: { _name: "Comment Threads", collapsed: { key: "collapsed", value: GM_getValue("collapsed", 1), query: "After first page, collapse original discussion post?", set: { type: "circle", options: ["Yes", "No"] } }, reversed: { key: "reversed", value: GM_getValue("reversed", 0), query: "Reverse comment threads (newest first)?", set: { type: "circle", options: ["Yes", "No"] } }, commentTop: { key: "commentTop", value: GM_getValue("commentTop", 0), query: "Show comment box at the top of threads?", set: { type: "circle", options: ["Yes", "No"] } }, onDemand: { key: "onDemand", value: GM_getValue("onDemand", 0), query: "Only load attached images on demand?", set: { type: "circle", options: ["Yes", "No"] } }, tracking: { key: "tracking", value: GM_getValue("tracking", 0), query: "Track read comments and topics on discussions?", set: { type: "circle", options: ["Yes", "No"] } }, pinning: { key: "pinning", value: GM_getValue("pinning", 1), query: "Allow discussions to be pinned?", set: { type: "circle", options: ["Yes", "No"] } }, blind: { key: "blind", value: GM_getValue("blind", 1), query: "Allow hiding of discussions?", set: { type: "circle", options: ["Yes", "No"], link: { label: "View Hidden Discussions", location: "/discussioms/hidden" } }, sub: { showBlinds: { key: "blindView", value: null, query: "", set: { type: "action", options: ["View hidden discussions"], actions: [function(){ window.location = "/discussioms/hidden"; }] } } } }, formatting: { key: "formatting", value: GM_getValue("formatting", 1), query: "Show quick format buttons on comment box?", set: { type: "circle", options: ["Yes", "No"] } }, preview: { key: "preview", value: GM_getValue("preview", 1), query: "Allow preview of posts before submitting?", set: { type: "circle", options: ["Yes", "No"] } } }, //User and group related social: { _name: "Users and Groups", hoverInfo: { key: "hoverInfo", value: GM_getValue("hoverInfo", 1), query: "Show profile details on avatar hover?", set: { type: "circle", options: ["Yes", "No"] } }, customTags: { key: "customTags", value: GM_getValue("customTags", 1), query: "Allow tagging of users and groups?", set: { type: "circle", options: ["Yes", "No"] } }, userLists: { key: "userLists", value: GM_getValue("userLists", 1), query: "Label black-/white- listed users?", set: { type: "circle", options: ["Yes", "No"] }, sub: { userColor: { key: "userColor", value: GM_getValue("userColor", 1), query: "Apply colors to usernames?", set: { type: "circle", options: ["Yes", "No"] } }, userWhite: { key: "userWhite", value: JSON.parse(GM_getValue("userWhite", '{"Foreground": "", "Background": ""}')), query: "Whitelisted label colors:", set: { type: "text", options: ["Foreground", "Background"], about: "Enter value as hexadecimal color, leave blank for defaults." } }, userBlack: { key: "userBlack", value: JSON.parse(GM_getValue("userBlack", '{"Foreground": "", "Background": ""}')), query: "Blacklisted label colors:", set: { type: "text", options: ["Foreground", "Background"], about: "Enter value as hexadecimal color, leave blank for defaults." } } } }, userStats: { key: "userStats", value: GM_getValue("userStats", 1), query: "Provide more visibility on user stats?", set: { type: "circle", options: ["Yes", "No"] } }, userTools: { key: "userTools", value: GM_getValue("userTools", 1), query: "Show SGTools links on user and winner pages?", set: { type: "circle", options: ["Yes", "No"] }, sub: { toolsOrdering: { key: "toolsOrdering", value: GM_getValue("toolsOrdering", 1), query: "Result ordering:", set: { type: "circle", options: ["Ascending", "Descending"] } } } } }, //Script related script: { _name: "Script", debugging: { key: "debugging", value: null, query: "Debug options", set: { type: "none", options: [] }, sub: { dbgConsole: { key: "dbgConsole", value: GM_getValue("dbgConsole", 2), query: "Console output level:", set: { type: "circle", options: ["None", "Basic", "Detailed"] } } } }, tagBackup: { key: "tagBackup", value: null, query: "Backup Tags", set: { type: "action", options: ["Import", "Export"], actions: [function(){profiles.tagImport()}, function(){profiles.tagExport()}] } } } }; var frogTags = { users: JSON.parse(GM_getValue("userTags", '{}')), groups: JSON.parse(GM_getValue("groupTags", '{}')) }; var frogTracks = { discuss: JSON.parse(GM_getValue("tracks[discuss]", '{}')), pins: JSON.parse(GM_getValue("tracks[pins]", '{}')), blinds: JSON.parse(GM_getValue("tracks[blinds]", '{}')) }; var frogStatic = { filters: [ [ { name: "Level", type: "number", min: 0, max: 10, inputs: [ { query: "level_min", label: "Min" }, { query: "level_max", label: "Max" } ] }, { name: "Copies", type: "number", min: 1, inputs: [ { query: "copy_min", label: "Min" }, { query: "copy_max", label: "Max" } ] }, { name: "DLC", type: "circle", group: "dlc", inputs: [ { value: "", label: "Included" }, { value: "false", label: "Excluded" }, { value: "true", label: "Only" } ] } ], [ { name: "Entries", type: "number", min: 0, inputs: [ { query: "entry_min", label: "Min" }, { query: "entry_max", label: "Max" } ] }, { name: "Metascore", type: "number", min: 0, max: 100, inputs: [ { query: "metascore_min", label: "Min" }, { query: "metascore_max", label: "Max" } ] }, { name: "Region Restricted", type: "circle", group: "region_restricted", inputs: [ { value: "", label: "Included" }, { value: "false", label: "Excluded" }, { value: "true", label: "Only" } ] } ], [ { name: "Release Date", type: "date", inputs: [ { query: "release_date_min" }, { query: "release_date_max" } ] } ] ] }; // Functions // var dbgLevel = frogVars.script.debugging.sub.dbgConsole.value, logging = { debug: function(message) { if (dbgLevel < 1) { console.debug("[SGT DEBUG] ", message); } }, info: function(message) { if (dbgLevel < 2) { console.log("[SGT INFO] ", message); } }, warn: function(message) { if (dbgLevel < 2) { console.warn("[SGT WARN] ", message); } }, alert: function(message) { console.log("[SGT ALERT] ", message); } }, helpers = { fromQuery: function(name) { var match, urlParams = {}, params = /([^&=]+)=?([^&]*)/g, decode = function(s) { return decodeURIComponent(s.replace(/\+/g, " ")); }; //bit of hackery using js return value on assignment while(match = params.exec(location.search.substring(1))) { urlParams[decode(match[1])] = decode(match[2]); } return urlParams[name]; }, pageSet: { GAList: function() { var path = location.pathname; return (path === "/" || ~path.indexOf("/giveaways/search") || ~path.indexOf("/user/") || (~path.indexOf("/group/") && !~path.indexOf("/users") && !~path.indexOf("/stats") && !~path.indexOf("/wishlist"))); }, CommentList: function() { return (~location.pathname.indexOf("/discussion/") || ~location.pathname.indexOf("/messages")); }, TableList: function() { var path = location.pathname; return (!~path.indexOf("/settings/") && !~path.indexOf("/about/") && !~path.indexOf("/legal/") && !~path.indexOf("/stats/") && !~path.indexOf("/discussioms/") && !~path.indexOf("/happy-holidays/") && !~path.indexOf("/giveaways/new") && !~path.indexOf("/giweaways/train") && !(~path.indexOf("/giveaway/") && !~path.indexOf("/entries")) && !helpers.pageSet.GAList() && !helpers.pageSet.CommentList()); } }, clonePage: function(url, applySkinCall) { var $dark = $("style").detach(); //compatibility with dark theme $("html").empty(); $.ajax({ method: "GET", url: urlBase + url }).done(function(page) { //clear copied page out var head = page.substring(page.indexOf("")+6, page.indexOf("")) .replace(//g, ""); //remove problematic scripts $("").appendTo("html").append(head); $("").appendTo("html").append(page.substring(page.indexOf("")+6, page.indexOf(""))); $dark.appendTo("html"); $(".sidebar__navigation").find("a[href='" + url + "']").parent() .removeClass("is-selected").find("i").remove(); //pull latest site js var jsIndex = page.indexOf("