Is there a way to force this to return "logged in"? const getLoginState = () => new…
- User
Is there a way to force this to return "logged in"? const getLoginState = () => new Promise((resolve) => { const sessionLoginState = JSON.parse(sessionStorage.getItem('LOGIN_STATE') || null);
if(sessionLoginState) resolve(sessionLoginState); document.addEventListener('LOGIN_FINISHED', (e) => resolve(e?.detail || null), { once: true }); }); async function hasBannerFreeSubscription() { let loginState = await getLoginState(); if(loginState === null || !loginState?.loggedIn) return false; let endpoint = "/api/getUserAdsEnablement"; const url = [endpoint, "?", loginState?.hashedEmail || ''].join(''); return fetch(url) .then(response => response.json()) .then(({ result }) => !result); } async function handleBannerFreeSubscription() { return hasBannerFreeSubscription() .then((result) => { if (result === false) return; window.enable_banner_ads = false; document.querySelectorAll('.adblock,.adform__text,.grid-ad,.adform__topbanner,.finddet-widget,.section-sticky-banners,.adform__sticky').forEach(b => b.remove()); } ); } async function setEnabledAdPositions() { let loginState = await getLoginState(); if(loginState === null || !loginState?.loggedIn) return; if(Array.isArray(undefined)) { // Restrict which ad positions are enabled, when user is logged in window.enabledAdPositions = undefined; } } Tampermonkey or ublock origin? Assistant
To force the
getLoginStatefunction to return"logged in", you can manipulate thesessionStoragedirectly before the script runs. Both Tampermonkey and uBlock Origin can be used to inject scripts into web pages, but Tampermonkey is more suitable for this task because it is designed specifically for running user scripts on web pages.Here's a step-by-step guide on how to achieve this using Tampermonkey:
-
Install Tampermonkey:
- If you haven't already, install the Tampermonkey extension for your browser.
-
Create a New Script:
- Click on the Tampermonkey icon in your browser toolbar.
- Select
Create a new script....
-
Edit the Script: Replace the template with the following script. This script will run before the page fully loads and will set the
LOGIN_STATEinsessionStorageto{"loggedIn": true}.
// ==UserScript== // @name Force Login State // @namespace http://tampermonkey.net/ // @version 1.0 // @description Force the login state to "logged in" // @author You // @match *://*/* // Adjust this to match the specific site(s) you want to target // @grant none // ==/UserScript== (function() { 'use strict'; // Run the script as soon as the document starts loading document.addEventListener('DOMContentLoaded', function() { // Set the LOGIN_STATE in sessionStorage to force "logged in" sessionStorage.setItem('LOGIN_STATE', JSON.stringify({ loggedIn: true, hashedEmail: "example@example.com" })); }, {once: true}); })();Explanation:
-
Metadata Block:
@name: The name of the script.@match: Specifies the pages where the script should run.*://*/*matches all pages, but you should replace this with the specific URL(s) where your target script runs. For example@match https://www.example.com/*- Other metadata like
@namespace,@version,@description,@author, and@grantprovide information about the script.
-
Script Body:
- The script adds an event listener for the
DOMContentLoadedevent, which fires when the initial HTML document has been completely loaded and parsed. - Inside the event listener,
sessionStorage.setItemis used to set theLOGIN_STATEitem to a JSON string representing a logged-in state. You can add additional properties likehashedEmailif needed. - The
{once: true}option ensures the event listener is removed after it has run once, preventing potential issues from multiple executions.
- The script adds an event listener for the
Testing the Script
-
Save the Script:
- After pasting the code, save the script in Tampermonkey.
-
Reload the Target Page:
- Navigate to the page where the original script runs and reload it. The Tampermonkey script will execute before the page fully loads and set the
LOGIN_STATEinsessionStorageto{"loggedIn": true}.
- Navigate to the page where the original script runs and reload it. The Tampermonkey script will execute before the page fully loads and set the
-
Verify the Result:
- Open the browser's developer tools and check the
sessionStorage. You should see theLOGIN_STATEitem with the value{"loggedIn": true}. - The functions
hasBannerFreeSubscriptionandsetEnabledAdPositionsshould now operate under the assumption that the user is logged in.
- Open the browser's developer tools and check the
Using uBlock Origin
While uBlock Origin is primarily an ad blocker, it also has a "Custom filters" feature that can run scripts. However, uBlock Origin's script injection is more limited and less flexible than Tampermonkey. For this reason Tampermonkey is the recommended tool for this task.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.