Handshake Hide Jobs

Add a button to hide jobs on Handshake

  1. // ==UserScript==
  2. // @name Handshake Hide Jobs
  3. // @namespace https://github.com/bhackel
  4. // @version 1.3
  5. // @description Add a button to hide jobs on Handshake
  6. // @author bhackel
  7. // @match https://*.joinhandshake.com/stu/postings*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=joinhandshake.com
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const savedHiddenJobIds = GM_getValue('hiddenJobIds', '[]');
  18. // Convert the retrieved string back to an array
  19. let hiddenJobIds = JSON.parse(savedHiddenJobIds);
  20.  
  21. function addButtonToDivs() {
  22. let targetDiv = document.querySelector("#skip-to-content > div:nth-child(4) > div > div:nth-child(1) > div > div > form > div:nth-child(2) > div > div > div > div:nth-child(3) > div > div");
  23.  
  24. // 1st Page is different than others
  25. if (targetDiv === null) {
  26. targetDiv = document.querySelector("#skip-to-content > div:nth-child(4) > div > div:nth-child(1) > div > div > form > div:nth-child(2) > div > div > div > div:nth-child(2) > div > div");
  27. }
  28.  
  29. const childrenArray = [...targetDiv.children]; // convert from nodelist to array
  30.  
  31. childrenArray.forEach(div => {
  32. // Ignore spacing divs
  33. if (div.querySelectorAll('div').length <= 1) {
  34. return;
  35. }
  36. // Unique identifier for each job
  37. let jobId = div.children[0].id;
  38. if (div.style.display !== 'none' && hiddenJobIds.includes(jobId)) {
  39. console.log("Hiding previously hidden job " + jobId);
  40. div.style.display = 'none';
  41. }
  42.  
  43. // Check if div already contains a button
  44. const existingButton = div.querySelector('.bhackel-button');
  45.  
  46. if (!existingButton) {
  47. const newButton = document.createElement('button');
  48. newButton.textContent = 'Hide';
  49. newButton.classList.add('bhackel-button'); // Add the class 'bhackel-button'
  50. newButton.addEventListener('click', () => {
  51. console.log("Hiding job " + jobId);
  52. div.style.display = 'none';
  53. hiddenJobIds.push(jobId);
  54. // Attempt to click the job below this one
  55. let nextJobDiv = div.nextElementSibling.nextElementSibling;
  56. setTimeout(function() {
  57. nextJobDiv?.children[0]?.click();
  58. }, 500);
  59. });
  60. div?.children[0]?.appendChild(newButton);
  61. }
  62. });
  63.  
  64. GM_setValue('hiddenJobIds', JSON.stringify(hiddenJobIds));
  65.  
  66. }
  67.  
  68. // Check for new divs and add buttons every 5 seconds (you can adjust the interval)
  69. setInterval(addButtonToDivs, 5000);
  70.  
  71. })();