Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripts Don't Execute Without Devtools Open #2193

Open
limitedAtonement opened this issue Sep 18, 2024 · 0 comments
Open

Scripts Don't Execute Without Devtools Open #2193

limitedAtonement opened this issue Sep 18, 2024 · 0 comments

Comments

@limitedAtonement
Copy link

I'm using Chromium on Arch Linux. I am new to TamperMonkey, so it's likely I'm just doing something wrong. Here is my script:

// ==UserScript==
// @name         Fix Walmart
// @namespace    http://tampermonkey.net/
// @version      2024-09-05
// @description  fix walmart
// @author       You
// @match        https://www.walmart.com/orders*
// @icon         https://i5.walmartimages.com/dfw/63fd9f59-fd82/d9c2b350-71fe-4bc2-be43-23fd97630434/v1/Walmart+_Logo_mweb.svg
// @grant        none
// ==/UserScript==

function hideSidebar() {
    const element = document.querySelector('.flex>.dn.br.b--black-10');
    console.log("tampermonkey; hiding sidebar. got element", element);
    element.style.display = 'none';
}

async function viewDetailsLink() {
    const buttons = document.querySelectorAll('main>section section>div>div>div>div>span>div>button');
    console.log("tampermonkey: view details link, got", buttons.length, "buttons");
    for (let i = 0; i < buttons.length; ++i) {
        // The default listener appears to be mousedown. By overriding mousedown, we eliminate the default
        //action and replace with our own
        const orderNumber =buttons[i].ariaLabel.split(' ').at(-1);
        buttons[i].onmousedown = ()=>window.open('https://walmart.com/orders/' + orderNumber, '_blank').focus();
    }
}

// The site is a SPA, so it changes dynamically without us knowing about it
setInterval(hideSidebar, 1000);
setInterval(viewDetailsLink, 1000);

When I go to walmart.com/orders, the page is not affected (I expect hideSidebar() to hide the sidebar). When I open devtools then reload the page, the sidebar is hidden as expected.

I looked for a discord server or IRC channel to discuss this as it's likely PEBKAC, but didn't find anything.

Can I get the script to run when I visit the site without devtools open?

@derjanb derjanb transferred this issue from Tampermonkey/tampermonkey-i18n Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant