// ==UserScript== // @name Steam JS fix // @version 9 // @author Bladru // @description Patches unsupported syntax // @include *://store.steampowered.com/* // @include *://steamcommunity.com/* // ==/UserScript== /* Opera only. Save as "Steam_js_fix.js" (without .user). */ (function(){ window.opera.addEventListener("BeforeScript", patch_scripts); function patch_scripts(UserJSEvent){ var script = UserJSEvent.element; var regex_let = /\blet\b/g; var for_of = "for ( var mutation of mutationsList )"; var for_in = "for ( var mutation in mutationsList )"; var regex_for_of = /for \( item of result\.purchase_receipt_info\.line_items \)\s+{/; var patched_for_of = "for ( i in result.purchase_receipt_info.line_items ) { var item = result.purchase_receipt_info.line_items[i];"; var regex_function_el = /AddSNRDepthParamsToCapsuleList\( \$Capsules \)\s+{/; var patched_function_el = "AddSNRDepthParamsToCapsuleList: function( $Capsules ){"; if ((script.src.indexOf("/gamehighlightplayer.js") != -1 || script.src.indexOf("/main.js") != -1 || script.src.indexOf("/salefunctions.js") != -1 ) && regex_let.test(script.text)){ script.text = script.text.replace(regex_let, "var"); console.log("'let' statement replaced with 'var' in " + script.src); } else if (script.src.indexOf("/shared_global.js") != -1 && script.text.indexOf(for_of) != -1){ /* patched function throws exception either way */ script.text = script.text.replace(for_of, for_in); console.log("'for .. of' statement replaced with 'for .. in' in " + script.src); } else if (script.src.indexOf("/registerkey.js") != -1 && regex_for_of.test(script.text)){ script.text = script.text.replace(regex_for_of, patched_for_of); console.log("'for .. of' statement replaced with 'for .. in' in " + script.src); } else if (script.src.indexOf("/dynamicstore.js") != -1 && regex_function_el.test(script.text)){ script.text = script.text.replace(regex_function_el, patched_function_el); console.log("AddSNRDepthParamsToCapsuleList declaration fixed in " + script.src); } else if (script.src.indexOf("/game.js") != -1){ script.text = script.text.replace("console.log( `#${i}", "//console.log( `#${i}"); } } })();