Greasy Fork is available in English.

Discussions » Development

Can't make script work on this website using Tampermonkey

§
Posted: 2020-03-15

Can't make script work on this website using Tampermonkey

I'm trying to make this script work, so that everytime I search the sorting is automatically set to ascending price.

This is the website: https://www.coopathome.ch/en/search/?text=cheese

The problem is the script doesn't show as being active whe I visit the website, even thought the @match field is set correctly, I think.

Here's the script:

// ==UserScript==
// @name         Coop@home
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        *coopathome.ch/en/search*
// @grant        none
// ==/UserScript==

(function() {

    var url = window.location.href;

if (url.search("coopathome.ch/en/search") >= 0) {
    url = url.replace('/?text','?q');
    /*window.location = url;*/
    history.pushState('data if any', 'Title of the page if any', url);
    history.replaceState('data if any', 'Title of the page if any', url);
}
})();
§
Posted: 2020-03-16
Edited: 2020-03-16

@match is incorrect. Change to:

// @match https://*.coopathome.ch/en/search*

or if you want both http & https

// @match *://*.coopathome.ch/en/search*

You dont need to check the URL since the pattern you are checking is the same as @match

(function() {

    const url = location.href.replace('/?text', '?q');
    // rest of the code
})();

Post reply

Sign in to post a reply.