討論 » 建立請求

is it possible to press enter

§
發表於:2023-02-11

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

§
發表於:2023-02-11

yes

NotYou管理員
§
發表於:2023-02-11

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))
§
發表於:2023-02-12

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)

§
發表於:2023-02-12

yes

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

§
發表於:2023-02-12

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管理員
§
發表於:2023-02-13

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

§
發表於:2023-02-13

@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管理員
§
發表於:2023-02-14

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.

§
發表於:2023-02-15

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管理員
§
發表於:2023-02-16

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

§
發表於:2023-02-23
編輯:2023-02-23

@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.

§
發表於:2023-02-23
編輯:2023-02-23

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管理員
§
發表於:2023-02-24

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管理員
§
發表於:2023-02-24

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,
})

發表回覆

登入以回復