diff --git a/2ndscript.js b/2ndscript.js new file mode 100644 index 0000000..307b3c1 --- /dev/null +++ b/2ndscript.js @@ -0,0 +1,82 @@ +// ==UserScript== +// @name New Userscript +// @namespace http://tampermonkey.net/ +// @version 2023-12-15 +// @description try to take over the world! +// @author You +// @grant none +// ==/UserScript== +(function() { + 'use strict'; + + // Add a fixed-position toolbar with an input box and two buttons + const toolbarHTML = ` +
+ + + + +
+ `; + document.body.insertAdjacentHTML('beforeend', toolbarHTML); + + // Function to copy text to clipboard using the modern Clipboard API + function copyToClipboard(text) { + navigator.clipboard.writeText(text).then(function() { + console.log('Correct answers copied to clipboard:', text); + }, function(err) { + console.error('Could not copy text:', err); + }); + } + + // Refactored function to search for the question and copy correct answers + function performSearchAndCopy(questionName) { + const button = document.getElementById('tm-search-btn'); + const allQuestions = document.querySelectorAll('.display_question'); + + // Reset the button color + button.style.backgroundColor = ''; + + let found = false; + let correctAnswersToCopy = ''; + + // Search for the question + allQuestions.forEach((questionDiv) => { + if (questionDiv.innerText.includes(questionName)) { + found = true; + // Find the correct answers within the same question container + const correctAnswers = questionDiv.parentElement.querySelectorAll('.correct_answer, .answer_text.correct'); + correctAnswers.forEach((answer) => { + correctAnswersToCopy += answer.innerText + '\n'; // Collect all correct answers text + }); + } + }); + + // Copy correct answers to clipboard if found + if (found && correctAnswersToCopy) { + copyToClipboard(correctAnswersToCopy.trim()); + } else { + // Change button color to red if question is not found or no correct answers + button.style.backgroundColor = 'red'; + } + } + + // Event listener for the input-based search button + document.getElementById('tm-search-btn').addEventListener('click', () => { + const questionName = document.getElementById('tm-question-input').value; + performSearchAndCopy(questionName); + }); + + // Function to fetch text from clipboard and search for answers + function clipboardSearchAndCopyAnswers() { + navigator.clipboard.readText().then((clipboardText) => { + // Use the clipboard text as the question name + performSearchAndCopy(clipboardText); + }).catch((err) => { + console.error('Failed to read clipboard contents:', err); + }); + } + + // Event listener for the clipboard search button + document.getElementById('tm-clipboard-btn').addEventListener('click', clipboardSearchAndCopyAnswers); +})(); \ No newline at end of file