add copier
This commit is contained in:
parent
1fc1b4fba1
commit
56153e9bf3
95
copier.js
Normal file
95
copier.js
Normal file
@ -0,0 +1,95 @@
|
||||
// ==UserScript==
|
||||
// @name copier
|
||||
// @namespace none
|
||||
// @version 0.1
|
||||
// @description sussy
|
||||
// @author sussy
|
||||
// @match
|
||||
// @icon none
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
// Create a persistent clipboard notification element
|
||||
const notificationDiv = document.createElement('div');
|
||||
notificationDiv.id = 'tm-clipboard-notification';
|
||||
notificationDiv.style = 'position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); background-color: rgba(0, 0, 0, 0.7); color: white; padding: 5px 10px; border-radius: 5px; z-index: 10000; font-size: 14px; font-family: Arial, sans-serif;';
|
||||
notificationDiv.textContent = 'Clipboard: (click "Check Clipboard" to view contents)';
|
||||
document.body.appendChild(notificationDiv);
|
||||
|
||||
// Button to check clipboard content
|
||||
const checkClipboardBtn = document.createElement('button');
|
||||
checkClipboardBtn.textContent = 'Check Clipboard';
|
||||
checkClipboardBtn.style = 'position: fixed; bottom: 10px; left: 50%; transform: translateX(-60%); margin-left: 1000px; z-index: 10001;';
|
||||
document.body.appendChild(checkClipboardBtn);
|
||||
|
||||
// Function to update the clipboard notification
|
||||
function updateClipboardNotification() {
|
||||
navigator.clipboard.readText().then(text => {
|
||||
notificationDiv.textContent = `Clipboard: ${text}`;
|
||||
}).catch(err => {
|
||||
notificationDiv.textContent = 'Clipboard: (unable to access clipboard)';
|
||||
console.error('Error reading clipboard', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Event listener for the button click
|
||||
checkClipboardBtn.addEventListener('click', updateClipboardNotification);
|
||||
|
||||
const destroyBtn = document.createElement('button');
|
||||
destroyBtn.textContent = 'Destroy';
|
||||
destroyBtn.style = 'margin-left: 10px; background-color: red; color: white; border: none; border-radius: 3px; padding: 3px 6px; cursor: pointer;';
|
||||
notificationDiv.appendChild(destroyBtn);
|
||||
|
||||
// Event listener to remove the notification on click
|
||||
destroyBtn.addEventListener('click', function() {
|
||||
notificationDiv.remove();
|
||||
checkClipboardBtn.remove();
|
||||
});
|
||||
|
||||
// Function to copy text to clipboard using the modern Clipboard API
|
||||
function copyToClipboard(text) {
|
||||
navigator.clipboard.writeText(text).then(function() {
|
||||
console.log('Text copied to clipboard:', text);
|
||||
}, function(err) {
|
||||
console.error('Could not copy text:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// Determine and copy text based on the question content
|
||||
function determineAndCopyText(question) {
|
||||
let textToCopy = "";
|
||||
const questionText = question.textContent.trim();
|
||||
|
||||
// Check the specific conditions for each question text
|
||||
if (questionText.startsWith("Oceń, czy poniższe zdania są prawdziwe.")) {
|
||||
// Copy the answer text for this specific question
|
||||
const answerLabel = question.closest('.question').querySelector('.answer label');
|
||||
if (answerLabel) {
|
||||
textToCopy = answerLabel.textContent.trim();
|
||||
}
|
||||
} else if (questionText.startsWith("Uporządkuj wydarzenia w kolejności chronologicznej")) {
|
||||
// Copy one of the options from the dropdown for this specific question
|
||||
const dropdown = question.closest('.question').querySelector('select.question_input');
|
||||
if (dropdown && dropdown.options.length > 1) {
|
||||
// Assuming you want to copy the first actual option (not the placeholder)
|
||||
textToCopy = dropdown.options[1].text; // Adjust index if needed
|
||||
}
|
||||
} else {
|
||||
// For other questions, copy the first sentence or block of text
|
||||
textToCopy = questionText.split('.')[0] + '.';
|
||||
}
|
||||
|
||||
// Copy the determined text to the clipboard
|
||||
if (textToCopy) {
|
||||
copyToClipboard(textToCopy);
|
||||
}
|
||||
}
|
||||
|
||||
// Observe the document for changes and apply the logic
|
||||
window.addEventListener('load', function() {
|
||||
const questions = document.querySelectorAll('.question_text');
|
||||
questions.forEach(determineAndCopyText);
|
||||
});
|
||||
})();
|
Loading…
x
Reference in New Issue
Block a user