From 8c28e761e0d157a332e55b135b8e99686c1e0f31 Mon Sep 17 00:00:00 2001 From: Greg Jacobs Date: Thu, 6 Jun 2024 04:22:38 -0400 Subject: [PATCH] git hook to fix readme when i commit as well as watchlist populator to speed up setting up all cc's for a deploy --- README.MD | 69 +++++++++++++------ package.json | 3 +- src/utils/bookmarklets/rbcSiteNavigator.js | 29 ++++++++ .../bookmarklets/rbcWatchlistPopulator.js | 48 +++++++++++++ src/utils/git/updateReadme.js | 68 ++++++++++++++++++ 5 files changed, 196 insertions(+), 21 deletions(-) create mode 100644 src/utils/bookmarklets/rbcSiteNavigator.js create mode 100644 src/utils/bookmarklets/rbcWatchlistPopulator.js create mode 100644 src/utils/git/updateReadme.js diff --git a/README.MD b/README.MD index 2101232..e7c1560 100644 --- a/README.MD +++ b/README.MD @@ -1,39 +1,68 @@ -# Gregs Memory Palace +# Gregs Memory Palace + +This project contains several files that perform various tasks. Here's a brief overview of each file: + +# File Summary -This project contains several files that perform various tasks. Here's a brief overview of each file: +## [dag.js](src\utils\bookmarklets\dag.js) -## [DAG](src/utils/bookmarklets/dag.js) + Opens the DAG Task details page(s) based on user input. If user provides a comma-separated list of DAG Task numbers, it opens each task's details page in a new tab. If user does not provide any input, it opens the default DAG Tasks page in a new tab. -This JavaScript file contains a bookmarklet function that prompts the user for a list of DAG Task numbers, separated by commas. For each provided number, it opens a new browser tab with the corresponding DAG Task details page. If the user doesn't provide any input, it opens the default DAG Tasks page in a new tab. This can be useful for quickly accessing multiple DAG Task details pages based on user input. +## [hashid.js](src\utils\bookmarklets\hashid.js) -## [hashid](src/utils/bookmarklets/hashid.js) + This JavaScript function takes a string, decodes it using decodeURIComponent, alerts the decoded string, and copies the result to the clipboard. The function works as follows: 1. Takes a string as input. 2. Decodes the string using decodeURIComponent. 3. Alerts the decoded string. 4. Copies the decoded string to the clipboard. Note: This function uses the Clipboard API which might not be fully supported in all browsers. -This JavaScript file contains a bookmarklet function that takes a string, decodes it using decodeURIComponent, alerts the decoded string, and copies the result to the clipboard. +## [jira.js](src\utils\bookmarklets\jira.js) -## [jira.js](src/utils/bookmarklets/jira.js) + This JavaScript function is a bookmarklet that prompts the user for a JIRA ticket number and then opens a new browser tab with the corresponding JIRA page for that ticket. The function works as follows: 1. Prompts the user to enter a JIRA ticket number. The entered value is stored in the `answer` variable. 2. Sets a default URL to the JIRA dashboard. 3. Checks if the user entered a value in the prompt. 4. If the user entered a value, changes the URL to point to the specific JIRA page for the entered ticket number. 5. Opens the URL in a new browser tab and brings focus to it. Note: This function is wrapped in a self-invoking function `(function() {...})();` which means it will automatically execute as soon as it is defined. -This JavaScript file contains a bookmarklet function that prompts the user for a JIRA ticket number and then opens a new browser tab with the corresponding JIRA page for that ticket. +## [moids.js](src\utils\bookmarklets\moids.js) -## [moids.js](src/utils/bookmarklets/moids.js) + This JavaScript function is a bookmarklet that prompts the user for multiple MOID (Markit On Demand) numbers and then opens a new browser tab for each corresponding Jira page for those MOIDs. The function works as follows: 1. Prompts the user to enter MOID numbers separated by commas. The entered values are stored in the `answers` array. 2. Sets a default URL to the Jira dashboard. 3. Checks if the user entered any values in the prompt. 4. If the user entered values, changes the URL to point to the specific Jira page for each entered MOID number. 5. Opens each URL in a new browser tab and brings focus to the last opened tab. Note: This function is wrapped in a self-invoking function `(function() {...})();` which means it will automatically execute as soon as it is defined. -This JavaScript file contains a bookmarklet function that prompts the user for multiple MOID (Markit On Demand) numbers and then opens a new browser tab for each corresponding Jira page for those MOIDs. +## [rbc-di-featureflags.js](src\utils\bookmarklets\rbc-di-featureflags.js) -## [rbc-di-featureflag.js](src/utils/bookmarklets/rbc-di-featureflags.js) + This function creates a modal dialog that allows the user to toggle feature flags. It retrieves the feature flags from the session storage, creates checkboxes for each flag, and saves the updated flags back to the session storage when the user clicks the save button. The modal dialog is appended to the document body and can be closed by clicking the save button. -This JavaScript file contains a bookmarklet function that checks the feature flags set in the session storage and displays themm as checkboxes that the user can set then save +## [rbcSessionStorage.js](src\utils\bookmarklets\rbcSessionStorage.js) -## [Workspace - WIP](src/utils/bookmarklets/workspace.js) + Deletes the 'fnc-rbc-session' property from the session storage if it exists. If the property exists, it prompts the user for confirmation before deleting. If the property does not exist, it displays an alert message. -This is just so i can get up and running on a new window with all the pages i care about +## [rbcSiteNavigator.js](src\utils\bookmarklets\rbcSiteNavigator.js) -## [jsToMsDate.js](src/utils/others/jsToMsDate.js) + Opens a specific URL based on the provided environment and language. Prompts the user to enter the environment and language in the format 'prod|ste,en|fr'. If the input is valid, it opens the corresponding URL in a new tab. If the input is invalid, it logs an error message to the console. -This JavaScript file contains a function that converts a JavaScript Date object to a Microsoft Date string format. It can be useful when working with APIs or databases that require dates to be in the Microsoft Date format. +## [rbcWatchlistPopulator.js](src\utils\bookmarklets\rbcWatchlistPopulator.js) -## [msToJsDate.js](src/utils/others/msToJsDate.js) + +This code is a bookmarklet that populates a watchlist on a web page. +It defines an array of new securities and a function called populateWatchlist. +The function finds the input field on the page, iterates over the new securities array, +and sets the value of the input field to each security in the array. +It then triggers events to simulate user input and key presses to add the security to the watchlist. +The process repeats for each security in the array with a delay of 2.5 seconds between each iteration. +The code is executed when the bookmarklet is clicked on the web page. -This JavaScript file contains a function that converts a Microsoft Date string format to a JavaScript Date object. It can be useful when working with APIs or databases that provide dates in the Microsoft Date format. +## [workspace.js](src\utils\bookmarklets\workspace.js) -## [showDebugInfo.js](src/utils/others/showDebugInfo.js) +No Description Provided -This JavaScript file contains a bookmarklet function that displays debug information about the current page. It can be useful for troubleshooting and understanding the state of the page during development. \ No newline at end of file +## [updateReadme.js](src\utils\git\updateReadme.js) + + This file is responsible for updating the README file with file links and descriptions. It reads the files in the specified directory, extracts their descriptions, and generates markdown links for each file. Then, it updates the README file with the generated links and descriptions. + +## [importBookmarkMaker.js](src\utils\importBookmarkMaker.js) + +No Description Provided + +## [jsToMsDate.js](src\utils\others\jsToMsDate.js) + +No Description Provided + +## [msToJsDate.js](src\utils\others\msToJsDate.js) + +No Description Provided + +## [showDebugInfo.js](src\utils\others\showDebugInfo.js) + +No Description Provided \ No newline at end of file diff --git a/package.json b/package.json index 0336421..edcfc05 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "test": "echo \"Error: no test specified\" && exit 1", "lint": "eslint src --ext .js", "lint:fix": "eslint src --ext .js --fix", - "format": "prettier src --write --ignore-unknown" + "format": "prettier src --write --ignore-unknown", + "readme": "node updateReadme.js" }, "repository": { "type": "git", diff --git a/src/utils/bookmarklets/rbcSiteNavigator.js b/src/utils/bookmarklets/rbcSiteNavigator.js new file mode 100644 index 0000000..37bda70 --- /dev/null +++ b/src/utils/bookmarklets/rbcSiteNavigator.js @@ -0,0 +1,29 @@ + +/** + * Opens a specific URL based on the provided environment and language. + * Prompts the user to enter the environment and language in the format 'prod|ste,en|fr'. + * If the input is valid, it opens the corresponding URL in a new tab. + * If the input is invalid, it logs an error message to the console. + */ +javascript: (function () { + const answer = prompt("Please enter the env and language in the format 'prod|ste,en|fr':"); + const [env, language] = answer.split(","); + switch (env) { + case "prod": + if (language === "fr") { + window.open("https://www1.royalbank.com/french/netaction/sgnf.html", "_blank").focus(); + } else { + window.open("https://www1.royalbank.com/english/netaction/sgne.html", "_blank").focus(); + } + break; + case "ste": + if (language === "fr") { + window.open("https://www1.steroyalbank.com/french/netaction/sgnf.html", "_blank").focus(); + } else { + window.open("https://www1.steroyalbank.com/english/netaction/sgne.html", "_blank").focus(); + } + break; + default: + console.log("Invalid input"); + } +})(); \ No newline at end of file diff --git a/src/utils/bookmarklets/rbcWatchlistPopulator.js b/src/utils/bookmarklets/rbcWatchlistPopulator.js new file mode 100644 index 0000000..bcee6a8 --- /dev/null +++ b/src/utils/bookmarklets/rbcWatchlistPopulator.js @@ -0,0 +1,48 @@ +/** +This code is a bookmarklet that populates a watchlist on a web page. +It defines an array of new securities and a function called populateWatchlist. +The function finds the input field on the page, iterates over the new securities array, +and sets the value of the input field to each security in the array. +It then triggers events to simulate user input and key presses to add the security to the watchlist. +The process repeats for each security in the array with a delay of 2.5 seconds between each iteration. +The code is executed when the bookmarklet is clicked on the web page. +*/ +javascript: (function () { + const newSecurities = [ + 'AMX', + 'VNORP', + 'AMBKP', + 'CSU.DB', + 'NFLX', + 'ICFSSUSN', + 'ICRP', + 'LDSVF', + 'AMTPQ', + 'DSHKP', + 'AITRR', + 'URW', + 'AP.UN', + 'PVF.WT' + ]; + function populateWatchlist() { + const foundInputs = document.querySelectorAll('.rbc-typeahead-search-input'); + const input = foundInputs && foundInputs.length > 1 ? foundInputs[1] : null; + if (input) { + let index = 0; + const interval = setInterval(() => { + if (index >= newSecurities.length) { + clearInterval(interval); + return; + } + input.value = newSecurities[index]; + input.dispatchEvent(new Event('input', { bubbles: true })); + input.dispatchEvent(new Event('change', { bubbles: true })); + setTimeout(() => { + input.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 13 })); + }, 1000); + index++; + }, 2500); + } + } + populateWatchlist(); +})(); diff --git a/src/utils/git/updateReadme.js b/src/utils/git/updateReadme.js new file mode 100644 index 0000000..4d1bf29 --- /dev/null +++ b/src/utils/git/updateReadme.js @@ -0,0 +1,68 @@ + +/** + * This file is responsible for updating the README file with file links and descriptions. + * It reads the files in the specified directory, extracts their descriptions, and generates + * markdown links for each file. Then, it updates the README file with the generated links + * and descriptions. + */ +const fs = require('fs'); +const path = require('path'); + +const resolvedPath = path.resolve(); +console.log(resolvedPath); + +const utilsDir = path.join(resolvedPath, 'src/utils'); +const readmePath = path.join(resolvedPath, 'README.md'); + +fs.readdir(utilsDir, (err, files) => { + function readDirectory(dir) { + const files = fs.readdirSync(dir); + const fileLinks = []; + + files.forEach((file) => { + const filePath = path.join(dir, file); + const stats = fs.statSync(filePath); + + if (stats.isFile()) { + const fileContent = fs.readFileSync(filePath, 'utf8'); + const description = getFileDescription(fileContent); + fileLinks.push(`## [${file}](${path.relative(resolvedPath, filePath)})\n\n${description}`); + } else if (stats.isDirectory()) { + fileLinks.push(...readDirectory(filePath)); + } + }); + + return fileLinks; + } + + const fileLinks = readDirectory(utilsDir); + + const readmeContent = fs.readFileSync(readmePath, 'utf8'); + let updatedReadmeContent = updateReadmeContent(readmeContent, fileLinks); + fs.writeFileSync(readmePath, updatedReadmeContent, 'utf8'); + + console.log('README updated successfully!'); +}); + +function getFileDescription(fileContent) { + // Extract the description from the function comment in the file + // You can use regular expressions or any other method to extract the description + // Replace the following line with your implementation + const descriptionRegex = /\/\*(.*?)\*\//s; + const match = fileContent.match(descriptionRegex); + const description = match ? match[1].trim().replace(/^\s*\* ?/gm, '') : 'No Description Provided'; + // const description = match ? match[1].trim().replace(/^\*/gm, '') : 'No Description Provided'; + + return description; +} + +function updateReadmeContent(readmeContent, fileLinks) { + const readmeSummaryIndex = readmeContent.indexOf('# File Summary'); + if (readmeSummaryIndex !== -1) { + // If '# File Summary' is found, keep everything before it + readmeContent = readmeContent.slice(0, readmeSummaryIndex); + } + // Append the new '# File Summary' section + readmeContent += '# File Summary\n\n' + fileLinks.join('\n\n'); + return readmeContent; +} \ No newline at end of file