Kanka Entity Privacy Setting on the Entry Tab

Makes the entity Privacy checkbox visible on both the Entry and Permissions tabs

  1. // ==UserScript==
  2. // @name Kanka Entity Privacy Setting on the Entry Tab
  3. // @namespace http://tampermonkey.net/
  4. // @version 2
  5. // @description Makes the entity Privacy checkbox visible on both the Entry and Permissions tabs
  6. // @author Salvatos
  7. // @license MIT
  8. // @match https://app.kanka.io/*/create*
  9. // @match https://app.kanka.io/*/edit*
  10. // @exclude https://app.kanka.io/*/posts/*
  11. // @icon https://www.google.com/s2/favicons?domain=kanka.io
  12. // ==/UserScript==
  13.  
  14. /* Only run if the current user has access to the Permissions tab */
  15. let permissionsTab = document.getElementById('form-permissions') ?? false;
  16.  
  17. if (permissionsTab) {
  18. const privBox = document.getElementsByClassName('privacy-callout')[0];
  19. const entryTab = document.getElementById('form-entry');
  20.  
  21. // At page load, move checkbox to top of Entry tab
  22. setTimeout(() => { // Give it half a second for the form’s JS to set the classes
  23. if (entryTab.classList.contains("active")) {
  24. entryTab.insertBefore(privBox, entryTab.firstChild);
  25. observePermissions();
  26. }
  27. // Unless the page is being reloaded in a different tab
  28. else {
  29. observeEntry();
  30. }
  31. }, 500);
  32.  
  33. /* When Permissions or Entry tab is focused, move checkbox to it.
  34. * Don’t rely on onClick, because the Back/Forward browser action also cycles between previously visited tabs.
  35. * Use mutation observers instead to watch the .active class. */
  36.  
  37. function observeEntry() {
  38. // Set and run an observer until the tab is activated
  39. let observer = new MutationObserver(function(mutations) {
  40. if (entryTab.classList.contains("active")) {
  41. entryTab.prepend(privBox);
  42. //console.log("Moved tab to Entry at " + Date.now());
  43. observer.disconnect();
  44. observePermissions();
  45. }
  46. });
  47. observer.observe(entryTab, {attributes: true, childList: false, characterData: false, subtree: false});
  48. }
  49. function observePermissions() {
  50. // Set and run an observer until the tab is activated
  51. let observer = new MutationObserver(function(mutations) {
  52. if (permissionsTab.classList.contains("active")) {
  53. permissionsTab.prepend(privBox);
  54. //console.log("Moved tab to Permissions at " + Date.now());
  55. observer.disconnect();
  56. observeEntry();
  57. }
  58. });
  59. observer.observe(permissionsTab, {attributes: true, childList: false, characterData: false, subtree: false});
  60. }
  61. }