I need to write a js userscript to capture some content and perform a click for the specific element. How should I start it
the element I need to find looks like this: “
这道题 flag 是hack[vbzpobcbwyioysfz]
“
The condition to click is that the element contains a substring that starts with “hack”, then a pair of square brackets with some chars in it.
well, the page scrolls very quickly. so I need to quickly find the newly added elements, how to do that?
多次迭代后,最终得到了如下能用的回复:
To quickly find and interact with newly added elements on a page that scrolls quickly, you can use Mutation Observers. A Mutation Observer is a JavaScript API that allows you to watch for changes in the DOM (Document Object Model) and react to those changes in real-time. Here’s how you can use a Mutation Observer to find and interact with newly added elements:
javascript
(function(){// Function to check if a message is a "hack" messagefunctionisHackMessage(messageText){return messageText && messageText.startsWith("这道题 flag 是hack[")&& messageText.endsWith("]");}// Function to process a single messagefunctionprocessMessage(messageBubble){const messageText = messageBubble.querySelector('span');if(isHackMessage(messageText.textContent.trim())){
console.log('Captured content:', messageText.textContent.trim());
messageBubble.click();}}// Callback function for the Mutation ObserverfunctionhandleMutations(mutationsList, observer){for(const mutation of mutationsList){if(mutation.type ==='childList'){// New elements have been addedfor(const node of mutation.addedNodes){if(node.nodeType === Node.ELEMENT_NODE){const messageBubble = node.querySelector('.fakeqq-message__bubble');if(messageBubble){processMessage(messageBubble);}}}}}}// Set up a Mutation Observer to watch for changes in the DOMconst targetNode = document.body;// You can change the target node to be more specificconst config ={childList:true,subtree:true};const observer =newMutationObserver(handleMutations);
observer.observe(targetNode, config);})();
In this code:
The handleMutations function is the callback for the Mutation Observer. It checks for added nodes and, if they are elements, it looks for the message bubble and processes it if it’s a “hack” message.
The Mutation Observer watches for changes in the DOM, specifically child node additions (childList: true) and sub-tree mutations (subtree: true). You can adjust the targetNode to target a more specific part of the DOM if necessary.
This code will monitor the DOM for any newly added elements with the class “fakeqq-message__bubble” and process them as they are added, making it suitable for pages with rapidly scrolling content.
import cv2
import numpy as np
defconvert_binary_to_mp4(input_file, output_file, frame_width, frame_height, frame_count):# Read the binary data from the filebuffer= np.fromfile(input_file, dtype=np.uint8)# Reshape the data to the original shapebuffer=buffer.reshape((frame_count, frame_height, frame_width,3))# Create a VideoWriter object to save the frames as an MP4 video
fourcc = cv2.VideoWriter_fourcc(*'mp4v')# Codec for MP4 format
out = cv2.VideoWriter(output_file, fourcc,30,(frame_width, frame_height))# Write each frame to the video filefor frame inbuffer:
out.write(frame)# Release the VideoWriter
out.release()if __name__ =="__main__":
input_file ="xaa"
output_file ="output_video.mp4"
frame_width =427# Enter the frame width used in your original code
frame_height =759# Enter the frame height used in your original code
frame_count =138# Enter the frame count used in your original code
convert_binary_to_mp4(input_file, output_file, frame_width, frame_height, frame_count)
import cv2
import numpy as np
if __name__ == "__main__":
input_file = "video.bin" # Assuming you have the binary data already loaded
# Load the binary data into the buffer (you should have the buffer already)
buffer = np.fromfile(input_file, dtype=np.uint8)
# Define the range for frame_width and frame_height
- for frame_width in range(100, 640, 1):
+ for frame_width in range(427, 428, 1):
- for frame_height in range(432, 433, 1):
+ for frame_height in range(600, 800, 1):
# Calculate the size of one frame
frame_size = frame_width * frame_height * 3 # 3 color channels (assuming no compression)
# Extract the data of the 1st frame
first_frame_data = buffer[:frame_size].reshape((frame_height, frame_width, 3))
# Save the 1st frame as an image
filename = f"{frame_width}_{frame_height}.png" # Output image file
cv2.imwrite(filename, first_frame_data)
The --to option gives you the maximal offset at which your string can start. The offset is relative to the start of the IP packet. If you add up:
20 bytes for the IP header,
20 bytes for the TCP header,
12 bytes for some TCP options
you’ll end up with 52 bytes. So the start of the TCP payload is at offset 52, anything less than that will match just the TCP/IP headers.
Remark that the TCP options do not have a fixed length. The number 12 was obtained experimentally through tcpdump, but every system can send a different number of options.
iptables 是从 IP 头开始筛,前面已经 20+20=40 byte 了,再带个时间戳就是 52 字节了
II. FORMAT SPECIFICATION
As an IP option, the contents of the first two octets are dictated by the
IP header format to be option type and option length in octets [Postel 80].
The next two octets are used to control this option.
0 7 15 23 31
+---------------+---------------+---------------+---------------+
| type | length | offset |overflw| flags |
+---------------+---------------+---------------+---------------+
| internet ID |
+---------------+---------------+---------------+---------------+
| time stamp |
+---------------+---------------+---------------+---------------+
.
.
.
option type = 68 decimal (i.e., option class = 2 and option number = 4);
option length = the number of octets with a maximum of 40 (limited by
IHL = 15);
offset = the number of octets from the beginning of this option to the
end of timestamps (i.e., the beginning of space for next
timestamp). It is set to one, an odd number, when no more
space remains in the header for timestamps;
overflow = the number of IP modules that cannot register timestamps due
to lack of space;
flag = 0 -- time stamps only
1 -- each timestamp is preceded with internet ID of the
registering entity
3 -- the internet ID fields are prespecified. An IP module only
registers its timestamp if it matches its own ID with the
next specified internet ID;
internet ID = ID for the timestamping device;
timestamp = a right-justified, 32-bit timestamp in milliseconds modulo
24 hours from midnight UT.
The timestamp option is not copied upon fragmentation. It is carried in
the first fragment.
// C program to implement// the above approach#include<stdio.h>#include<stdlib.h>#include<string.h>// Driver codeintmain(){
FILE* ptr;char ch;// Opening file in reading mode
ptr =fopen("/flag1","r");if(NULL== ptr){printf("file can't be opened \n");}printf("content of this file are \n");// Printing what is written in file// character by character using loop.
ch =fgetc(ptr);while(ch !=EOF){printf("%c", ch);
ch =fgetc(ptr);// Checking if character is not EOF.// If it is EOF stop eading.}// Closing the filefclose(ptr);return0;}
sensor sw1 switch1 @enabled
sensor sw2 switch2 @enabled
sensor sw3 switch3 @enabled
sensor sw4 switch4 @enabled
sensor sw5 switch5 @enabled
sensor sw6 switch6 @enabled
sensor sw7 switch7 @enabled
sensor sw8 switch8 @enabled
op shl t sw1 7
set number t
op shl t sw2 6
op add number number t
op shl t sw3 5
op add number number t
op shl t sw4 4
op add number number t
op shl t sw5 3
op add number number t
op shl t sw6 2
op add number number t
op shl t sw7 1
op add number number t
set t sw8
op add number number t
set en 0
set i 0
jump 33 greaterThanEq i 16
op pow fl0 i 2
jump 31 notEqual fl0 number
set en 1
jump 33 always x false
op add i i 1
jump 26 always x false
op equal fl1 0 sw1
op equal fl2 0 sw6
op or fl3 fl1 fl2
jump 38 equal fl3 0
set en 0
control enabled generator1 en
control enabled panel1 en
end
flowchart TD
A(en=0, i=0)--> C{i>=16?}
C -->|Y| D("FL_3=(!SW1)or(!SW6)")
C -->|N| E(FL_0=i^2)
E --> F{FL_0==num?}
F -->|Y|G(en=1)
F -->|N|H(i++)
G --> D
H --> C
D --> I{FL_3==0}
I -->|Y|J[en]
I -->|N|K[0]
sensor t switch1 @enabled
control enabled source1 t
sensor t switch2 @enabled
control enabled source2 t
sensor t switch3 @enabled
control enabled source3 t
sensor t switch4 @enabled
control enabled source4 t
sensor t switch5 @enabled
control enabled source5 t
sensor t switch6 @enabled
control enabled source6 t
sensor t switch7 @enabled
control enabled source7 t
sensor t switch8 @enabled
control enabled source8 t
目前主流的浏览器都不允许随意弹出窗口(popup),但是小 X 是一个很好说话的人,随便找个理由他就会允许你弹窗了;而这里这个 bot 甚至不需要理由,就会来查看你的弹窗(如果有);
搜了 Google 怎么弹窗全是 alert(),那完全没用啊,bot 不吃 alert 啊
那我当然问问 GPT 怎么弹窗对吧(
问 popup 结果丢了个 HTML dialog?
21-4
主流浏览器都会拦截的弹窗,大概是像学校教务系统那种古早的弹出式窗口吧。
再问
I am writing a web app. In some important cases I need to prompt a separate browser window to alert the user for their choice. How can I implement that in JS?
To open a separate browser window or pop-up in JavaScript, you can use the window.open() method. Here’s how you can implement it:
javascript
functionopenPopup(){// Specify the URL of the page you want to open in the popupvar popupURL ="https://example.com/your-popup-page.html";// Define the window's properties (size, position, etc.)var windowFeatures ="width=400,height=400,resizable,scrollbars=yes";// Open the popup windowvar popup = window.open(popupURL,"PopupWindow", windowFeatures);// Check if the browser blocked the popupif(popup ==null||typeof popup ==="undefined"){alert("Popup blocked! Please enable pop-ups for this site.");}else{// Popup opened successfully// You can do further operations with the 'popup' window object// For example, you can write content to it or communicate with it.}}
感觉快了,但是这个 PopupWindow 是啥
what does the PopupWindow mean?
In the code example, “PopupWindow” is a name or identifier for the newly opened popup window. It’s the name that you give to the popup window when you call window.open(). This name is used to refer to the popup window in your JavaScript code if you want to perform further operations on it.
For example, you can use this name to:
Reference the popup window in order to interact with it, such as updating its content or closing it.
Check if a window with the same name is already open. If a window with the same name is open, it will load the new content into the existing window.
Here’s an example of how you might use the name to update the content of the popup window:
javascript
>functionupdatePopupContent(){var popupURL ="https://example.com/updated-popup-content.html";var popupWindow = window.open(popupURL,"PopupWindow","width=400,height=400,resizable,scrollbars=yes");// You can access the popup window by its name and interact with itif(popupWindow){// For example, you can change its location
popupWindow.location = popupURL;}}
So, “PopupWindow” is just a user-defined name that helps you refer to the popup window in your code. You can use any name you like, but it should be unique within your application to avoid conflicts with other window names.
I want to reference js method window.name in my code but my colleague ask me not to use semicolon, dot or round brackets in my code. What can I do?
If you want to reference the window.name property in your code without using semicolons, dots, or round brackets, you can use square brackets and a string literal to access the property. Here’s how you can do it:
javascript
var name = window['name'];
By using square brackets and a string literal, you can access the name property of the window object without using the dot notation. This should meet your colleague’s requirements while allowing you to reference the property.