Automatic brush station B Barrage

Automatic filling station B barrage (createEvent message mechanism included)

To look at last night's game really mad at me. RNG actually has lost. . .
To LPL. . . I wrote a script for the refueling of LPL. I hope you can join me for the LPL Come on!
Script code is as follows:

var event = document.createEvent('Event');
event.initEvent('input', true, true);
function fun123(){
    $('.chat-input.border-box').val("前方高能!!");
    $('.chat-input.border-box')[0].dispatchEvent(event);
    $('.bl-button.live-skin-highlight-button-bg.bl-button--primary.bl-button--small').click();
}
setInterval("fun123()","100");

The first step to open the browser and log B station

Press F12 to open the console

Paste the code and press ENTER

Please viewing


Down is the other principle of non-technical people please leave
***

After several debugging I found B station textareacan send after the need to trigger a keydown event.
So I looked up w3c documents, summarized as follows:


Many methods createEvent used, such as initCustomEvent, have been abandoned. Use event constructors instead.

Creating a specified type of event. Return of the object must be initialized and can be passed to element.dispatchEvent.


grammar

var event = document.createEvent(type);

event is the Event object is created.
of the type is a string representing the type of event to create. Event type may include "UIEvents", "MouseEvents", "MutationEvents", or "HTMLEvents". See the Notes section for details.

Examples

// 创建事件
var event = document.createEvent('Event');

// 定义事件名为'build'.
event.initEvent('build', true, true);

// 监听事件
elem.addEventListener('build', function (e) {
  // e.target matches elem
}, false);

// 触发对象可以是任何元素或其他事件目标
elem.dispatchEvent(event);

Create a custom event

Events can use the Eventconstructor to create the following:

var event = new Event('build');

// Listen for the event.
elem.addEventListener('build', function (e) { ... }, false);

// Dispatch the event.
elem.dispatchEvent(event);

Most modern browsers will support this constructor (Internet Explorer exceptions).

Add custom data - CustomEvent ()

To add more data event object, you can use CustomEvent, detail attribute can be used to pass custom data
CustomEvent interfaces can add more data event object. For example, event can be created as follows:

var event = new CustomEvent('build', { 'detail': elem.dataset.time });

The following code allows you to access more data in event listener:

function eventHandler(e) {
  log('The time is: ' + e.detail);
}

Outdated way
early events created by the Java API uses the method inspired. An example is shown below:

// Create the event.
var event = document.createEvent('Event');

// Define that the event name is 'build'.
event.initEvent('build', true, true);

// Listen for the event.
document.addEventListener('build', function (e) {
  // e.target matches document from above
}, false);

// target can be any Element or other EventTarget.
document.dispatchEvent(event);

Event bubbling

Usually you need to trigger events from child elements, and let it capture ancestors:

<form>
  <textarea></textarea>
</form>
const form = document.querySelector('form');
const textarea = document.querySelector('textarea');

// Create a new event, allow bubbling, and provide any data you want to pass to the "details" property
const eventAwesome = new CustomEvent('awesome', {
  bubbles: true,
  detail: { text: () => textarea.value }
});

// The form element listens for the custom "awesome" event and then consoles the output of the passed text() method
form.addEventListener('awesome', e => console.log(e.detail.text()));

// As the user types, the textarea inside the form dispatches/triggers the event to fire, and uses itself as the starting point
textarea.addEventListener('input', e => e.target.dispatchEvent(eventAwesome));

Dynamically create and distribute event

Elements can listen for the event has not been created:

<form>
  <textarea></textarea>
</form>
const form = document.querySelector('form');
const textarea = document.querySelector('textarea');

form.addEventListener('awesome', e => console.log(e.detail.text()));

textarea.addEventListener('input', function() {
  // Create and dispatch/trigger an event on the fly
  // Note: Optionally, we've also leveraged the "function expression" (instead of the "arrow function expression") so "this" will represent the element
  this.dispatchEvent(new CustomEvent('awesome', { bubbles: true, detail: { text: () => textarea.value } }))
});

Built-in trigger event

The following example demonstrates a click on the check box (click) analog (that is generating a click event in the program), click on the simulation using the DOM method. See this dynamic example

`function simulateClick() { var event = new MouseEvent('click', { 'view': window, 'bubbles': true, 'cancelable': true }); var cb = document.getElementById('checkbox'); var cancelled = !cb.dispatchEvent(event); if (cancelled) { // A handler called preventDefault. alert("cancelled"); } else { // None of the handlers called preventDefault. alert("not cancelled"); } }

Guess you like

Origin www.cnblogs.com/godoforange/p/11707213.html