Prolific add "Take part in this study" Button to top of page

Continuously scans for the "Take part in this study" button and clones it to the top-right corner

  1. // ==UserScript==
  2. // @name Prolific add "Take part in this study" Button to top of page
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Continuously scans for the "Take part in this study" button and clones it to the top-right corner
  6. // @author You
  7. // @match https://app.prolific.com/studies*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Function to create and position the cloned button
  15. function addClonedButton(originalButton) {
  16. // If the cloned button already exists, do nothing
  17. if (document.querySelector('#cloned-study-button')) return;
  18.  
  19. // Clone the original button
  20. const clonedButton = originalButton.cloneNode(true);
  21. clonedButton.id = 'cloned-study-button'; // Add an ID to the cloned button to prevent duplicates
  22.  
  23. // Style the cloned button to overlay at the top-right
  24. clonedButton.style.position = 'fixed';
  25. clonedButton.style.top = '70px';
  26. clonedButton.style.right = '10px';
  27. clonedButton.style.zIndex = '1000'; // Ensure it's above other elements
  28. clonedButton.style.backgroundColor = '#007bff'; // Optionally style the button
  29. clonedButton.style.padding = '10px';
  30. clonedButton.style.borderRadius = '5px';
  31. clonedButton.style.cursor = 'pointer';
  32. clonedButton.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)'; // Add a subtle shadow
  33.  
  34. // Append the cloned button to the body
  35. document.body.appendChild(clonedButton);
  36.  
  37. // Ensure clicking the cloned button triggers the original button's click event
  38. clonedButton.addEventListener('click', function() {
  39. originalButton.click(); // Trigger the original button's click
  40. });
  41.  
  42. console.log("Cloned 'Take part in this study' button added.");
  43. }
  44.  
  45. // Function to check for the button and clone it if found
  46. function checkForButton() {
  47. const originalButton = document.querySelector('.reserve-study-button[data-testid="reserve"]');
  48.  
  49. // If the button is found, clone it and add it to the top-right
  50. if (originalButton) {
  51. addClonedButton(originalButton);
  52. }
  53. }
  54.  
  55. // Initial check on page load
  56. checkForButton();
  57.  
  58. // Continuously check for the button at intervals (fallback for observer)
  59. setInterval(checkForButton, 3000); // Check every 3 seconds
  60.  
  61. // MutationObserver to detect changes to the DOM
  62. const observer = new MutationObserver(() => {
  63. checkForButton();
  64. });
  65.  
  66. // Start observing changes to the body
  67. observer.observe(document.body, { childList: true, subtree: true });
  68. })();