this post was submitted on 18 Aug 2024
1 points (100.0% liked)

Perchance - Create a Random Text Generator

459 readers
8 users here now

⚄︎ Perchance

This is a Lemmy Community for perchance.org, a platform for sharing and creating random text generators.

Feel free to ask for help, share your generators, and start friendly discussions at your leisure :)

This community is mainly for discussions between those who are building generators. For discussions about using generators, especially the popular AI ones, the community-led Casual Perchance forum is likely a more appropriate venue.

See this post for the Complete Guide to Posting Here on the Community!

Rules

1. Please follow the Lemmy.World instance rules.

2. Be kind and friendly.

  • Please be kind to others on this community (and also in general), and remember that for many people Perchance is their first experience with coding. We have members for whom English is not their first language, so please be take that into account too :)

3. Be thankful to those who try to help you.

  • If you ask a question and someone has made a effort to help you out, please remember to be thankful! Even if they don't manage to help you solve your problem - remember that they're spending time out of their day to try to help a stranger :)

4. Only post about stuff related to perchance.

  • Please only post about perchance related stuff like generators on it, bugs, and the site.

5. Refrain from requesting Prompts for the AI Tools.

  • We would like to ask to refrain from posting here needing help specifically with prompting/achieving certain results with the AI plugins (text-to-image-plugin and ai-text-plugin) e.g. "What is the good prompt for X?", "How to achieve X with Y generator?"
  • See Perchance AI FAQ for FAQ about the AI tools.
  • You can ask for help with prompting at the 'sister' community Casual Perchance, which is for more casual discussions.
  • We will still be helping/answering questions about the plugins as long as it is related to building generators with them.

6. Search through the Community Before Posting.

  • Please Search through the Community Posts here (and on Reddit) before posting to see if what you will post has similar post/already been posted.

founded 1 year ago
MODERATORS
 

I'm not too studied-up on CORS, but I know what it's there for. Currently there's a number of things that are not possible to do because our generator is on a different subdomain than other generators or iframes, etc. etc. and even the top-level page we're actually on.

With that allowed (I think CORS can allow this), there's a lot more customisation we can do of things like t2i image iframes and gallery iframes, reading/changing the top-level url, etc. Maybe that's something you don't want to allow, but I for one have wanted to do these things for completely benign legit reasons multiple times.

you are viewing a single comment's thread
view the rest of the comments
[–] perchance 1 points 3 months ago* (last edited 3 months ago) (15 children)
  • I want to remove the gallery buttons in my plugin pages for example
  • that would reach across into the main perchance.org domain it’s disallowed

Allowing general-purpose cross-domain access like this is not possible, since it would allow very easy login credential stealing, and stuff like that, but these particular things that you've mentioned are good suggestions.

RE gallery button: You're talking about the "send to gallery" and the "open gallery" buttons in the menu after clicking the heart button, right? Would something like this work?

promptData
  prompt = ...
  hideGalleryButtons = true

I have needed history.replaceState before myself, but haven't gotten around to properly thinking about it. I think it should be fine to allow a generator to change the query parameters and hash (i.e. everything other than the pathname - since otherwise could 'spoof' other generators/pages). Can you let me know your specific use case to help me triangulate on a good approach here? Do you specifically need pushState? Or will replaceState do? I'm reluctant to add pushState because it can be used ~maliciously - like the spammy sites that effectively hijack your back button to prevent you from leaving the page (or at least, make it require an extra click or two).

[–] wthit56 1 points 3 months ago (14 children)

Ah yeah, I thought there'd be other repercussions. Maybe just somehow injecting in certain object so they can work? Or something? Yeah, only allow changing hash and params. That should be fine.

Assuming replaceState is just changing the current entry in history, yeah that's totally fine. But as it's going to be different to that in some ways anyway, you could build in your own property with getter/setter perhaps. Like...

get params() { return { param1: value1, ...}; },
set params(value) { history.replaceState() ... },

get hash() { return top.location.hash; }
set hash(value) { top.location.hash = value; }

May require messages or whatever.

We can currently read hash, but set it only on our own iframe. And we can read params, but with potentially other added stuff like for the preview iframe.

What I've done for now is, when the user clicks a button it clicks a hidden link which is then (presumably) caught by perchance, and changes the top-level page.

Speaking of which, by the way... it seems going to perchance.org/generator#anchor works. But if you click a link within the generator going to #anchor it loads up /welcome#anchor instead? At the moment I've got some code that catches and handles clicks on such links so it just scrolls there correctly. But just a heads up, as it seems some of this stuff is implemented and working, but not fully and not all aspects.

[–] perchance 3 points 3 months ago* (last edited 3 months ago) (13 children)

Thanks!

  1. I've hackily fixed <a href="#foo">foo</a> clicks so they work properly now.

  2. I've also added a fix so if you visit perchance.org/whatever#foo it'll correctly try to scroll to the id="foo" element if it exists: https://perchance.org/dkp9npcidc#foo - pinging @[email protected]

  3. You can also type a hash into the address bar of an already loaded page and press enter, and it'll scroll to the element, like a normal top-level page does.

  4. I've also fixed history.replaceState so you can now change the query string of the top-level frame as shown below. It'll throw an error if you try to change the pathname, since that could allow for malicious 'spoofing' of other generators as mentioned above.

history.replaceState({}, "", `/${generatorName}?foo=1`)
  1. You can change the hash with window.location.hash = "#foo" (you can also do this with replaceState IIUC).
  2. You can change page/tab title with document.title = "foo"; and it'll propagate to the top-level frame.
  3. You can change the favicon like you usually would (add a <link rel="icon" href="https://exampe.com/image.png"> to <head>) and it'll propagate to the top-level frame.

Let me know if you find any bugs 👍

And I've added a hideGalleryButtons to the text to image plugin.

load more comments (12 replies)
load more comments (12 replies)
load more comments (12 replies)