BOSS - bookmark.os saver script

Adds a shortcut to bookmark the current page with bookmark.os <https://bookmarkos.com/help/basics>. CTRL + ALT + ']' opens a pop-up to bookmark the current page, CTRL + ALT + '[' shows all bookmarks in a new tab.

  1. // ==UserScript==
  2. // @name BOSS - bookmark.os saver script
  3. // @namespace <https://github.com/lundeen-bryan>
  4. // @version 1.1.1
  5. // @description Adds a shortcut to bookmark the current page with bookmark.os <https://bookmarkos.com/help/basics>. CTRL + ALT + ']' opens a pop-up to bookmark the current page, CTRL + ALT + '[' shows all bookmarks in a new tab.
  6. // @author lundeen-bryan
  7. // @match *://*/*
  8. // @icon https://bookmarkos.com//favicon-32x32.png
  9. // @license GPL
  10. // @run-at 'document-end'
  11. // @noframes true
  12. // ==/UserScript==
  13.  
  14. /**
  15. * This function extracts meta information from the current webpage and opens a new window
  16. * with a URL that includes this meta information as parameters for bookmarking purposes.
  17. */
  18. function bookmarkPage() {
  19. // Get all meta elements on the current page
  20. var metas = document.getElementsByTagName("meta");
  21. var metaInfo = {};
  22. var metaDescription = null;
  23. var ogDescription = null;
  24. var twitterDescription = null;
  25. var ogType = null;
  26. var metaKeywords = null;
  27.  
  28. // Loop through the meta elements to find specific meta information
  29. for (var i = 0; i < metas.length; i++) {
  30. // Get the current meta element in the loop
  31. var meta = metas[i];
  32.  
  33. // Check if the 'name' attribute of the meta element is 'description'
  34. if (meta.getAttribute("name") == "description") {
  35. // If it is, assign the value of the 'content' attribute to 'metaDescription'
  36. metaDescription = metas[i].getAttribute("content");
  37. }
  38. // Check if the 'property' attribute of the meta element is 'og:description'
  39. else if (meta.getAttribute("property") == "og:description") {
  40. // If it is, assign the value of the 'content' attribute to 'ogDescription'
  41. ogDescription = metas[i].getAttribute("content");
  42. }
  43. // Check if the 'name' attribute of the meta element is 'twitter:description'
  44. else if (meta.getAttribute("name") == "twitter:description") {
  45. // If it is, assign the value of the 'content' attribute to 'twitterDescription'
  46. twitterDescription = metas[i].getAttribute("content");
  47. }
  48. // Check if the 'property' attribute of the meta element is 'og:type'
  49. else if (meta.getAttribute("property") == "og:type") {
  50. // If it is, assign the value of the 'content' attribute to 'ogType'
  51. ogType = metas[i].getAttribute("content");
  52. }
  53. // Check if the 'name' attribute of the meta element is 'keywords'
  54. else if (meta.getAttribute("name") == "keywords") {
  55. // If it is, assign the value of the 'content' attribute to 'metaKeywords'
  56. metaKeywords = metas[i].getAttribute("content");
  57. }
  58. }
  59.  
  60. // Store the extracted meta information in an object
  61. metaInfo["meta_description"] =
  62. metaDescription || ogDescription || twitterDescription;
  63. metaInfo["meta_keywords"] = metaKeywords;
  64. metaInfo["og_type"] = ogType;
  65.  
  66. // Calculate the window position for the new window, center the modal window on active screen
  67. var dualScreenLeft =
  68. window.screenLeft != undefined ? window.screenLeft : screen.left;
  69. var dualScreenTop =
  70. window.screenTop != undefined ? window.screenTop : screen.top;
  71. width = window.innerWidth
  72. ? window.innerWidth
  73. : document.documentElement.clientWidth
  74. ? document.documentElement.clientWidth
  75. : screen.width;
  76. height = window.innerHeight
  77. ? window.innerHeight
  78. : document.documentElement.clientHeight
  79. ? document.documentElement.clientHeight
  80. : screen.height;
  81.  
  82. var left = width / 2 - 750 / 2 + dualScreenLeft;
  83. var top = height / 2 - 450 / 2 + dualScreenTop;
  84.  
  85. // Open a new window with the bookmarking URL and meta information as parameters
  86. window.open(
  87. "https://bookmarkos.com/save?url=" +
  88. encodeURIComponent(location.href) +
  89. "&title=" +
  90. encodeURIComponent(document.title) +
  91. "&meta_description=" +
  92. encodeURIComponent(metaInfo["meta_description"]) +
  93. "&meta_keywords=" +
  94. encodeURIComponent(metaInfo["meta_keywords"]) +
  95. "&og_type=" +
  96. encodeURIComponent(metaInfo["og_type"]),
  97. "bookmark",
  98. "left=" +
  99. left +
  100. ",top=100,width=750,height=450,toolbar=0,location=0,resizable=0"
  101. );
  102. }
  103.  
  104. function gotoBm() {
  105. // Shows bookmarks sorted by time, insted of the senseless sort by title default
  106. window.open("https://bookmarkos.com/access_extension");
  107. }
  108.  
  109. function keyPressEvent(event) {
  110. var kcode = event.keyCode ? event.keyCode : event.which;
  111. if (event.ctrlKey && event.altKey) {
  112. if (kcode == 221) bookmarkPage(); // ']'
  113. if (kcode == 219) gotoBm(); // '['
  114. }
  115. }
  116.  
  117. document.addEventListener('keydown', keyPressEvent, true);
  118.  
  119. // Call the bookmarkPage function to initiate the bookmarking process
  120. // bookmarkPage();