Created
January 22, 2025 13:10
-
-
Save wiljdaws/67bcedcd2b303a56e780b53c559eea71 to your computer and use it in GitHub Desktop.
deeplink generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Deep Link Generator | |
| // @namespace https://www.linkedin.com/in/djwsoftdev/ | |
| // @icon https://th.bing.com/th/id/OIG3._CZDlLfu1ns7YW7FWJGI?pid=ImgGn | |
| // @version 1.5 | |
| // @description Generate a deep link based on the current URL and add a button to the page to generate the deep link. | |
| // @author Dawson J Williams (wiljdaws) | |
| // @match *://*.console.aws.amazon.com/* | |
| // @grant GM_registerMenuCommand | |
| // @require https://openuserjs.org/src/libs/sizzle/GM_config.js | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| // Load settings from local storage | |
| const loadSettings = () => { | |
| return { | |
| base_url: localStorage.getItem('base_url') || 'https://conduit.security.a2z.com/console', | |
| aws_account_id: localStorage.getItem('aws_account_id') || '', | |
| iam_roles: localStorage.getItem('iam_roles') || '', | |
| active_role: localStorage.getItem('active_role') || '', | |
| session_duration: localStorage.getItem('session_duration') || 43200 | |
| }; | |
| }; | |
| // Save settings to local storage | |
| const saveSettings = (settings) => { | |
| localStorage.setItem('base_url', settings.base_url); | |
| localStorage.setItem('aws_account_id', settings.aws_account_id); | |
| localStorage.setItem('iam_roles', settings.iam_roles); | |
| localStorage.setItem('active_role', settings.active_role); | |
| localStorage.setItem('session_duration', settings.session_duration); | |
| }; | |
| const settings = loadSettings(); | |
| // Configuration | |
| GM_config.init({ | |
| id: 'DeepLinkConfig', | |
| title: 'Deep Link Generator Settings', | |
| fields: { | |
| base_url: { | |
| label: 'Base URL', | |
| type: 'text', | |
| default: settings.base_url | |
| }, | |
| aws_account_id: { | |
| label: 'AWS Account ID', | |
| type: 'text', | |
| default: settings.aws_account_id | |
| }, | |
| iam_roles: { | |
| label: 'IAM Roles (comma-separated)', | |
| type: 'textarea', | |
| default: settings.iam_roles | |
| }, | |
| active_role: { | |
| label: 'Active IAM Role', | |
| type: 'select', | |
| options: settings.iam_roles.split(',').map(role => role.trim()), | |
| default: settings.active_role | |
| }, | |
| session_duration: { | |
| label: 'Session Duration', | |
| type: 'number', | |
| default: settings.session_duration | |
| } | |
| }, | |
| css: ` | |
| #DeepLinkConfig { | |
| background: #f9f9f9; | |
| border: 1px solid #ccc; | |
| padding: 10px; | |
| border-radius: 8px; | |
| } | |
| #DeepLinkConfig .field_label { | |
| font-family: Consolas, monospace; | |
| } | |
| `, | |
| events: { | |
| open: function() { | |
| const roles = GM_config.get('iam_roles').split(',').map(role => role.trim()); | |
| GM_config.fields.active_role.options = roles; | |
| GM_config.fields.active_role.value = GM_config.get('active_role'); | |
| GM_config.fields.active_role.reload(); | |
| }, | |
| save: function() { | |
| const newSettings = { | |
| base_url: GM_config.get('base_url'), | |
| aws_account_id: GM_config.get('aws_account_id'), | |
| iam_roles: GM_config.get('iam_roles'), | |
| active_role: GM_config.get('active_role'), | |
| session_duration: GM_config.get('session_duration') | |
| }; | |
| saveSettings(newSettings); | |
| const roles = newSettings.iam_roles.split(',').map(role => role.trim()); | |
| GM_config.fields.active_role.options = roles; | |
| GM_config.fields.active_role.reload(); | |
| } | |
| } | |
| }); | |
| GM_registerMenuCommand('Settings', () => { | |
| GM_config.open(); | |
| }); | |
| function generateDeepLink(destination_url) { | |
| const params = { | |
| "awsAccountId": GM_config.get('aws_account_id'), | |
| "awsPartition": "aws", | |
| "bucketType": "general", | |
| "iamRole": GM_config.get('active_role'), | |
| "redirect": "true", | |
| "sessionDuration": GM_config.get('session_duration').toString(), | |
| "tab": "objects" | |
| }; | |
| let encoded_destination = encodeURIComponent(destination_url); | |
| encoded_destination = encoded_destination.replace(/\?/g, '%3F').replace(/=/g, '%3D').replace(/#/g, '%23').replace(/%20/g, '+'); | |
| const encoded_params = new URLSearchParams(params).toString(); | |
| return `${GM_config.get('base_url')}?${encoded_params}&destination=${encoded_destination}`; | |
| } | |
| function addButton() { | |
| const button = document.createElement('button'); | |
| button.innerText = 'Generate Deep Link'; | |
| button.id = 'deepLinkButton'; | |
| button.addEventListener('click', () => { | |
| const current_url = window.location.href; | |
| const deep_link = generateDeepLink(current_url); | |
| navigator.clipboard.writeText(deep_link).then(() => { | |
| alert('Deep Link copied to clipboard!'); | |
| }).catch(err => { | |
| console.error('Failed to copy text: ', err); | |
| }); | |
| }); | |
| document.body.appendChild(button); | |
| } | |
| const css = ` | |
| #deepLinkButton { | |
| position: fixed; | |
| bottom: 50px; | |
| right: 25px; | |
| z-index: 1000; | |
| padding: 10px; | |
| background: linear-gradient(145deg, #f9f9f9, #ececec); | |
| color: navy; | |
| font-family: Consolas, monospace; | |
| border: none; | |
| border-radius: 8px; | |
| cursor: pointer; | |
| box-shadow: 0 0 15px 5px #007bff; | |
| animation: rotateGlow 5s infinite linear; | |
| transition: transform 0.3s ease; | |
| } | |
| #deepLinkButton:hover { | |
| transform: scale(1.05); | |
| } | |
| @keyframes rotateGlow { | |
| 0%, 100% { | |
| box-shadow: 0 0 8px 2px #007bff, 0 0 15px 5px #007bff, 0 0 25px 10px #007bff; | |
| } | |
| 25% { | |
| box-shadow: 0 0 15px 5px #007bff, 0 0 25px 10px #007bff, 0 0 35px 15px #007bff; | |
| } | |
| 50% { | |
| box-shadow: 0 0 25px 10px #007bff, 0 0 35px 15px #007bff, 0 0 45px 20px #007bff; | |
| } | |
| 75% { | |
| box-shadow: 0 0 15px 5px #007bff, 0 0 25px 10px #007bff, 0 0 35px 15px #007bff; | |
| } | |
| } | |
| `; | |
| const style = document.createElement('style'); | |
| style.type = 'text/css'; | |
| style.appendChild(document.createTextNode(css)); | |
| document.head.appendChild(style); | |
| addButton(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment