Prolific Export

Forum export for surveys on Prolific

  1. // ==UserScript==
  2. // @name Prolific Export
  3. // @namespace https://github.com/Kadauchi/
  4. // @version 1.1.0
  5. // @description Forum export for surveys on Prolific
  6. // @author Kadauchi
  7. // @icon http://i.imgur.com/oGRQwPN.png
  8. // @include https://www.prolific.ac/studies*
  9. // @grant GM_setClipboard
  10. // ==/UserScript==
  11.  
  12. function exportStudy (id) {
  13. const study = document.getElementById(id);
  14. const attrs = study.getElementsByTagName(`li`);
  15.  
  16. const link = study.querySelector(`a[href^="/studies/"]`).href;
  17. const title = study.getElementsByTagName(`h3`)[0].textContent;
  18. const researcher = attrs[0].textContent.split(':')[1];
  19. const reward = attrs[1].textContent.split(':')[1].split(`$`)[0];
  20. const perhour = attrs[2].textContent.split(':')[1];
  21. const available = attrs[3].textContent.split(':')[1];
  22. const time = attrs[4].textContent.split(':')[1];
  23. const completion = attrs[5].textContent.split(':')[1];
  24. const exchangeRate = localStorage.getItem(`exchangeRate`);
  25.  
  26. const exportcode =
  27. `[table][tr][td]` +
  28. `[b][size=5][color=red]PROLIFIC STUDY[/color][/size][/b]\n` +
  29. `[b]Title:[/b] [url=${link}]${title}[/url]\n` +
  30. `[b]Hosted by : [/b] ${researcher}\n` +
  31. `[b]Reward : [/b][color=green][b] ${reward}[/color] ${exchangeRate ? `| [color=green]$${(+exchangeRate * +reward.replace(/[^0-9.]/g, ``)).toFixed(2)}[/color]` : ``}[/b]\n` +
  32. `[b]Avg. Reward Per Hour : [/b] ${perhour} ${exchangeRate ? `| $${(+exchangeRate * +perhour.replace(/[^0-9.]/g, ``)).toFixed(2)}/hr` : ``}\n` +
  33. `[b]Available Places : [/b] ${available}\n` +
  34. `[b]Maximum Allowed Time : [/b] ${time}\n` +
  35. `[b]Avg. Completion Time : [/b] ${completion}\n` +
  36. `[/td][/tr][/table]`
  37. ;
  38.  
  39. GM_setClipboard(exportcode);
  40. alert(`Forum export has been copied to your clipboard.`);
  41. }
  42.  
  43. for (let elem of document.getElementsByClassName(`study`)) {
  44. elem.insertAdjacentHTML(
  45. `beforebegin`,
  46. `<button class="exporter" type="button" data-id="${elem.id}">Forum Export</button>`
  47. );
  48. }
  49.  
  50. document.addEventListener(`click`, function (event) {
  51. const elem = event.target;
  52.  
  53. if (elem.matches(`.exporter`)) {
  54. exportStudy(elem.dataset.id);
  55. }
  56. });