§
Δημοσιεύτηκε: 11/02/2023

i'd like to alert(1) then press enter using userscript, is it possible?

§
Δημοσιεύτηκε: 11/02/2023

yes

NotYouΣυντονιστής
§
Δημοσιεύτηκε: 11/02/2023

There you go:

let node = document.querySelector('YOUR_SELECTOR') || document.documentElement
let config = {
  code: 'Enter',
  key: 'Enter',
  keyCode: 13,
  which: 13,
  target: node,
}

node.dispatchEvent(new KeyboardEvent('keydown', config))

node.dispatchEvent(new KeyboardEvent('keyup', config))
§
Δημοσιεύτηκε: 12/02/2023

There you go:

let node = document.querySelector('YOUR_SELECTOR') || document.documentElement
let config = {
  code: 'Enter',
  key: 'Enter',
  keyCode: 13,
  which: 13,
  target: node,
}

node.dispatchEvent(new KeyboardEvent('keydown', config))

node.dispatchEvent(new KeyboardEvent('keyup', config))

dear i think you misunderstood, alert don't have a selector, it's not a custom alertbox, regular alert(1)

§
Δημοσιεύτηκε: 12/02/2023

yes

how do i do that? the native alert box not custom tho

§
Δημοσιεύτηκε: 12/02/2023

i'd like to alert(1) then press enter using userscript, is it possible?

No, unless you will control the entire browser using node.js like so: https://chercher.tech/puppeteer/alerts-puppeteer

NotYouΣυντονιστής
§
Δημοσιεύτηκε: 13/02/2023

@ANGRY MAN, just created custom alter box :p Is it big problem??

§
Δημοσιεύτηκε: 13/02/2023

@ANGRY MAN, just created custom alter box :p Is it big problem??

no, i wanna hang the process so i can alter a value in the source before it's rendered :D, i used blocking while loop sleep approach, it works..

but the alert one is easier if i could just get it out of their sight programmatically..

NotYouΣυντονιστής
§
Δημοσιεύτηκε: 14/02/2023

Oh, that's why you did it... Can't you just add to script meta values this block?:

// @run-at document-idle

The script will run when the document is fully loaded.

§
Δημοσιεύτηκε: 15/02/2023

Oh, that's why you did it... Can't you just add to script meta values this block?:

// @run-at document-idle

The script will run when the document is fully loaded.

look a value is fetched because userscripts can't intercept http traffic i am trying to alter that value before it's set/assigned and

for that i have to be fast(document-start?) and hang the process(blocking sleep)

the script is 5 line of code, should i send it here?

NotYouΣυντονιστής
§
Δημοσιεύτηκε: 16/02/2023

@ANGRY MAN, yeah I think, if you will send code, then I'd probably be able to help you.

§
Δημοσιεύτηκε: 23/02/2023
Επεξεργάστηκε: 23/02/2023

@ANGRY MAN, yeah I think, if you will send code, then I'd probably be able to help you.

sorry for the late reply, been very busy lately, here is the code

// ==UserScript==
// @name         ChatGPT_Plus
// @version      0.1
// @description  .
// @run-at       document-start
// @match        https://chat.openai.com/*
// @grant        none
// ==/UserScript==
setInterval(() =>{
    window.__NEXT_DATA__.props.pageProps.accountStatusResponse.account_plan.is_paid_subscription_active = true
},0)

reload the website a couple to see the effect,
i'd like to make sure everytime it's set to true and when you go to a conversation and come back to /chat the effect should still be there

can i achieve any of these, thanks a whole lot.

§
Δημοσιεύτηκε: 23/02/2023
Επεξεργάστηκε: 23/02/2023

one more question if it's okay, can i actively check the size/length elements of a div

like first get the total size, if it increased addEventListener to the last added one?
trying to add "double click at chatgpt responses to have it copied to your clipboard"

NotYouΣυντονιστής
§
Δημοσιεύτηκε: 24/02/2023

Actually, there exists much easier solution, this is not good this in actual coding (in company's code, open-source project etc.), but if you want to achieve good performance just with this little user-script, that's what you can do:

Object.defineProperty(Object.prototype, 'is_paid_subscription_active', {
  get() {
    return true
  }
})
NotYouΣυντονιστής
§
Δημοσιεύτηκε: 24/02/2023

To actively check div size, you must use MutationObserver, like this:

let node = document.querySelector('div') // write your selector of div here

let obs = new MutationObserver(() => {
  let width = node.offsetWidth
  let height = node.offsetHeight

  console.log('Width:', width, 'Height:', height) // logs width and height of element
})

obs.observe(node, {
  childTree: true,
  subtree: true,
  attributes: true,
})

If the element does exist all time, then you can do something like this:

let selector = 'div' // write your selector of div here

let obs = new MutationObserver(() => {
  let node = document.querySelector(selector)

  if(node) {
    let width = node.offsetWidth
    let height = node.offsetHeight

    console.log('Width:', width, 'Height:', height) // logs width and height of element
  }
})

obs.observe(document.documentElement, {
  childTree: true,
  subtree: true,
  attributes: true,
})

Δημοσίευση απάντησης

Συνδεθείτε για να δημοσιεύσετε μια απάντηση.