Kinobot Hide Used Requests

Adds a toggle in user page to hide used/rejected requests.

  1. // ==UserScript==
  2. // @name Kinobot Hide Used Requests
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.2
  5. // @description Adds a toggle in user page to hide used/rejected requests.
  6. // @author seaque
  7. // @license MIT
  8. // @match *://*.kino.caretas.club/user*
  9. // @require https://code.jquery.com/jquery-1.12.4.min.js
  10. // @icon data:image/svg+xml,<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 112.16 122.88"><defs><style>.cls-1{fill: whitesmoke;}</style></defs><title>film-camera</title><path class="cls-1" d="M14.76,47.89H71.34a9.56,9.56,0,0,1,9.54,9.53V93a9.58,9.58,0,0,1-9.54,9.54H53.86l12.7,20.37H54.73L40.89,104.27l-14,18.61h-12l12.62-20.37H14.76A9.57,9.57,0,0,1,5.22,93V57.42a9.56,9.56,0,0,1,9.54-9.53Zm.24-38a15,15,0,1,1-15,15,15,15,0,0,1,15-15ZM5.27,24.93A3.05,3.05,0,1,1,8.32,28a3,3,0,0,1-3.05-3.05Zm9.81,9.66a3.06,3.06,0,1,1,3-3.06,3.05,3.05,0,0,1-3,3.06Zm9.66-9.82a3.06,3.06,0,1,1-3-3.05,3.06,3.06,0,0,1,3,3.05Zm-9.82-9.66a3.06,3.06,0,1,1-3.05,3.06,3.06,3.06,0,0,1,3.05-3.06ZM61.06,0A19.89,19.89,0,1,1,41.17,19.89,19.88,19.88,0,0,1,61.06,0Zm-.12,5.8a4.44,4.44,0,1,1-4.44,4.44A4.44,4.44,0,0,1,60.94,5.8ZM46.88,20.08a4.45,4.45,0,1,1,4.44,4.44,4.44,4.44,0,0,1-4.44-4.44ZM61.17,34.14a4.44,4.44,0,1,1,4.44-4.44,4.44,4.44,0,0,1-4.44,4.44Zm14-14.28a4.44,4.44,0,1,1-4.44-4.45,4.44,4.44,0,0,1,4.44,4.45ZM86.3,91V60.38l25.86-15.24v61.51L86.3,91Z"/></svg>
  11. // @run-at document-end
  12. // @grant GM_addStyle
  13. // ==/UserScript==
  14. /* globals jQuery, $, waitForKeyElements */
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. const setVisibility = (status) => {
  20. let used = $("#requests_table > thead > tr > td:nth-child(2):contains('1')");
  21. status == "hidden" ? used.parent().hide() : used.parent().show();
  22. };
  23.  
  24. const createHideToggle = () => {
  25. const tableElement = document.createElement('tr');
  26. tableElement.setAttribute('id', 'my_tr');
  27. tableElement.innerHTML = `
  28. <td></td>
  29. <td>
  30. <img src="https://cdn-icons-png.flaticon.com/512/60/60954.png" style="width: 1.5em; margin-right: 10px; filter: invert(100%); pointer-events: none;">
  31. <input type="checkbox" id="switch" class="checkbox" />
  32. <label for="switch" class="toggle"></label>
  33. </td>
  34. `;
  35.  
  36. // Use Greasymonkey function to style the button
  37. GM_addStyle("#my_tr { text-align: right; } .toggle { position: relative; display: inline-block; width: 1.5em; background-color: #EFCFD4; border-radius: 10px; border: 2px solid #DEC2C5; padding: 10px; } .toggle:after { content: ''; position: absolute; width: 1.1em; height: 1.1em; border-radius: 50%; background-color: #770919; top: 1px; left: 1px; bottom:1px; transition: all 0.5s; margin-bottom:5px; } .checkbox:checked + .toggle::after { left : 1.5em; background-color: #FFFFFF;} .checkbox:checked + .toggle { background-color: #770919; } .checkbox { display : none; }");
  38.  
  39. const header = document.querySelector('.header');
  40. header.parentNode.insertBefore(tableElement, header);
  41. };
  42.  
  43. const handleCheckboxChange = () => {
  44. const checkbox = document.querySelector("#my_tr > td:nth-child(2) > input")
  45.  
  46. checkbox.addEventListener('change', function() {
  47. if (this.checked) {
  48. setVisibility('hidden');
  49. localStorage.setItem('hideOnLoad', true);
  50. } else {
  51. setVisibility('visible');
  52. localStorage.setItem('hideOnLoad', false);
  53. }
  54. });
  55.  
  56. };
  57.  
  58. const init = () => {
  59.  
  60. const checkbox = document.querySelector("#my_tr > td:nth-child(2) > input");
  61. const hideOnLoad = localStorage.getItem('hideOnLoad');
  62.  
  63. createHideToggle();
  64. setVisibility();
  65. handleCheckboxChange();
  66.  
  67. if (hideOnLoad !== null) {
  68. if (hideOnLoad === "true") {
  69. setVisibility("hidden");
  70. document.querySelector('#my_tr input[type="checkbox"]').checked = true;
  71. } else {
  72. setVisibility("visible");
  73. document.querySelector('#my_tr input[type="checkbox"]').checked = false;
  74. }
  75. }
  76. };
  77.  
  78. init();
  79.  
  80. })();