Add article menu item

This user script will add menu options to to each article in BuildWise.

目前为 2024-12-13 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Add article menu item
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description This user script will add menu options to to each article in BuildWise.
  6. // @author saikiran.dannana@buildwise.ai
  7. // @match *://*.buildwise.ai/*
  8. // @icon https://images.buildwise.ai/BuildWise_logo_without_name.png
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. console.log("Script execution starts");
  16. // This script adds a click event listener to an element with id 'article-menu-btn'.
  17. // When clicked, it clones an element with id 'article-menu-item-1', modifies its content using an array of objects,
  18. // and appends the modified clones to a container with id 'article-menu-container'.
  19.  
  20. // Wait for the DOM to load
  21.  
  22. setTimeout(()=> {
  23. // Get the button element by its ID
  24. const menuButton = document.getElementById('article-menu-btn');
  25. console.log("Menu Button", menuButton);
  26.  
  27. // Ensure the button exists
  28. if (!menuButton) {
  29. console.error('Button with id "article-menu-btn" not found.');
  30. return;
  31. }
  32.  
  33. // Add a click event listener to the button
  34. menuButton.addEventListener('click', () => {
  35. console.log("Menu Button clicked");
  36. // Get the container element by its ID
  37. setTimeout(() => {
  38. const menuContainer = document.getElementById('menu-list-container');
  39.  
  40. // Ensure the container exists
  41. if (!menuContainer) {
  42. console.error('Container with id "menu-list-container" not found.');
  43. return;
  44. }
  45.  
  46. // Find the element to be cloned by its ID
  47. const menuItemToClone = document.getElementById('menu-list-item-1');
  48. console.log(menuItemToClone);
  49.  
  50. // Ensure the element to clone exists
  51. if (!menuItemToClone) {
  52. console.error('Element with id "menu-list-item-1" not found.');
  53. return;
  54. }
  55.  
  56. // Define the array of items with svgIcon and name keys
  57. const items = [
  58. { svgIcon: `
  59. <svg width="17" height="17" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
  60. <path d="M5.44019 2.97528C4.7482 3.04007 4.12246 3.25208 3.58948 3.60544C3.37011 3.74973 3.22435 3.86898 3.03147 4.06186C2.5353 4.5595 2.18931 5.22352 2.03913 5.96998C1.9449 6.43524 1.95226 5.89784 1.94637 12.4261C1.94343 16.7297 1.94637 18.417 1.95815 18.5878C2.01263 19.3475 2.23495 20.0306 2.61039 20.5901C2.80768 20.8831 3.12718 21.2247 3.3863 21.4176C3.94873 21.8387 4.61569 22.0963 5.35921 22.1802C5.65368 22.2126 18.4953 22.2141 18.8015 22.1802C19.5347 22.1022 20.1884 21.8563 20.7243 21.4588C21.5003 20.8816 21.9861 20.0645 22.1569 19.0442C22.2143 18.7041 22.2173 18.5745 22.2173 16.7945V15.0616L19.8822 15.0645L17.5486 15.0689L16.5282 16.8136L15.5079 18.5583H12.0067H8.50556L6.75644 15.5695L5.00586 12.5822L5.04119 12.5218C5.07653 12.4614 7.8813 7.6661 8.28471 6.97852L8.50409 6.60308H12.0067H15.5094L16.5268 8.34778L17.5441 10.0925L19.8807 10.0969L22.2173 10.0998V8.40078C22.2173 6.65314 22.2129 6.48235 22.1569 6.14224C22.0185 5.2986 21.6799 4.61839 21.1204 4.05597C20.5948 3.5274 19.9543 3.19466 19.1681 3.04007C18.7352 2.95614 19.1048 2.95909 12.0583 2.96203C8.49084 2.96203 5.51381 2.96792 5.44019 2.97528Z" fill="black"/>
  61. <path d="M10.2356 9.27804C10.2194 9.30454 9.83067 9.99212 9.37131 10.8063C8.91195 11.6205 8.49675 12.3522 8.45111 12.4332L8.36719 12.5819L9.31094 14.1779L10.2547 15.7754H12.1525H14.0503L14.9764 14.2074C15.4859 13.3446 15.9099 12.6246 15.9187 12.6084C15.932 12.5805 15.8009 12.3419 14.9882 10.9035L14.043 9.23093H12.154H10.265L10.2356 9.27804Z" fill="#EC5F2A"/>
  62. </svg>
  63. `, name: 'Send to Procore' },
  64. ];
  65.  
  66. // Iterate over the array to create modified clones
  67. items.forEach(item => {
  68. // Clone the original menu item
  69. const clonedItem = menuItemToClone.cloneNode(true);
  70.  
  71. // Find and update the SVG content within the cloned item
  72. const svgElement = clonedItem.querySelector('svg');
  73. if (svgElement) {
  74. svgElement.outerHTML = item.svgIcon;
  75. }
  76.  
  77. // Find and update the text content within the cloned item
  78. const textNode = clonedItem.querySelector('#menu-item-title'); // Assuming a class for the text node
  79. if (textNode) {
  80. textNode.textContent = item.name;
  81. }
  82.  
  83. console.log(clonedItem);
  84.  
  85. // Append the modified clone to the container
  86. menuContainer.appendChild(clonedItem);
  87. });
  88. });
  89. }, 2000);
  90. }, 8000);
  91. })();