fb-root-filter.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. (function () {
  2. var HIDE_AT_ROOT = new Set(['content', 'excels', 'excels_html', 'pdfs', 'words', 'words_html']);
  3. function isRootFilesPath(path) {
  4. var p = (path || '').replace(/\/+$/, '');
  5. return p === '' || p === '/files';
  6. }
  7. function textOf(el) {
  8. var n = el.querySelector && el.querySelector('.name');
  9. var t = n ? (n.textContent || '') : (el.textContent || '');
  10. return t.trim();
  11. }
  12. function hideDefaultFoldersAtRoot() {
  13. if (!isRootFilesPath(location.pathname)) return;
  14. var items = document.querySelectorAll('#listing .item');
  15. items.forEach(function (item) {
  16. var name = textOf(item);
  17. if (!name || !HIDE_AT_ROOT.has(name)) return;
  18. // hide item card/row without affecting backend data
  19. item.style.display = 'none';
  20. item.setAttribute('data-fb-hidden-default', '1');
  21. });
  22. }
  23. function apply() {
  24. hideDefaultFoldersAtRoot();
  25. }
  26. var ob = new MutationObserver(function () { apply(); });
  27. ob.observe(document.documentElement, { childList: true, subtree: true });
  28. apply();
  29. setTimeout(apply, 100);
  30. setTimeout(apply, 400);
  31. })();