Bitwarden Select Enhance

Enable shift-click checkbox to select items bulkly in Bitwarden web.

  1. // ==UserScript==
  2. // @name Bitwarden Select Enhance
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.2
  5. // @description Enable shift-click checkbox to select items bulkly in Bitwarden web.
  6. // @author moeakwak
  7. // @match https://vault.bitwarden.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=bitwarden.com
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. function waitForElment(selector) {
  15. return new Promise(resolve => {
  16. if (document.querySelector(selector)) {
  17. return resolve(document.querySelector(selector));
  18. }
  19.  
  20. const observer = new MutationObserver(mutations => {
  21. if (document.querySelector(selector)) {
  22. resolve(document.querySelector(selector));
  23. observer.disconnect();
  24. }
  25. });
  26.  
  27. observer.observe(document.body, {
  28. childList: true,
  29. subtree: true
  30. });
  31. });
  32. }
  33.  
  34.  
  35. function selectBetween(tbody, from, to) {
  36. tbody.children("tr").each(function (index) {
  37. if (index > from && index < to)
  38. $(this).find("td.table-list-checkbox > input").click();
  39. })
  40. }
  41.  
  42.  
  43. function bindOnClick(tbody) {
  44. tbody.children("tr").each(function (index) {
  45. $(this).find("td.table-list-checkbox > input").click(function (ev) {
  46. // console.log("clicked", index, ev);
  47. if (ev.shiftKey) {
  48. selectBetween(tbody, lastClickIndex, index);
  49. } else {
  50. lastClickIndex = index;
  51. }
  52. })
  53. })
  54. }
  55.  
  56.  
  57. let lastClickIndex = null;
  58.  
  59.  
  60. $(document).ready(async function() {
  61. await waitForElment("app-vault-ciphers > table");
  62.  
  63. const tbody = $("app-vault-ciphers > table > tbody");
  64.  
  65. bindOnClick(tbody);
  66.  
  67. tbody.bind('DOMSubtreeModified', function(e) {
  68. if (e.target.innerHTML.length > 0) {
  69. bindOnClick(tbody);
  70. }
  71. });
  72. });