Greasy Fork is available in English.

Discussions » تطوير

Replacing JS files on page. Load the page ignoring the hash

§
Posted: 23-12-2021
Edited: 23-12-2021

I recently created a script that replaces any JS file on the site (https://greasyfork.org/ru/scripts/437488-easy-script-replacement-example). But sometimes it may not work if the document is loaded from the hash. I solve this problem this way, but I'm not sure about this solution and it doesn't seem stable to me.

// if document was loaded from hash HTML may not be replaced
var firstLoad = localStorage.getItem('firstLoad');
if (!firstLoad === '1') {
....localStorage.setItem('firstLoad', '1');
....// reloading with hash ignoring
....return window.location.reload(true)
} else {
....localStorage.removeItem(firstLoad);
}

§
Posted: 23-12-2021

!firstLoad === '1' is always false

§
Posted: 23-12-2021

if document was loaded from hash

And what does that mean? You mean cache maybe?

§
Posted: 23-12-2021

You mean cache maybe?

Maybe.

§
Posted: 23-12-2021
!firstLoad === '1' is always false

indeed

Post reply

تسجيل الدخول إلى مرحلة ما بعد الرد.