Last active
March 14, 2023 19:30
-
-
Save twnlink/5db576f3bc13038659294789b689e986 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Force Enable r/place, again | |
// @namespace https://toonl.ink | |
// @description Force enable r/place | |
// @version 1.1.0 | |
// @author toonlink | |
// @license CC0-1.0 | |
// @include https://www.reddit.com/* | |
// @include https://new.reddit.com/* | |
// @include https://reddit.com/* | |
// @run-at document-start | |
// ==/UserScript== | |
const originalDefineProperty = Object.defineProperty; | |
Object.defineProperty = function (...args) { | |
args[2].configurable = true; | |
try { | |
return originalDefineProperty.apply(this, args); | |
} catch {} | |
}; | |
// https://github.com/Cumcord/spitroast | |
const spitroast = (() => { | |
var u=["a","b","i"],l=new Map;function w(c,t,o,r,i){let e=l.get(t)?.[c];if(!e)return i?Reflect.construct(t[c],o,r):t[c].apply(r,o);for(let s of e.b.values()){let h=s.call(r,o);Array.isArray(h)&&(o=h)}let p=(...s)=>i?Reflect.construct(e.o,s,r):e.o.apply(r,s);for(let s of e.i.values()){let h=p;p=(...d)=>s.call(r,d,h)}let a=p(...o);for(let s of e.a.values())a=s.call(r,o,a)??a;return a}function k(c,t,o,r){let i=l.get(c),e=i?.[t];return e?.[r].has(o)?(e[r].delete(o),u.every(p=>e[p].size===0)&&(Reflect.defineProperty(c,t,{value:e.o,writable:!0,configurable:!0})||(c[t]=e.o),delete i[t]),Object.keys(i).length==0&&l.delete(c),!0):!1}function g(){for(let[c,t]of l.entries())for(let o in t)for(let r of u)for(let i of t[o]?.[r].keys()??[])k(c,o,i,r)}var y=c=>(t,o,r,i=!1)=>{if(typeof o[t]!="function")throw new Error(`${t} is not a function in ${o.constructor.name}`);l.has(o)||l.set(o,{});let e=l.get(o);if(!e[t]){let s=o[t];e[t]={o:s,b:new Map,i:new Map,a:new Map};let h=(f,n,b)=>{let j=w(t,o,n,f,b);return i&&a(),j},d=new Proxy(s,{apply:(f,n,b)=>h(n,b,!1),construct:(f,n)=>h(s,n,!0),get:(f,n,b)=>n=="toString"?s.toString.bind(s):Reflect.get(f,n,b)});Reflect.defineProperty(o,t,{value:d,configurable:!0,writable:!0})||(o[t]=d)}let p=Symbol(),a=()=>k(o,t,p,c);return e[t][c].set(p,r),a};var z=y("b"),E=y("i"),H=y("a");return {after: H, before: z, instead: E, unpatchAll: g}; | |
})() | |
// https://github.com/Cumcord/websmack | |
const websmack = (() => { | |
var B="__LOADABLE_LOADED_CHUNKS__",c=t=>{if(t??=Object.keys(window).find(s=>s.includes("Jsonp")),t??=window[B]&&B,!window[t])return;let e=typeof window[t]=="function"?window[t]:(...s)=>window[t].push(s),r;return e([Symbol()],{get:(s,p,o)=>r=o},[["get"]]),delete r.m.get,delete r.c.get,[r.c,r]};var b=t=>{if(t??=Object.keys(window).find(r=>r.startsWith("webpackChunk")),!window[t])return;let e;return window[t].push([[Symbol()],{},r=>{e=r}]),window[t].pop(),[e.c??Object.fromEntries(Object.entries(e.m).map(([r])=>[r,{id:r,loaded:!0,exports:e(r)}])),e]};var w=t=>window[t??Object.keys(window).find(e=>e.startsWith("parcelRequire"))]?.cache;var h=t=>{let e=c(t);if(e?.[0])return["jsonp",...e];let r=b(t);if(r?.[0])return["chunk",...r];let s=w(t);if(s)return["parcel",s];throw new Error("No module fetching methods succeeded.")};var i=t=>e=>t.every(r=>e[r]!==void 0),f=t=>e=>e.prototype&&t.every(r=>e.prototype[r]!==void 0),d=(t,e=!0)=>r=>(e?r.displayName:r.default?.displayName)===t,a=t=>e=>t.every(r=>Object.keys(e).some(s=>s.toLowerCase().includes(r.toLowerCase()))),l=t=>e=>{let r=new RegExp(`(${t}$)|((\\w+\\()+${t}\\))`);if(r.test(e.displayName))return!0;if(typeof e.$$typeof=="symbol"&&e.Consumer===void 0&&(e.type||e.render)){for(;typeof e.type=="object"||typeof e.render=="object";)e=e.type??e.render;if(r.test(e.type?.displayName)||r.test(e.render?.displayName))return!0}},D=t=>typeof t=="object"||typeof t=="function",y=t=>e=>D(e)&&Object.values(e).some(r=>D(r)&&t.some(s=>r?.[s]!==void 0)),x=(t,e)=>r=>Object.entries(e).filter(([,s])=>s.toString().match(r)).map(([s])=>t[s]?.exports).filter(s=>s);var j=(t,e)=>{let r=[],s=p=>e.forEach(([o,n],u)=>{n&&!r[u]&&(r[u]=[]),o(p)&&(n?r[u].push(p):r[u]||(r[u]=p))});for(let p in t){let o=t[p].exports;!o||o===window||(o.default&&o.__esModule&&s(o.default),s(o))}return r},C=t=>({find:e=>t.push([e,!1]),findAll:e=>t.push([e,!0]),findByProps:(...e)=>t.push([i(e),!1]),findByPropsAll:(...e)=>t.push([i(e),!0]),findByPrototypes:(...e)=>t.push([f(e),!1]),findByPrototypesAll:(...e)=>t.push([f(e),!0]),findByNestedProps:(...e)=>t.push([y(e),!1]),findByNestedPropsAll:(...e)=>t.push([y(e),!0]),findByDisplayName:(e,r)=>t.push([d(e,r),!1]),findByDisplayNameAll:(e,r)=>t.push([d(e,r),!0]),findByDispNameDeep:e=>t.push([l(e),!1]),findByDispNameDeepAll:e=>t.push([l(e),!0]),findByKeyword:(...e)=>t.push([a(e),!1]),findByKeywordAll:(...e)=>t.push([a(e),!0])}),m=t=>e=>{let r=[],s=C(r);return e(s),j(t,r)};var A=(t,e=!0)=>r=>{let s=[];for(let p in t){let o=t[p].exports;if(!(!o||o===window)){if(o.default&&o.__esModule&&r(o.default)){if(e)return o.default;s.push(o.default)}if(r(o)){if(e)return o;s.push(o)}}}if(!e)return s},N=([,t,e])=>{let r=A(t),s=A(t,!1),p=e?x(t,e.m):()=>{throw new Error("findByCode does not work with this bundler")};return{batchFind:m(t),find:r,findAll:s,findByProps:(...o)=>r(i(o)),findByPropsAll:(...o)=>s(i(o)),findByPrototypes:(...o)=>r(f(o)),findByPrototypesAll:(...o)=>s(f(o)),findByNestedProps:(...o)=>r(y(o)),findByNestedPropsAll:(...o)=>s(y(o)),findByDisplayName:(o,n)=>r(d(o,n)),findByDisplayNameAll:(o,n)=>s(d(o,n)),findByDispNameDeep:o=>r(l(o)),findByDispNameDeepAll:o=>s(l(o)),findByKeyword:(...o)=>r(a(o)),findByKeywordAll:(...o)=>s(a(o)),findByCodeAll:p,findByCode:o=>p(o)[0]}},_=([,t])=>m(t);var G=()=>N(h());return {autoApi: G,autoraid: h,createApi: N,createBatchFind: _,parcelRequire: w,webpackChunk: b,webpackJsonp:c}; | |
})() | |
function getFindAsync() { | |
let found = false; | |
let patched = false; | |
// rushed garbage, this is just because we load so fucking early | |
return new Promise((resolve) => { | |
let webpackObj; | |
// I think a Proxy would need the parent to actually intercept this, and you can't replace the window with a proxy so... | |
Object.defineProperty(window, "__LOADABLE_LOADED_CHUNKS__", { | |
get() { | |
return webpackObj; | |
}, | |
set(val) { | |
webpackObj = new Proxy(val, { | |
get(obj, prop) { | |
return obj[prop]; | |
}, | |
set(obj, prop, val) { | |
obj[prop] = val; | |
if (prop == "push" && !patched) { | |
patched = true; | |
const modules = websmack.autoraid()[1]; | |
resolve((modName, patchFunc) => { | |
let unpatch = spitroast.after("push", webpackObj, () => { | |
if (modules[modName]) { | |
unpatch(); | |
patchFunc(modules[modName]) | |
} | |
}) | |
}) | |
} | |
return true; | |
}, | |
}); | |
}, | |
}); | |
}); | |
} | |
(async () => { | |
const findAsync = await getFindAsync(); | |
findAsync("./src/reddit/selectors/experiments/garlicBread.ts", (module) => { | |
spitroast.instead("a", module.exports, () => true) | |
spitroast.instead("b", module.exports, () => "place") | |
// dumb way of doing this but it works | |
spitroast.instead("c", module.exports, () => window.location.pathname.startsWith("/r/place")) | |
}) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment