There is a website that has a certain button, the href
of which changes every week. I need a bookmark that will redirect me to the URL in this href
.
I tried to use a Bookmarklet, but it doesn't seem to work, as I need the page to load completely at the time the JavaScript code is executed.
Here's what i have:
javascript:(function(){
window.location.href = "https://rasp.tpu.ru/site/department.html?id=7950&cource=1";
window.location.href = Array.from(document.querySelectorAll('a')).find(element => element.href.includes('gruppa_42148')).href
})();
I tried to wait for the website to load:
javascript:(function(){
window.location.href = "https://rasp.tpu.ru/site/department.html?id=7950&cource=1";
window.addEventListener('load', function () { window.location.href = Array.from(document.querySelectorAll('a')).find(element => element.href.includes('gruppa_42148')).href })
})();
But it's not working. As i understand, this is simply not possible with a bookmarklet, you can not run a script in one page, then go to another and try to get the content of this page in order to continue executing something in the script.
I was also thinking about writing a script in Tampermonkey that will run only when I go to this site from a certain bookmark, but again I have no idea how to do this.
There is actually a link on this page that seems to be a server redirect link to the calendar page:
https://go.tpu.ru/VJSufWbM > https://rasp.tpu.ru/redirect/kalendar.html?hash=1Xyu9g > https://rasp.tpu.ru/gruppa_42148/2024/1/view.html
You can also do what you want with tampermonkey:
// ==UserScript==
// @name bookmark
// @namespace http://tampermonkey.net/
// @version 2024-09-04
// @description .
// @author You
// @match https://rasp.tpu.ru/site/department.html?id=7950&cource=1
// @icon https://www.google.com/s2/favicons?sz=64&domain=tpu.ru
// @grant none
// ==/UserScript==
if (location.hash === '#bookmark'){
const a = document.querySelector('a[href*=gruppa_42148]');
a && location.replace(a.href);
}
this will only redirect if the url includes the hash #bookmark
.
and use this as the bookmark url:
https://rasp.tpu.ru/site/department.html?id=7950&cource=1#bookmark