Certainly! Below is a prompt for an AI designed to write TamperMonkey scripts.
Prompt for TamperMonkey Script Writing AI
Objective:
Create a TamperMonkey script that enhances the functionality of a specified website by automating tasks, modifying content, or improving user experience. The script should be well-commented, efficient, and adhere to best practices for user script development.
Instructions:
Identify the Target Website:
Specify the website the script will be applied to. For this example, let's use "ExampleSocialMedia.com".
Define the Script's Purpose:
Clearly state what the script is intended to do. For this example the script will “Automatically like and comment on posts containing specific keywords”.
Script Metadata:
Include the necessary metadata at the top of the script.
// ==UserScript==
// @name Auto Like and Comment on ExampleSocialMedia
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Automatically like and comment on posts containing specific keywords on ExampleSocialMedia.com
// @author YourName
// @match https://www.examplesocialmedia.com/*
// @grant none
// ==/UserScript==
Keywords and Comments:
Define the keywords that will trigger the like and comment actions.
Provide a list of comments that the script can randomly choose from when commenting.
Write the main function that will be executed when the script runs.
Use MutationObserver to monitor changes in the DOM and identify new posts.
Check if the post content contains any of the specified keywords.
If a keyword is found, automatically like the post and add a comment.
(function() {
'use strict';
// Function to like a post
function likePost(postElement) {
const likeButton = postElement.querySelector('.like-button');
if (likeButton) {
likeButton.click();
}
}
// Function to comment on a post
function commentOnPost(postElement) {
const commentInput = postElement.querySelector('.comment-input');
const commentButton = postElement.querySelector('.comment-button');
if (commentInput && commentButton) {
const randomComment = comments[Math.floor(Math.random() * comments.length)];
commentInput.value = randomComment;
commentButton.click();
}
}
// Function to check if post contains any keywords
function containsKeyword(postContent) {
return keywords.some(keyword => postContent.includes(keyword));
}
// MutationObserver to monitor new posts
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.type === 'childList') {
mutation.addedNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE) {
const postContent = node.querySelector('.post-content')?.textContent || "";
if (containsKeyword(postContent)) {
likePost(node);
commentOnPost(node);
}
}
});
}
});
});
// Start observing the target node for configured mutations
observer.observe(document.body, { childList: true, subtree: true });
})();
Testing and Debugging:
Include instructions for testing the script.
Provide guidance on how to debug common issues, such as elements not being found or actions not being performed.
Testing Instructions:
1. Install the TamperMonkey extension in your browser.
2. Create a new script and copy the above code into the editor.
3. Navigate to ExampleSocialMedia.com and ensure you are logged in.
4. Manually trigger new posts to appear and observe if the script likes and comments on posts containing the specified keywords.
Debugging Tips:
- Use the browser's developer tools to inspect elements and ensure the correct selectors are being used.
- Add console.log statements to debug and verify that functions are being called as expected
- Ensure that the @match URL correctly matches the pages where the script should run
Output:
The AI should generate a complete, functional TamperMonkey script based on the above instructions, ready to be copied into the TamperMonkey editor and used on ExampleSocialMedia.com.
User
A system Instructions, Like the LLM personality
Assistant
Certainly! Below is a system of instructions to guide an LLM (Large Language Model) in generating a TamperMonkey script. This system of instructions acts like a "personality" for the LLM, ensuring it produces a coherent, well-structured, and functional script.
System Instructions for LLM: TamperMonkey Script Generation
1. Understand the Objective
Instruction: Clearly define the objective of the script. This includes identifying the target website and specifying the script’s purpose.
Example: "The script will automatically like and comment on posts containing specific keywords on ExampleSocialMedia.com."
2. Script Metadata
Instruction: Include the necessary TamperMonkey metadata at the top of the script. This metadata provides essential information about the script, such as its name, version, description, author, and the websites it should run on.
// ==UserScript==
// @name Auto Like and Comment on ExampleSocialMedia
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Automatically like and comment on posts containing specific keywords on ExampleSocialMedia.com
// @author YourName
// @match https://www.examplesocialmedia.com/*
// @grant none
// ==/UserScript==
3. Define Keywords and Comments
Instruction: Specify the keywords that will trigger the script’s actions and provide a list of comments that the script can use.
Template:
const keywords = ["{keyword1}", "{keyword2}", "{keyword3}"];
const comments = [
"{comment1}",
"{comment2}",
"{comment3}",
// Add more comments as needed
];
Instruction: Write the main function that will be executed when the script runs. This should include:
A function to like a post.
A function to comment on a post.
A function to check if a post contains any of the specified keywords.
A MutationObserver to monitor changes in the DOM and identify new posts.
Template:
(function() {
'use strict';
// Function to like a post
function likePost(postElement) {
const likeButton = postElement.querySelector('{likeButtonSelector}');
if (likeButton) {
likeButton.click();
}
}
// Function to comment on a post
function commentOnPost(postElement) {
const commentInput = postElement.querySelector('{commentInputSelector}');
const commentButton = postElement.querySelector('{commentButtonSelector}');
if (commentInput && commentButton) {
const randomComment = comments[Math.floor(Math.random() * comments.length)];
commentInput.value = randomComment;
commentButton.click();
}
}
// Function to check if post contains any keywords
function containsKeyword(postContent) {
return keywords.some(keyword => postContent.includes(keyword));
}
// MutationObserver to monitor new posts
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.type === 'childList') {
mutation.addedNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE) {
const postContent = node.querySelector('{postContentSelector}')?.textContent || "";
if (containsKeyword(postContent)) {
likePost(node);
commentOnPost(node);
}
}
});
}
});
});
// Start observing the target node for configured mutations
observer.observe(document.body, { childList: true, subtree: true });
})();
Example:
(function() {
'use strict';
// Function to like a post
function likePost(postElement) {
const likeButton = postElement.querySelector('.like-button');
if (likeButton) {
likeButton.click();
}
}
// Function to comment on a post
function commentOnPost(postElement) {
const commentInput = postElement.querySelector('.comment-input');
const commentButton = postElement.querySelector('.comment-button');
if (commentInput && commentButton) {
const randomComment = comments[Math.floor(Math.random() * comments.length)];
commentInput.value = randomComment;
commentButton.click();
}
}
// Function to check if post contains any keywords
function containsKeyword(postContent) {
return keywords.some(keyword => postContent.includes(keyword));
}
// MutationObserver to monitor new posts
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.type === 'childList') {
mutation.addedNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE) {
const postContent = node.querySelector('.post-content')?.textContent || "";
if (containsKeyword(postContent)) {
likePost(node);
commentOnPost(node);
}
}
});
}
});
});
// Start observing the target node for configured mutations
observer.observe(document.body, { childList: true, subtree: true });
})();
5. Testing and Debugging Instructions
Instruction: Provide clear instructions for testing the script and guidance on how to debug common issues.
Template:
Testing Instructions:
1. Install the TamperMonkey extension in your browser.
2. Create a new script and copy the above code into the editor.
3. Navigate to {WebsiteURL} and ensure you are logged in.
4. Manually trigger new posts to appear and observe if the script performs the intended actions.
Debugging Tips:
- Use the browser's developer tools to inspect elements and ensure the correct selectors are being used.
- Add console.log statements to debug and verify that functions are being called as expected
- Ensure that the @match URL correctly matches the pages where the script should run
Example:
Testing Instructions:
1. Install the TamperMonkey extension in your browser.
2. Create a new script and copy the above code into the editor.
3. Navigate to ExampleSocialMedia.com and ensure you are logged in.
4. Manually trigger new posts to appear and observe if the script likes and comments on posts containing the specified keywords.
Debugging Tips:
- Use the browser's developer tools to inspect elements and ensure the correct selectors are being used.
- Add console.log statements to debug and verify that functions are being called as expected
- Ensure that the @match URL correctly matches the pages where the script should run
Final Output
The LLM should generate a complete, functional TamperMonkey script based on these system instructions, ready to be copied into the TamperMonkey editor and used on the specified website.
Example Final Script
// ==UserScript==
// @name Auto Like and Comment on ExampleSocialMedia
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Automatically like and comment on posts containing specific keywords on ExampleSocialMedia.com
// @author YourName
// @match https://www.examplesocialmedia.com/*
// @grant none
// ==/UserScript==
const keywords = ["keyword1", "keyword2", "keyword3"];
const comments = [
"Great post!",
"I really enjoyed this!",
"Fantastic content!",
"Well said!",
"Keep it up!"
];
(function() {
'use strict';
// Function to like a post
function likePost(postElement) {
const likeButton = postElement.querySelector('.like-button');
if (likeButton) {
likeButton.click();
}
}
// Function to comment on a post
function commentOnPost(postElement) {
const commentInput = postElement.querySelector('.comment-input');
const commentButton = postElement.querySelector('.comment-button');
if (commentInput && commentButton) {
const randomComment = comments[Math.floor(Math.random() * comments.length)];
commentInput.value = randomComment;
commentButton.click();
}
}
// Function to check if post contains any keywords
function containsKeyword(postContent) {
return keywords.some(keyword => postContent.includes(keyword));
}
// MutationObserver to monitor new posts
const observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
if (mutation.type === 'childList') {
mutation.addedNodes.forEach(node => {
if (node.nodeType === Node.ELEMENT_NODE) {
const postContent = node.querySelector('.post-content')?.textContent || "";
if (containsKeyword(postContent)) {
likePost(node);
commentOnPost(node);
}
}
});
}
});
});
// Start observing the target node for configured mutations
observer.observe(document.body, { childList: true, subtree: true });
})();