0

Foreword: I am amateur, just trying to make my own js script to make some task easier on myself.

I'm using and learning JavaScript.

The code(s) I've tried:

window.history.go(-1);

history.back

What I wanted to do: Make a script that goes back a page when it encounters a certain page stated in the @match metadata.

What happened: I tested on Chrome DevTool Console and it worked. The page goes back and all is well. I include it in a Tampermonkey script, and it doesn't seem to work. It's like it's ignored altogether. The metadata seemed to be working fine, since it's the same metadata I used for another script and they work alright.

My question:

How can I make this work?

The whole script:

// @name         MFP reload 1.0
// @namespace    http://tampermonkey.net/
// @version      1
// @description  reload when encountering error
// @author       Miso
// @match        https://www.myfitnesspal.com/exercise/copy_workout?*
// @match        https://www.myfitnesspal.com/exercise/add_favorites
// @grant        none
// ==/UserScript==

window.history.back();
051W
  • 3
  • 3

1 Answers1

0

Try this (I had to change the url because I do not have an account):

// ==UserScript==
// @name         New Userscript
// @namespace    https://www.051W.com
// @version      0.1
// @description  Nonsense
// @author       Nonsense
// @match        https://www.myfitnesspal.com/*
// @grant        none
// ==/UserScript==


(function() {
    'use strict';
    window.history.back();
})();

Remember to enable the script https://i.stack.imgur.com/P7phT.png

Gantendo
  • 4,615
  • 1
  • 18
  • 30
  • 1
    I tried that, and it WORKED!!! Thank you so much! I would not been able to figure that out! It's probably a simple thing, but you have helped me a ton!!! – 051W Jun 20 '22 at 19:33