Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SteamSearchPlusOneFilter.user.js
// ==UserScript==
// @name Steam Search +1 Filter
// @namespace luckz
// @author luckz
// @version 0.1.0
// @description hide Profile Features Limited / Steam is Learning / Low Confidence Metric / PlusZero from the current search results
// @match https://store.steampowered.com/search/*
// @connect bartervg.com
// @grant GM_xmlhttpRequest
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @grant GM_registerMenuCommand
// @downloadURL https://gist.github.com/Luckz/8b13814ac60105ee2249cf16dd4eb126/raw/SteamSearchPlusOneFilter.user.js
// @updateURL https://gist.github.com/Luckz/8b13814ac60105ee2249cf16dd4eb126/raw/SteamSearchPlusOneFilter.user.js
// ==/UserScript==
/* eslint-disable-next-line no-redeclare */
/* global jQuery */
// ==Configuration==
//Set your +0 sync interval in hours. (Set to 0 if you want to force a sync)
const syncIntervalPFL = 3 * 24;
const syncIntervalACH = 7 * 24;
// ==/Configuration==
// ==Globals==
const PFL = {
sourceURL: 'https://bartervg.com/browse/tag/481/json/',
syncInterval: syncIntervalPFL,
storeTimestamp: 'ssf_pfl_last',
storeJSON: 'ssf_pfl',
storage: {},
};
const ACH = {
sourceURL: 'https://bartervg.com/browse/tag/473/json/',
syncInterval: syncIntervalACH,
storeTimestamp: 'ssf_ach_last',
storeJSON: 'ssf_ach',
storage: {},
};
// ==/Globals==
GM_deleteValue('ssf_last'); // TODO : remove mid/late 2021
GM_registerMenuCommand('⭕️ Remove +0 (PFL)', removePlusZero);
GM_registerMenuCommand('🏆 Remove No Cheevos', removeNoCheev);
async function removePlusZero() {
await ensureDataLoaded(PFL);
filterForStorage(PFL.storage, true);
}
async function removeNoCheev() {
await ensureDataLoaded(ACH);
filterForStorage(ACH.storage, false);
}
async function ensureDataLoaded(obj) {
const {sourceURL, syncInterval, storeTimestamp, storeJSON} = obj; // storage can't have a new variable since it's to be replaced
const timestamp = GM_getValue(storeTimestamp, 0);
// check if data already set or in storage
if ((Date.now() - timestamp) < (syncInterval * 60000)) {
if (Object.keys(obj.storage).length > 1000)
return;
else {
obj.storage = JSON.parse(GM_getValue(storeJSON, '{}'));
if (Object.keys(obj.storage).length > 1000)
return;
}
}
// update data
try {
obj.storage = await makeGetRequestMinLengthJson(sourceURL);
GM_setValue(storeJSON, JSON.stringify(obj.storage));
GM_setValue(storeTimestamp, Date.now());
} catch (error) {
console.log('SSF: disappointing try/catch failure');
console.log(error);
}
}
function makeGetRequestMinLengthJson(url) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'GET',
url: url,
onload: function(response) {
if (response.responseText.length > 5000)
resolve(JSON.parse(response.responseText));
else
reject(new Error(`response too short getting ${url}`));
},
onerror: function(error) {
reject(error);
},
});
});
}
function filterForStorage(storage, removeMatching = true) {
const productLinks = jQuery('#search_resultsRows > a');
productLinks.each(function() {
const currentItem = jQuery(this);
if (removeMatching && storage[currentItem.attr('data-ds-appid')] !== undefined)
currentItem.remove();
else if (!removeMatching && storage[currentItem.attr('data-ds-appid')] === undefined)
currentItem.remove();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment