oneko.js icon indicating copy to clipboard operation
oneko.js copied to clipboard

Store neko position across pages

Open st4rburn opened this issue 1 year ago • 12 comments

Basically what it says, it's just a solution for #10 using local storage

st4rburn avatar Sep 26 '24 08:09 st4rburn

I like this! If you'd like some more stuff to do, make the localStorage entry only change on page beforeUnload. If not i'll merge it once I have the time to implement that

I might also wanna see if i can make this configurable with like data-neko-localstorage-pos or something with a better name on the script element

Thank you for your PR c:

adryd325 avatar Sep 27 '24 00:09 adryd325

Thank you! Oh true, I didn't even think of that. I'll try after work if I get a chance

And do you mean like as a bool or the key name or something else? I should be able to do that too c:

st4rburn avatar Sep 27 '24 03:09 st4rburn

i meant like, on the script tag you can have <script data-asdf="true" src="./neko.js"> and access it in js from document.currentScript.dataset["asdf"]

if "asdf" is true then persist data across navigation, else dont save or read localStorage

you could call it "data-persist-position" or something

adryd325 avatar Sep 27 '24 04:09 adryd325

Ohh cool okay Btw working on this I noticed beforeUnload not getting called, and it turns out the event isn't fired when there isn't interaction, or at least I can't get it to fire on Firefox, so I don't think that method will work on a lot of websites/browsers It is kinda cursed just calling it after every frame but I'm not really sure if there's a better way to do it if we need user interaction so :/ Going to work on the data attribute now though

st4rburn avatar Sep 27 '24 12:09 st4rburn

It can be set based on data-persist-position now c: I've set the default to true as well but it's just a bool so easy to change that

st4rburn avatar Sep 27 '24 13:09 st4rburn

What about a dark mode oneko or maybe a gray one? like with a CSS style or something similar.

Mrgaton avatar Sep 28 '24 15:09 Mrgaton

Ohh cool okay Btw working on this I noticed beforeUnload not getting called, and it turns out the event isn't fired when there isn't interaction, or at least I can't get it to fire on Firefox, so I don't think that method will work on a lot of websites/browsers It is kinda cursed just calling it after every frame but I'm not really sure if there's a better way to do it if we need user interaction so :/ Going to work on the data attribute now though

what about

window.navigation.addEventListener("navigate", (event) => {
    console.log('location changed!');
})

Mrgaton avatar Sep 28 '24 15:09 Mrgaton

That specifically didn't work but I just got data to store with both unload and beforeunload even though it was the same as I used before? So going to see if I can make that work again

st4rburn avatar Sep 28 '24 15:09 st4rburn

would be cool too to add an option to set oneko size via style like


		nekoEl.style.transform = 'scale(1.8)';

Mrgaton avatar Sep 28 '24 15:09 Mrgaton

Turns out I did a stupid and tried to add the event to document at first and just never realised, but I think it only works for window So it works now lol

st4rburn avatar Sep 28 '24 15:09 st4rburn

would be cool too to add an option to set oneko size via style like

		nekoEl.style.transform = 'scale(1.8)';

please make issues for feature requests rather than making requests in an unrelated pull request

adryd325 avatar Sep 28 '24 17:09 adryd325

would be cool too to add an option to set oneko size via style like

		nekoEl.style.transform = 'scale(1.8)';

please make issues for feature requests rather than making requests in an unrelated pull request

okay :C

Mrgaton avatar Sep 28 '24 17:09 Mrgaton