Secret MindTech - Personal Use Plugin

Infinite scroll for job feed. Scroll up and scroll donw buttons. Reveal real number of applicants for a job.

目前为 2024-01-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Secret MindTech - Personal Use Plugin
  3. // @namespace Secret MindTech
  4. // @description Infinite scroll for job feed. Scroll up and scroll donw buttons. Reveal real number of applicants for a job.
  5. // @grant none
  6. // @include /^https?://www\.upwork\.com/.*$/
  7. // @require https://code.jquery.com/jquery-2.2.4.min.js
  8. // @author Preet Patel
  9. // @version 0.0.2.20161026195722
  10. // @downloadURL
  11. // @updateURL
  12. // ==/UserScript==
  13.  
  14. if (window != window.top) {
  15. /* I'm in a frame! */
  16. return;
  17. }
  18.  
  19. // Call the scrollToTop function to scroll to the top
  20. $(document).ready(function () {
  21. const roomBodyElement = document.querySelector(".scroll-wrapper");
  22. const chatData = [];
  23. function hasMoreContent() {
  24. // Implement your logic to check if there is more content to load
  25. // For example, check if there is a "Load more" button or if the element is still scrollable
  26. // Return true if there is more content, otherwise return false
  27. }
  28.  
  29. // Function to scroll the "room-body" element to the top
  30. function scrollToTopWithinRoomBody() {
  31. roomBodyElement.scrollTo({
  32. top: 0,
  33. behavior: "smooth",
  34. });
  35. }
  36.  
  37. // Function to scroll within "room-body" until all content is loaded
  38. function scrollUntilAllContentLoaded() {
  39. // Scroll to the top initially
  40. scrollToTopWithinRoomBody();
  41.  
  42. // Scroll until all content is loaded
  43. function scrollUntilLoaded() {
  44. if (hasMoreContent()) {
  45. roomBodyElement.scrollTop += 100; // Adjust the scrolling amount as needed
  46. setTimeout(scrollUntilLoaded, 500); // Adjust the timeout as needed
  47. } else {
  48. // All content loaded, log the content
  49. chatData.push(roomBodyElement.textContent.trim());
  50. }
  51. }
  52.  
  53. // Start scrolling
  54. scrollUntilLoaded();
  55. }
  56.  
  57. async function callApi(chatData) {
  58. var myHeaders = new Headers();
  59. myHeaders.append("Content-Type", "application/json");
  60. myHeaders.append(
  61. "Authorization",
  62. "Bearer sk-eNmdjIZMJPSNdi0zYSFNT3BlbkFJ6pba0T1Tk1e2P1qq7b3"
  63. );
  64. myHeaders.append(
  65. "Cookie",
  66. "__cf_bm=n5nikmqwZHaJZhPdlpp6YOw_W.MS3j8uBBUew_vyV5A-1704106717-1-ATh3AcH81+LhdJCLgr2gWOHFnvg7crSjg+DpG26lrdiTsCK01t6djWbeqNVQPkR1Px6AsceHCsLCOW9gLK9WIr4=; _cfuvid=xolwxSgSsVPYPlcJlSZOAJR_aDZlcupAEdoLV8s31fs-1704106717014-0-604800000; __cf_bm=jIX7KVQj.dIhTlv8ekk92Zo4XFDxw3TodVopEz6scag-1704109610-1-Ad74Kzer1eduCvZoqJtCApQ2hk12yszHHwQTiwp+zH5JYW5SRAeNGPtgfDXlT8G7MD68vdRCWIn6bqxJFyGDkOM=; _cfuvid=w008BJQ.JEg3GSQRX71znv6qWS.7Ct7r5HVdZIZUxlQ-1704109610345-0-604800000"
  67. );
  68. console.log(123)
  69. var raw = JSON.stringify({
  70. model: "gpt-3.5-turbo",
  71. messages: [
  72. {
  73. role: "system",
  74. content: "You are a helpful assistant.",
  75. },
  76. {
  77. role: "user",
  78. content: JSON.stringify(chatData),
  79. },
  80. ],
  81. });
  82. console.log(456)
  83. var requestOptions = {
  84. method: "POST",
  85. headers: myHeaders,
  86. body: raw,
  87. redirect: "follow",
  88. };
  89. console.log(789)
  90. const response = await fetch(
  91. "https://api.openai.com/v1/chat/completions",
  92. requestOptions
  93. );
  94. // .then(response => response.text())
  95. // .then(result => console.log(result))
  96. // .catch(error => console.log('error', error));
  97. return response.json();
  98. }
  99.  
  100. // Delay the execution of the scraping script for 5 seconds
  101. setTimeout(async () => {
  102. // Call the function to scroll within "room-body" until all content is loaded
  103. scrollUntilAllContentLoaded();
  104. console.log(chatData);
  105. const reply = await callApi(`My name is Preet Patel, what should i reply?. Generate reply or followup message in max 50 words and without subject and any footer messages. "${chatData}"`)
  106. console.log(reply)
  107.  
  108. // reply = "Hello, Thanks for your message.";
  109. const proseMirrorElement = document.querySelector(".ProseMirror");
  110.  
  111. // Create a new paragraph element
  112. const paragraphElement = document.createElement("p");
  113.  
  114. console.log(reply.choices)
  115. // Set the content of the paragraph element
  116. paragraphElement.innerHTML = reply.choices[0].message.content;
  117.  
  118. // Append the paragraph element to the "ProseMirror" element
  119. proseMirrorElement.appendChild(paragraphElement);
  120. }, 2000); // 5000 milliseconds (5 seconds)
  121. });