├── samples ├── links-sample.png ├── attachments-sample.png ├── options-button-sample.png ├── link-patterns.json └── sample.html ├── src ├── icons │ ├── zlc-icon-16x16.png │ ├── zlc-icon-32x32.png │ ├── zlc-icon-48x48.png │ ├── bufo-sad-but-ok.png │ ├── zlc-icon-128x128.png │ ├── zlc-icon-disabled-16x16.png │ ├── home.svg │ ├── loader.svg │ ├── gear.svg │ ├── search.svg │ ├── copy.svg │ └── check.svg ├── manifest.json ├── manifest-chrome.json ├── manifest-firefox.json ├── options │ ├── options.css │ ├── options.html │ └── options.js ├── popup │ ├── popup.html │ ├── popup.css │ └── popup.js ├── content-scripts │ └── contentscript.js ├── lib │ └── browser-polyfill.min.js └── background │ └── background.js ├── .github ├── dependabot.yml └── workflows │ ├── diagram.yml │ └── codeql.yml ├── .gitignore ├── makefile ├── PRIVACY.md ├── README.md ├── diagram.svg └── LICENSE /samples/links-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BagToad/Zendesk-Link-Collector/HEAD/samples/links-sample.png -------------------------------------------------------------------------------- /src/icons/zlc-icon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BagToad/Zendesk-Link-Collector/HEAD/src/icons/zlc-icon-16x16.png -------------------------------------------------------------------------------- /src/icons/zlc-icon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BagToad/Zendesk-Link-Collector/HEAD/src/icons/zlc-icon-32x32.png -------------------------------------------------------------------------------- /src/icons/zlc-icon-48x48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BagToad/Zendesk-Link-Collector/HEAD/src/icons/zlc-icon-48x48.png -------------------------------------------------------------------------------- /samples/attachments-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BagToad/Zendesk-Link-Collector/HEAD/samples/attachments-sample.png -------------------------------------------------------------------------------- /src/icons/bufo-sad-but-ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BagToad/Zendesk-Link-Collector/HEAD/src/icons/bufo-sad-but-ok.png -------------------------------------------------------------------------------- /src/icons/zlc-icon-128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BagToad/Zendesk-Link-Collector/HEAD/src/icons/zlc-icon-128x128.png -------------------------------------------------------------------------------- /samples/options-button-sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BagToad/Zendesk-Link-Collector/HEAD/samples/options-button-sample.png -------------------------------------------------------------------------------- /src/icons/zlc-icon-disabled-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BagToad/Zendesk-Link-Collector/HEAD/src/icons/zlc-icon-disabled-16x16.png -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "github-actions" 9 | directory: "/" 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /.github/workflows/diagram.yml: -------------------------------------------------------------------------------- 1 | name: Project Structure Diagram 2 | permissions: 3 | contents: write 4 | on: 5 | workflow_dispatch: 6 | push: 7 | branches: 8 | - main 9 | jobs: 10 | get_data: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout code 14 | uses: actions/checkout@v5 15 | - name: Update diagram 16 | uses: githubocto/repo-visualizer@0.9.1 17 | with: 18 | excluded_paths: "LICENSE, PRIVACY.md, README.md, .gitignore" 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ZLC Specific 2 | build 3 | 4 | # General 5 | .DS_Store 6 | .AppleDouble 7 | .LSOverride 8 | 9 | # Icon must end with two \r 10 | Icon 11 | 12 | # Thumbnails 13 | ._* 14 | 15 | # Files that might appear in the root of a volume 16 | .DocumentRevisions-V100 17 | .fseventsd 18 | .Spotlight-V100 19 | .TemporaryItems 20 | .Trashes 21 | .VolumeIcon.icns 22 | .com.apple.timemachine.donotpresent 23 | 24 | # Directories potentially created on remote AFP share 25 | .AppleDB 26 | .AppleDesktop 27 | Network Trash Folder 28 | Temporary Items 29 | .apdisk 30 | -------------------------------------------------------------------------------- /src/icons/home.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /samples/link-patterns.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "b19a712c-dd34-491f-a43a-c0483f44f045", 4 | "pattern": "https:\\/\\/docs\\.github\\.com\\/", 5 | "showDate": false, 6 | "showParent": false, 7 | "summaryType": "none", 8 | "title": "GitHub Docs" 9 | }, 10 | { 11 | "id": "4adcb721-769c-48cd-b1b4-21bc76addad4", 12 | "pattern": "https:\\/\\/github\\.com\\/orgs\\/community\\/discussions", 13 | "showDate": true, 14 | "showParent": false, 15 | "summaryType": "all", 16 | "title": "GitHub Discussions" 17 | }, 18 | { 19 | "id": "9f6bc302-e46a-4621-a55d-fc4af232984d", 20 | "pattern": "https://[A-Za-z0-9]+\\.zendesk\\.com/agent/tickets/[0-9]+", 21 | "showDate": false, 22 | "showParent": false, 23 | "summaryType": "all", 24 | "title": "Zendesk Tickets" 25 | } 26 | ] 27 | -------------------------------------------------------------------------------- /src/icons/loader.svg: -------------------------------------------------------------------------------- 1 | 2 | loader-icon-svg 3 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 3, 3 | "name": "Zendesk Link Collector", 4 | "version": "1.4.0", 5 | "description": "Summarize links and attachments", 6 | "background": { 7 | "service_worker": "background/background.js" 8 | }, 9 | "content_scripts": [ 10 | { 11 | "matches": ["https://*.zendesk.com/*"], 12 | "run_at": "document_start", 13 | "js": ["lib/browser-polyfill.min.js", "content-scripts/contentscript.js"] 14 | } 15 | ], 16 | "icons": { 17 | "128": "icons/zlc-icon-128x128.png", 18 | "48": "icons/zlc-icon-48x48.png", 19 | "32": "icons/zlc-icon-32x32.png", 20 | "16": "icons/zlc-icon-16x16.png" 21 | }, 22 | "options_ui": { 23 | "page": "options/options.html", 24 | "browser_style": false, 25 | "open_in_tab": true 26 | }, 27 | "action": { 28 | "default_popup": "popup/popup.html" 29 | }, 30 | "commands": { 31 | "_execute_action": { 32 | "description": "Open the extension" 33 | }, 34 | "copy-ticket-id": { 35 | "description": "Copy ticket ID to clipboard" 36 | }, 37 | "copy-ticket-id-md": { 38 | "description": "Copy ticket ID to clipboard in markdown" 39 | } 40 | }, 41 | "permissions": ["activeTab", "storage", "clipboardWrite"], 42 | "host_permissions": ["https://*.zendesk.com/*"] 43 | } 44 | -------------------------------------------------------------------------------- /src/manifest-chrome.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 3, 3 | "name": "Zendesk Link Collector", 4 | "version": "1.4.0", 5 | "description": "Summarize links and attachments", 6 | "background": { 7 | "service_worker": "background/background.js" 8 | }, 9 | "content_scripts": [ 10 | { 11 | "matches": ["https://*.zendesk.com/*"], 12 | "run_at": "document_start", 13 | "js": ["lib/browser-polyfill.min.js", "content-scripts/contentscript.js"] 14 | } 15 | ], 16 | "icons": { 17 | "128": "icons/zlc-icon-128x128.png", 18 | "48": "icons/zlc-icon-48x48.png", 19 | "32": "icons/zlc-icon-32x32.png", 20 | "16": "icons/zlc-icon-16x16.png" 21 | }, 22 | "options_ui": { 23 | "page": "options/options.html", 24 | "browser_style": false, 25 | "open_in_tab": true 26 | }, 27 | "action": { 28 | "default_popup": "popup/popup.html" 29 | }, 30 | "commands": { 31 | "_execute_action": { 32 | "description": "Open the extension" 33 | }, 34 | "copy-ticket-id": { 35 | "description": "Copy ticket ID to clipboard" 36 | }, 37 | "copy-ticket-id-md": { 38 | "description": "Copy ticket ID to clipboard in markdown" 39 | } 40 | }, 41 | "permissions": ["activeTab", "storage", "clipboardWrite"], 42 | "host_permissions": ["https://*.zendesk.com/*"] 43 | } 44 | -------------------------------------------------------------------------------- /src/manifest-firefox.json: -------------------------------------------------------------------------------- 1 | { 2 | "manifest_version": 3, 3 | "name": "Zendesk Link Collector", 4 | "version": "1.4.0", 5 | "description": "Summarize links and attachments", 6 | "background": { 7 | "scripts": ["lib/browser-polyfill.min.js", "background/background.js"] 8 | }, 9 | "content_scripts": [ 10 | { 11 | "matches": ["https://*.zendesk.com/*"], 12 | "run_at": "document_start", 13 | "js": ["lib/browser-polyfill.min.js", "content-scripts/contentscript.js"] 14 | } 15 | ], 16 | "icons": { 17 | "128": "icons/zlc-icon-128x128.png", 18 | "48": "icons/zlc-icon-48x48.png", 19 | "32": "icons/zlc-icon-32x32.png", 20 | "16": "icons/zlc-icon-16x16.png" 21 | }, 22 | "options_ui": { 23 | "page": "options/options.html", 24 | "browser_style": false, 25 | "open_in_tab": true 26 | }, 27 | "action": { 28 | "default_popup": "popup/popup.html" 29 | }, 30 | "commands": { 31 | "_execute_action": { 32 | "description": "Open the extension" 33 | }, 34 | "copy-ticket-id": { 35 | "description": "Copy ticket ID to clipboard" 36 | }, 37 | "copy-ticket-id-md": { 38 | "description": "Copy ticket ID to clipboard in markdown" 39 | } 40 | }, 41 | "permissions": ["activeTab", "storage", "clipboardWrite"], 42 | "host_permissions": ["https://*.zendesk.com/*"], 43 | "browser_specific_settings": { 44 | "gecko": { 45 | "id": "{e4a90df4-3bc1-11ee-be56-0242ac120002}" 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/icons/gear.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/search.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/icons/copy.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | # Makefile 2 | 3 | # Directories 4 | SRC_DIR = src 5 | BUILD_DIR = build 6 | FIREFOX_BUILD_DIR = $(BUILD_DIR)/firefox 7 | CHROME_BUILD_DIR = $(BUILD_DIR)/chrome 8 | 9 | # Commands 10 | MKDIR_P = mkdir -p 11 | RM = rm -rf 12 | CP = cp -r 13 | MV = mv 14 | WE = web-ext 15 | 16 | .PHONY: all clean firefox chrome build lint 17 | 18 | # Build with web-ext 19 | all: prep-firefox prep-chrome build-firefox build-chrome 20 | build: all 21 | 22 | # Lint with web-ext 23 | lint: prep-firefox prep-chrome lint-firefox lint-chrome 24 | 25 | # Prep build directories for Firefox 26 | prep-firefox: 27 | $(MKDIR_P) $(FIREFOX_BUILD_DIR) 28 | $(CP) $(SRC_DIR)/* $(FIREFOX_BUILD_DIR) 29 | $(MV) $(FIREFOX_BUILD_DIR)/manifest-firefox.json $(FIREFOX_BUILD_DIR)/manifest.json 30 | $(RM) $(FIREFOX_BUILD_DIR)/manifest-chrome.json 31 | 32 | # Prep build directories for Chrome 33 | prep-chrome: 34 | $(MKDIR_P) $(CHROME_BUILD_DIR) 35 | $(CP) $(SRC_DIR)/* $(CHROME_BUILD_DIR) 36 | $(MV) $(CHROME_BUILD_DIR)/manifest-chrome.json $(CHROME_BUILD_DIR)/manifest.json 37 | $(RM) $(CHROME_BUILD_DIR)/manifest-firefox.json 38 | 39 | # Build for Firefox with web-ext 40 | build-firefox: 41 | $(WE) build --source-dir=$(FIREFOX_BUILD_DIR) --artifacts-dir=$(FIREFOX_BUILD_DIR)/artifacts 42 | 43 | # Build for Chrome with web-ext 44 | build-chrome: 45 | $(WE) build --source-dir=$(CHROME_BUILD_DIR) --artifacts-dir=$(CHROME_BUILD_DIR)/artifacts 46 | 47 | # Lint for Firefox with web-ext 48 | lint-firefox: 49 | $(WE) lint --source-dir=$(FIREFOX_BUILD_DIR) 50 | 51 | # Lint for Chrome with web-ext (will produce warnings) 52 | lint-chrome: 53 | $(WE) lint --source-dir=$(CHROME_BUILD_DIR) 54 | 55 | clean: 56 | $(RM) $(BUILD_DIR) -------------------------------------------------------------------------------- /PRIVACY.md: -------------------------------------------------------------------------------- 1 | # Privacy Policy 2 | 3 | # Information We Collect 4 | No information is transmitted off of your devices or sent back to any server. 5 | 6 | This extension reads data on `https://*.zendesk.com/*` sites you are visiting, sends requests to those sites on behalf of you, and stores the results of those requests in storage and memory for the purpose of displaying that information in the extension UI in a formatted way. 7 | 8 | Your settings, such as link RegEx and titles are collected from your input and stored in your browser storage. 9 | 10 | # How We Use Your Information 11 | The Zendesk URL and page data (ticket comments and metadata) are collected and stored only in memory and in local storage for the purpose of displaying the processed information in the extension UI. 12 | 13 | Each time a new Zendesk ticket is processed, the previous ticket data is cleared from storage. 14 | 15 | On applicable browsers, settings are synced between devices according to your browser's capability. If you have browser sync disabled in your browser, this extensions settings are stored locally instead. Ticket data is never synced between devices. 16 | 17 | Absolutely no data is transmitted off of your devices or sent back to any server. 18 | 19 | # Security of Your Information 20 | Your data does not leave your browsers beyond that which is defined in the [Google Chrome sync](https://developer.chrome.com/docs/extensions/reference/storage/#property-sync) and [Firefox sync](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/sync) APIs. 21 | 22 | Every effort is made to ensure that your data is handled responsibly and in accordance with standard industry practices for browser extensions. 23 | 24 | # Contact Information 25 | If you have any questions about the Privacy Policy, please contact me. 26 | -------------------------------------------------------------------------------- /src/icons/check.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/options/options.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: sans-serif; 3 | color: rgb(201, 209, 217); 4 | background-color: rgb(22, 27, 34); 5 | color-scheme: dark; 6 | } 7 | 8 | /* Generic Input Styles */ 9 | button:hover, 10 | input[type="checkbox"]:enabled:hover, 11 | input[type="file"], 12 | input[type=file]::-webkit-file-upload-button, 13 | select { 14 | /* Found solution for "Choose File" button not applying styles here: 15 | https://stackoverflow.com/questions/1537223/change-cursor-type-on-input-type-file */ 16 | cursor: pointer; 17 | background-color: rgb(39, 44, 51); 18 | } 19 | 20 | button { 21 | border-radius: 4px; 22 | padding: 2px 12px; 23 | background-color: rgb(33, 38, 45); 24 | border-color: rgba(240, 246, 252, 0.1); 25 | color: rgb(201, 209, 217); 26 | } 27 | 28 | button:disabled { 29 | background-color: rgb(39, 44, 51); 30 | color: rgb(148 147 147); 31 | } 32 | 33 | button:disabled:hover { 34 | cursor: not-allowed; 35 | } 36 | 37 | .input-label { 38 | position: relative; 39 | } 40 | 41 | .input-label::after { 42 | content: "?"; 43 | position: absolute; 44 | top: -15px; 45 | left: -8px; 46 | width: 15px; 47 | height: 15px; 48 | border-radius: 50%; 49 | background-color: rgb(148 147 147); 50 | color: white; 51 | display: flex; 52 | justify-content: center; 53 | align-items: center; 54 | cursor: help; 55 | } 56 | 57 | .input-container-column { 58 | display: flex; 59 | flex-direction: column; 60 | } 61 | 62 | .input-container-row [type="text"] { 63 | width: 200px; 64 | } 65 | 66 | .input-container-row label { 67 | font-weight: bold; 68 | margin: 0 2px 0 15px; 69 | } 70 | 71 | .input-container-row label:first-child { 72 | margin-left: 0; 73 | } 74 | 75 | .input-container-row { 76 | margin-bottom: 15px; 77 | } 78 | 79 | .input-container-row { 80 | display: flex; 81 | flex-direction: row; 82 | align-items: center; 83 | } 84 | 85 | .input-container-row * { 86 | margin: 0 5px; 87 | } 88 | 89 | #link-patterns-error { 90 | background-color: rgb(179 0 0 / 18%); 91 | padding: 10px; 92 | border: 2px solid rgb(179 0 0 / 18%); 93 | } 94 | 95 | .hidden { 96 | display: none; 97 | } 98 | 99 | /* Table Styles */ 100 | table#table-link-patterns { 101 | border-collapse: collapse; 102 | } 103 | 104 | table#table-link-patterns td, table#table-link-patterns th { 105 | border: 1px solid rgb(201, 209, 217); 106 | text-align: center; 107 | } 108 | 109 | table#table-link-patterns td { 110 | padding: 5px 10px; 111 | } 112 | 113 | table#table-link-patterns th { 114 | font-size: 15px; 115 | background-color: rgb(32, 37, 45); 116 | padding: 10px; 117 | } 118 | 119 | table tr.editing { 120 | background-color: rgb(179 0 0 / 18%); 121 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Zendesk Link Collector 4 | 5 | This is a browser extension that collects links from a Zendesk ticket according to custom Regular Expression (regex) values. This tool's purpose is to help Zendesk users more easily handle _long_ tickets where links and/or attachments are key information. 6 | 7 | ## Installation 8 | This extension can be installed from the [Firefox addons store](https://addons.mozilla.org/en-CA/firefox/addon/zendesk-link-collector/) or the [Chrome web store](https://chrome.google.com/webstore/detail/zendesk-link-collector/nckhapficnbbmcpapjnnegpagfcbjpja). 9 | 10 | [![Chrome Web Store Version](https://img.shields.io/chrome-web-store/v/nckhapficnbbmcpapjnnegpagfcbjpja?logo=Google%20Chrome)](https://chrome.google.com/webstore/detail/zendesk-link-collector/nckhapficnbbmcpapjnnegpagfcbjpja) [![Mozilla Add-on Version](https://img.shields.io/amo/v/zendesk-link-collector?logo=Firefox)](https://addons.mozilla.org/en-CA/firefox/addon/zendesk-link-collector/) 11 | 12 | You can also manually [install it from the source code](#chrome-manual-installation). 13 | 14 | ## Configuration 15 | Access the configuration page to set link regex patterns you would like to aggregate from tickets. 16 | 17 | Some default link patterns will be available when you install the extension. You can also download [a sample JSON file containing the default patterns](./samples/link-patterns.json) to import from the configuration page. 18 | 19 | ### Google Chrome and Firefox 20 | 21 | Click the ⚙️ icon in the top-right corner of the extension popup to open the configuration page. 22 | 23 | ![options-button](samples/options-button-sample.png) 24 | 25 | ## Features 26 | 27 | ### Link Aggregation 28 | - Links are aggregated according to custom regex patterns. 29 | - No other chaos from the ticket is included in the link, only actual links are considered (`a` anchor elements). 30 | - Links can optionally display "context" when the "Show context?" checkbox option selected. This shows the surrounding text beside the link (the context is the parent HTML element of the `a` element). 31 | - Scroll to a link's source comment by clicking the spyglass icon (🔍) beside a link. 32 | 33 | ![image](samples/links-sample.png) 34 | 35 | 36 | ### Attachment Aggregation 37 | - Attachments are aggregated. 38 | - Scroll to an attachment's source comment by clicking the spyglass icon beside a link. 39 | 40 | ![image](samples/attachments-sample.png) 41 | 42 | ### Chrome Manual Installation 43 | 1. Clone the repository or download and extract the ZIP file to your local machine. 44 | 2. Open `chrome://extensions` in your Google Chrome browser. 45 | 3. Turn on `Developer mode` by clicking the toggle in the top-right corner. 46 | 4. Click on the `Load unpacked` button and select the `src` folder in the directory containing the extracted ZIP file. 47 | 48 | ## Project Strucutre 49 | 50 | The project is structured like a typical manifest v3 browser extension, with some slight differences. For example, we have separate browser-specific manifest files and a `makefile` to build for each target browser. 51 | 52 | Below is a diagram of the project using [`githubocto/repo-visualizer`](https://github.com/githubocto/repo-visualizer/). 53 | 54 | ![Visualization of the codebase](./diagram.svg) 55 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "main", "dev**" ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ "main", "dev**" ] 20 | schedule: 21 | - cron: '44 12 * * 1' 22 | workflow_dispatch: 23 | 24 | jobs: 25 | analyze: 26 | name: Analyze 27 | # Runner size impacts CodeQL analysis time. To learn more, please see: 28 | # - https://gh.io/recommended-hardware-resources-for-running-codeql 29 | # - https://gh.io/supported-runners-and-hardware-resources 30 | # - https://gh.io/using-larger-runners 31 | # Consider using larger runners for possible analysis time improvements. 32 | runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} 33 | timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} 34 | permissions: 35 | actions: read 36 | contents: read 37 | security-events: write 38 | 39 | strategy: 40 | fail-fast: false 41 | matrix: 42 | language: [ 'javascript' ] 43 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] 44 | # Use only 'java' to analyze code written in Java, Kotlin or both 45 | # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both 46 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 47 | 48 | steps: 49 | - name: Checkout repository 50 | uses: actions/checkout@v5 51 | 52 | # Initializes the CodeQL tools for scanning. 53 | - name: Initialize CodeQL 54 | uses: github/codeql-action/init@v4 55 | with: 56 | languages: ${{ matrix.language }} 57 | # If you wish to specify custom queries, you can do so here or in a config file. 58 | # By default, queries listed here will override any specified in a config file. 59 | # Prefix the list here with "+" to use these queries and those in the config file. 60 | 61 | # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 62 | queries: security-and-quality 63 | 64 | 65 | # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). 66 | # If this step fails, then you should remove it and run the build manually (see below) 67 | - name: Autobuild 68 | uses: github/codeql-action/autobuild@v4 69 | 70 | # ℹ️ Command-line programs to run using the OS shell. 71 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 72 | 73 | # If the Autobuild fails above, remove it and uncomment the following three lines. 74 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 75 | 76 | # - run: | 77 | # echo "Run, Build Application using script" 78 | # ./location_of_script_within_repo/buildscript.sh 79 | 80 | - name: Perform CodeQL Analysis 81 | uses: github/codeql-action/analyze@v4 82 | with: 83 | category: "/language:${{matrix.language}}" 84 | -------------------------------------------------------------------------------- /src/popup/popup.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | Links 11 | Attachments 12 | Images 13 | 14 | 15 | 16 |
17 | 33 |
34 | 35 | 36 | 37 | All Attachments 38 | 39 |
40 |
41 | 42 | 43 | 44 | All Images 45 | 46 |
47 |
48 |
49 | 56 |
57 | 61 |
62 |
63 | 67 |
68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/options/options.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Options Page 5 | 6 | 7 | 8 |

Options Page

9 |
10 |
11 | 12 | 13 |
14 |
15 | 16 | 17 | 18 | 19 |
20 |
21 |
22 | 23 |
24 | 69 |

Import/Export

70 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/content-scripts/contentscript.js: -------------------------------------------------------------------------------- 1 | console.log("Zendesk Link Collector - loaded content script"); 2 | 3 | // Message handler for messages from the background script. 4 | browser.runtime.onMessage.addListener(function (request, sender, sendResponse) { 5 | // Scroll to the comment. 6 | if (request.type == "scroll") { 7 | // This is async because it contains a fetch which we must wait for before sending a response. 8 | (async () => { 9 | const element = document.querySelector( 10 | `[data-comment-id="${request.commentID}"]` 11 | ) 12 | ? // Older Zendesk versions. 13 | document.querySelector(`[data-comment-id="${request.commentID}"]`) 14 | : // Newer Zendesk versions. 15 | document.querySelector(`[id="comment-${request.auditID}"]`); 16 | if (element) { 17 | element.scrollIntoView({ behavior: "smooth", block: "center" }); 18 | highlightComment(element); 19 | return; 20 | } 21 | // Last resort, sometimes zendesk does not add the data-comment-id or id attributes to the comments. 22 | // Get the comment from the audits endpoint, find the comment with the same HTML in the DOM and scroll to it. 23 | const url = new URL(document.URL); 24 | const urlArr = url.href.split("/"); 25 | const ticketID = urlArr[urlArr.length - 1]; 26 | 27 | const response = await fetch( 28 | `${url.protocol}//${url.hostname}/api/v2/tickets/${ticketID}/audits/${request.auditID}` 29 | ); 30 | const data = await response.json(); 31 | document.querySelectorAll(".zd-comment").forEach((comment) => { 32 | data.audit.events.forEach((event) => { 33 | if (event.type == "Comment") { 34 | if (comment.outerHTML == event.html_body) { 35 | comment.scrollIntoView({ behavior: "smooth", block: "center" }); 36 | highlightComment(comment); 37 | return; 38 | } 39 | } 40 | }); 41 | }); 42 | })(); 43 | } 44 | 45 | // Code from https://stackoverflow.com/questions/55214828/how-to-make-a-cross-origin-request-in-a-content-script-currently-blocked-by-cor/55215898#55215898 46 | if (request.type == "fetch") { 47 | fetch(request.input, request.init).then( 48 | function (response) { 49 | return response.text().then(function (text) { 50 | sendResponse([ 51 | { 52 | body: text, 53 | status: response.status, 54 | statusText: response.statusText, 55 | }, 56 | null, 57 | ]); 58 | }); 59 | }, 60 | function (error) { 61 | sendResponse([null, error]); 62 | } 63 | ); 64 | } 65 | 66 | // Background script does not have a DOM, so when it needs to parse links from HTML, it sends this message. 67 | if (request.type == "parse-html-a") { 68 | const parser = new DOMParser(); 69 | const doc = parser.parseFromString(request.htmlText, "text/html"); 70 | const links = doc.querySelectorAll(`a`); 71 | const linksArr = []; 72 | links.forEach((link) => { 73 | linksArr.push({ 74 | parent_text: link.parentElement.innerHTML, 75 | text: link.innerText, 76 | href: link.href, 77 | }); 78 | }); 79 | sendResponse(linksArr); 80 | } 81 | 82 | // Try to open zendesk preview. 83 | if (request.type == "image-preview") { 84 | const imageURL = request.imageURL; 85 | document.querySelectorAll("a").forEach((a) => { 86 | if (a.href == imageURL) { 87 | //Close any modal that are open. 88 | const closeButton = document.querySelector( 89 | '[data-garden-id="modals.close"]' 90 | ); 91 | if (closeButton) { 92 | closeButton.click(); 93 | } 94 | if (a) { 95 | a.click(); 96 | } 97 | } 98 | }); 99 | } 100 | 101 | // Copying to clipboard not possible 102 | if (request.type == "copy-not-possible") { 103 | navigator.clipboard.writeText("ZLC - Background processing disabled."); 104 | } 105 | 106 | // Copy ticket ID to clipboard. 107 | if (request.type == "copy-ticket-id") { 108 | browser.storage.local.get("ticketStorage").then((data) => { 109 | if ( 110 | data.ticketStorage == undefined || 111 | data.ticketStorage.ticketID == undefined 112 | ) { 113 | return; 114 | } 115 | navigator.clipboard.writeText(data.ticketStorage.ticketID); 116 | }); 117 | } 118 | 119 | // Copy ticket ID to clipboard in markdown. 120 | if (request.type == "copy-ticket-id-md") { 121 | browser.storage.local.get("ticketStorage").then((data) => { 122 | if ( 123 | data.ticketStorage == undefined || 124 | data.ticketStorage.ticketID == undefined 125 | ) { 126 | return; 127 | } 128 | navigator.clipboard.writeText( 129 | `[ZD#${data.ticketStorage.ticketID}](${document.URL})` 130 | ); 131 | }); 132 | } 133 | 134 | return true; 135 | }); 136 | 137 | function highlightComment(element) { 138 | let highlightElement = element; 139 | let counter = 0; 140 | const maxCounter = 20; 141 | // Traverse up the DOM tree until an 'article' element is found or counter reaches 10 142 | while ( 143 | highlightElement && 144 | highlightElement.nodeName.toLowerCase() !== "article" && 145 | counter < maxCounter 146 | ) { 147 | highlightElement = highlightElement.parentElement; 148 | counter++; 149 | } 150 | 151 | // If an 'article' element is found or the nth parent is reached, highlight whatever the element is. 152 | if (highlightElement) { 153 | const originalColor = highlightElement.style.backgroundColor; 154 | 155 | highlightElement.style.transition = "background-color 0.5s ease"; 156 | highlightElement.style.backgroundColor = "#ffff99"; 157 | setTimeout(() => { 158 | // Set the background color back to its original color to start the fade-out transition 159 | highlightElement.style.backgroundColor = originalColor; 160 | }, 2000); 161 | 162 | // After the transition is complete, remove the style attribute 163 | setTimeout(() => { 164 | highlightElement.removeAttribute("style"); 165 | }, 2500); // Ensure the style attribute is removed after the transition is complete. 166 | // This is very important to ensure the HTML of this element stays the same as what is returned by the audits endpoint. 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /samples/sample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | Links 9 | Attachments 10 | 11 |
12 |
13 |
14 | 73 |
74 | 78 | 110 |
111 | 112 | 113 |
114 | 115 | -------------------------------------------------------------------------------- /src/popup/popup.css: -------------------------------------------------------------------------------- 1 | /* Variables */ 2 | :root { 3 | --accent: rgb(33 90 48); 4 | --accent-hover: rgb(43 100 58); 5 | --accent-dark: rgb(22 80 38); 6 | --accent-dark-hover: rgb(33 90 48); 7 | --accent-light: rgb(98, 163, 75); 8 | 9 | --primary-bg: rgb(22, 27, 34); 10 | --primary-bg-light: rgb(33, 38, 45); 11 | --primary-bg-light-active: rgb(42, 47, 54); 12 | --secondary: rgb(73, 78, 85); 13 | } 14 | 15 | * { 16 | margin: 0; 17 | padding: 0; 18 | box-sizing: border-box; 19 | accent-color: var(--accent-light); 20 | } 21 | 22 | 23 | /* Scrollbar Styles */ 24 | /* Firefox */ 25 | * { 26 | scrollbar-width: thin; 27 | scrollbar-color: var(--secondary) var(--primary-bg); 28 | } 29 | 30 | /* Chrome, Edge and Safari */ 31 | *::-webkit-scrollbar { 32 | height: 10px; 33 | width: 10px; 34 | } 35 | *::-webkit-scrollbar-track { 36 | border-radius: 0px; 37 | background-color: var(--primary-bg); 38 | } 39 | 40 | *::-webkit-scrollbar-track:hover { 41 | background-color: var(--primary-bg-light); 42 | } 43 | 44 | *::-webkit-scrollbar-track:active { 45 | background-color: var(--primary-bg-light-active); 46 | } 47 | 48 | *::-webkit-scrollbar-thumb { 49 | border-radius: 0px; 50 | background-color: var(--secondary); 51 | } 52 | 53 | *::-webkit-scrollbar-thumb:hover { 54 | background-color: var(--accent); 55 | } 56 | 57 | *::-webkit-scrollbar-thumb:active { 58 | background-color: var(--accent-light); 59 | } 60 | 61 | *::-webkit-scrollbar-corner { 62 | background-color: var(--primary-bg); 63 | } 64 | 65 | *::-webkit-scrollbar-corner:hover { 66 | background-color: var(--primary-bg-light); 67 | } 68 | 69 | 70 | body { 71 | width: fit-content; 72 | height: fit-content; 73 | border-radius: 0.5em; 74 | font-family: sans-serif; 75 | color: rgb(201, 209, 217); 76 | background-color: var(--primary-bg); 77 | text-decoration: none; 78 | } 79 | 80 | #container { 81 | flex-direction: column; 82 | overflow: auto; 83 | min-width: 450px; 84 | max-width: 800px; 85 | min-height: 150px; 86 | max-height: 500px; 87 | } 88 | 89 | a { 90 | color: rgb(47, 129, 247); 91 | text-decoration: none; 92 | } 93 | 94 | a:hover { 95 | text-decoration: underline; 96 | } 97 | 98 | .button-fill.checked { 99 | background-color: var(--accent); 100 | border-color: var(--accent-dark); 101 | } 102 | 103 | .button-fill.checked:hover { 104 | background-color: var(--accent-hover); 105 | border-color: var(--accent-dark-hover); 106 | } 107 | 108 | .button { 109 | padding: 10px; 110 | font-size: 14px; 111 | text-align: center; 112 | background-color: var(--primary-bg-light); 113 | border-color: var(--secondary); 114 | border-width: 2px; 115 | border-style: solid; 116 | text-decoration: none; 117 | color: rgb(201, 209, 217); 118 | } 119 | 120 | /* This class is un-set by JavaScript */ 121 | .icon-button.hidden { 122 | display: none; 123 | transition: opacity 0.3s ease-in-out; 124 | } 125 | 126 | .icon-button { 127 | opacity: 1; 128 | transition: opacity 0.3s ease-in-out; 129 | } 130 | 131 | .icon-invert { 132 | filter: invert(1); 133 | } 134 | 135 | .button-fill { 136 | flex: 1; 137 | } 138 | 139 | .button-sub { 140 | display: flex; 141 | justify-content: flex-start; 142 | column-gap: 10px; 143 | padding: 0.5em; 144 | font-size: 1em; 145 | border-width: 1px; 146 | } 147 | 148 | .button-sub label:hover, .button-sub input:hover { 149 | cursor: pointer; 150 | } 151 | 152 | .button:hover { 153 | background-color: var(--primary-bg-light-active); 154 | cursor: pointer; 155 | } 156 | 157 | #button-whats-new { 158 | margin-left: auto; 159 | } 160 | 161 | .row { 162 | display: flex; 163 | flex-direction: row; 164 | width: 100%; 165 | } 166 | 167 | .row-sub { 168 | display: none; 169 | } 170 | 171 | /* .row-links { 172 | display: none; 173 | } */ 174 | 175 | .row-sub.selected { 176 | display: flex; 177 | } 178 | 179 | #button-options { 180 | flex-grow: 0; 181 | } 182 | 183 | #button-options img { 184 | vertical-align: middle; 185 | } 186 | 187 | /* Loader Styles */ 188 | #loader { 189 | display: none; 190 | } 191 | 192 | #loader.loading { 193 | display: block; 194 | position: fixed; 195 | top: 5%; 196 | width: 100%; 197 | height: 100%; 198 | background-image: url(../icons/loader.svg); 199 | background-repeat: no-repeat; 200 | background-position: center; 201 | background-size: 40px; 202 | animation: spin 2s linear infinite; 203 | } 204 | 205 | @keyframes spin { 206 | 0% { transform: rotate(0deg); } 207 | 100% { transform: rotate(360deg); } 208 | } 209 | 210 | /* List Styles */ 211 | h3.list-header { 212 | margin-top: 15px; 213 | margin-bottom: 3px; 214 | } 215 | 216 | .list-item-links[data-source="custom field"]::before { 217 | content: ""; 218 | position: relative; 219 | margin-right: 5px; 220 | width: 10px; 221 | height: 10px; 222 | border-radius: 50%; 223 | background-color: rgb(124 11 11); 224 | display: flex; 225 | justify-content: center; 226 | align-items: center; 227 | cursor: help; 228 | } 229 | 230 | /* Remove unused space between headers and the view buttons */ 231 | #list-container-links h3:first-of-type, #list-container-attachments #list-container-images ul:first-of-type { 232 | margin-top: 0; 233 | } 234 | 235 | ul.list-links, ul.list-attachments, li.list-item-images { 236 | display: flex; 237 | flex-direction: column; 238 | } 239 | 240 | li.list-item-links, li.list-item-attachments, li.list-item-images { 241 | list-style: none; 242 | margin-bottom: 2px; 243 | } 244 | 245 | li.list-item-images { 246 | margin-bottom: 30px; 247 | } 248 | 249 | li.list-item-images i { 250 | margin-bottom: 7px; 251 | } 252 | 253 | li.list-item-links { 254 | display: flex; 255 | flex-direction: row; 256 | } 257 | 258 | /* Force context to shrink first before shrinking the link text. */ 259 | /* li.list-item-links .link-context { 260 | flex-shrink: 0; 261 | flex-grow: 1; 262 | flex-basis: 0px; 263 | min-width: 0px; 264 | } */ 265 | 266 | li .link-date { 267 | color: var(--accent-light); 268 | font-size: 0.80em; 269 | display: flex; 270 | align-items: center; /* This will align the item vertically */ 271 | } 272 | 273 | li .link-date:hover { 274 | cursor: pointer; 275 | font-size: 1em; 276 | text-decoration: underline; 277 | } 278 | 279 | li.list-item-attachments ul li { 280 | margin-left: 10px; 281 | list-style: circle; 282 | list-style-position: inside; 283 | } 284 | 285 | .list-container { 286 | display: none; 287 | flex-direction: column; 288 | padding: 20px; 289 | white-space: nowrap; 290 | height: inherit; 291 | } 292 | 293 | /* This class is an option and is set on nodes by JavaScript. */ 294 | .list-container.wrap { 295 | white-space: normal; 296 | } 297 | 298 | /* This class is set by JavaScript in response to user clicking different views. */ 299 | .list-container.selected { 300 | display: flex; 301 | } 302 | 303 | /* 404 styles */ 304 | .not-found-container { 305 | display: flex; 306 | flex-direction: column; 307 | align-items: center; 308 | row-gap: 5px; 309 | } 310 | 311 | /* This class is un-set by JavaScript */ 312 | .not-found-container.hidden { 313 | display: none; 314 | } 315 | 316 | /* Search/Scroll-to icon styles */ 317 | .icon-li:hover { 318 | cursor: pointer; 319 | } 320 | 321 | .icon-li:hover { 322 | filter: invert(96%) sepia(1%) saturate(4016%) hue-rotate(179deg) brightness(93%) contrast(82%); 323 | } 324 | 325 | .icon-li { 326 | background-repeat: no-repeat; 327 | filter: invert(1); 328 | display: inline-block; 329 | padding: 6px; 330 | margin-right: 4px; 331 | vertical-align: middle; 332 | } 333 | 334 | .icon-copy { 335 | background-image: url(../icons/copy.svg); 336 | } 337 | 338 | .icon-search { 339 | background-image: url(../icons/search.svg); 340 | } 341 | 342 | .button-images.checked { 343 | background-color: var(--accent); 344 | border-color: var(--accent-dark); 345 | } 346 | 347 | .button-images.checked:hover { 348 | background-color: var(--accent-hover); 349 | border-color: var(--accent-dark-hover); 350 | } 351 | 352 | #list-container-images { 353 | display: none; 354 | flex-direction: column; 355 | padding: 20px; 356 | white-space: nowrap; 357 | } 358 | 359 | .list-item-images { 360 | margin-bottom: 30px; 361 | max-width: 750px; 362 | } 363 | 364 | .list-item-images img { 365 | max-width: 750px; 366 | } 367 | 368 | #list-container-images img:hover { 369 | cursor: zoom-in; 370 | } 371 | 372 | #list-container-images.selected { 373 | display: flex; 374 | } -------------------------------------------------------------------------------- /src/lib/browser-polyfill.min.js: -------------------------------------------------------------------------------- 1 | (function(a,b){if("function"==typeof define&&define.amd)define("webextension-polyfill",["module"],b);else if("undefined"!=typeof exports)b(module);else{var c={exports:{}};b(c),a.browser=c.exports}})("undefined"==typeof globalThis?"undefined"==typeof self?this:self:globalThis,function(a){"use strict";if(!globalThis.chrome?.runtime?.id)throw new Error("This script should only be loaded in a browser extension.");if("undefined"==typeof globalThis.browser||Object.getPrototypeOf(globalThis.browser)!==Object.prototype){a.exports=(a=>{const b={alarms:{clear:{minArgs:0,maxArgs:1},clearAll:{minArgs:0,maxArgs:0},get:{minArgs:0,maxArgs:1},getAll:{minArgs:0,maxArgs:0}},bookmarks:{create:{minArgs:1,maxArgs:1},get:{minArgs:1,maxArgs:1},getChildren:{minArgs:1,maxArgs:1},getRecent:{minArgs:1,maxArgs:1},getSubTree:{minArgs:1,maxArgs:1},getTree:{minArgs:0,maxArgs:0},move:{minArgs:2,maxArgs:2},remove:{minArgs:1,maxArgs:1},removeTree:{minArgs:1,maxArgs:1},search:{minArgs:1,maxArgs:1},update:{minArgs:2,maxArgs:2}},browserAction:{disable:{minArgs:0,maxArgs:1,fallbackToNoCallback:!0},enable:{minArgs:0,maxArgs:1,fallbackToNoCallback:!0},getBadgeBackgroundColor:{minArgs:1,maxArgs:1},getBadgeText:{minArgs:1,maxArgs:1},getPopup:{minArgs:1,maxArgs:1},getTitle:{minArgs:1,maxArgs:1},openPopup:{minArgs:0,maxArgs:0},setBadgeBackgroundColor:{minArgs:1,maxArgs:1,fallbackToNoCallback:!0},setBadgeText:{minArgs:1,maxArgs:1,fallbackToNoCallback:!0},setIcon:{minArgs:1,maxArgs:1},setPopup:{minArgs:1,maxArgs:1,fallbackToNoCallback:!0},setTitle:{minArgs:1,maxArgs:1,fallbackToNoCallback:!0}},browsingData:{remove:{minArgs:2,maxArgs:2},removeCache:{minArgs:1,maxArgs:1},removeCookies:{minArgs:1,maxArgs:1},removeDownloads:{minArgs:1,maxArgs:1},removeFormData:{minArgs:1,maxArgs:1},removeHistory:{minArgs:1,maxArgs:1},removeLocalStorage:{minArgs:1,maxArgs:1},removePasswords:{minArgs:1,maxArgs:1},removePluginData:{minArgs:1,maxArgs:1},settings:{minArgs:0,maxArgs:0}},commands:{getAll:{minArgs:0,maxArgs:0}},contextMenus:{remove:{minArgs:1,maxArgs:1},removeAll:{minArgs:0,maxArgs:0},update:{minArgs:2,maxArgs:2}},cookies:{get:{minArgs:1,maxArgs:1},getAll:{minArgs:1,maxArgs:1},getAllCookieStores:{minArgs:0,maxArgs:0},remove:{minArgs:1,maxArgs:1},set:{minArgs:1,maxArgs:1}},devtools:{inspectedWindow:{eval:{minArgs:1,maxArgs:2,singleCallbackArg:!1}},panels:{create:{minArgs:3,maxArgs:3,singleCallbackArg:!0},elements:{createSidebarPane:{minArgs:1,maxArgs:1}}}},downloads:{cancel:{minArgs:1,maxArgs:1},download:{minArgs:1,maxArgs:1},erase:{minArgs:1,maxArgs:1},getFileIcon:{minArgs:1,maxArgs:2},open:{minArgs:1,maxArgs:1,fallbackToNoCallback:!0},pause:{minArgs:1,maxArgs:1},removeFile:{minArgs:1,maxArgs:1},resume:{minArgs:1,maxArgs:1},search:{minArgs:1,maxArgs:1},show:{minArgs:1,maxArgs:1,fallbackToNoCallback:!0}},extension:{isAllowedFileSchemeAccess:{minArgs:0,maxArgs:0},isAllowedIncognitoAccess:{minArgs:0,maxArgs:0}},history:{addUrl:{minArgs:1,maxArgs:1},deleteAll:{minArgs:0,maxArgs:0},deleteRange:{minArgs:1,maxArgs:1},deleteUrl:{minArgs:1,maxArgs:1},getVisits:{minArgs:1,maxArgs:1},search:{minArgs:1,maxArgs:1}},i18n:{detectLanguage:{minArgs:1,maxArgs:1},getAcceptLanguages:{minArgs:0,maxArgs:0}},identity:{launchWebAuthFlow:{minArgs:1,maxArgs:1}},idle:{queryState:{minArgs:1,maxArgs:1}},management:{get:{minArgs:1,maxArgs:1},getAll:{minArgs:0,maxArgs:0},getSelf:{minArgs:0,maxArgs:0},setEnabled:{minArgs:2,maxArgs:2},uninstallSelf:{minArgs:0,maxArgs:1}},notifications:{clear:{minArgs:1,maxArgs:1},create:{minArgs:1,maxArgs:2},getAll:{minArgs:0,maxArgs:0},getPermissionLevel:{minArgs:0,maxArgs:0},update:{minArgs:2,maxArgs:2}},pageAction:{getPopup:{minArgs:1,maxArgs:1},getTitle:{minArgs:1,maxArgs:1},hide:{minArgs:1,maxArgs:1,fallbackToNoCallback:!0},setIcon:{minArgs:1,maxArgs:1},setPopup:{minArgs:1,maxArgs:1,fallbackToNoCallback:!0},setTitle:{minArgs:1,maxArgs:1,fallbackToNoCallback:!0},show:{minArgs:1,maxArgs:1,fallbackToNoCallback:!0}},permissions:{contains:{minArgs:1,maxArgs:1},getAll:{minArgs:0,maxArgs:0},remove:{minArgs:1,maxArgs:1},request:{minArgs:1,maxArgs:1}},runtime:{getBackgroundPage:{minArgs:0,maxArgs:0},getPlatformInfo:{minArgs:0,maxArgs:0},openOptionsPage:{minArgs:0,maxArgs:0},requestUpdateCheck:{minArgs:0,maxArgs:0},sendMessage:{minArgs:1,maxArgs:3},sendNativeMessage:{minArgs:2,maxArgs:2},setUninstallURL:{minArgs:1,maxArgs:1}},sessions:{getDevices:{minArgs:0,maxArgs:1},getRecentlyClosed:{minArgs:0,maxArgs:1},restore:{minArgs:0,maxArgs:1}},storage:{local:{clear:{minArgs:0,maxArgs:0},get:{minArgs:0,maxArgs:1},getBytesInUse:{minArgs:0,maxArgs:1},remove:{minArgs:1,maxArgs:1},set:{minArgs:1,maxArgs:1}},managed:{get:{minArgs:0,maxArgs:1},getBytesInUse:{minArgs:0,maxArgs:1}},sync:{clear:{minArgs:0,maxArgs:0},get:{minArgs:0,maxArgs:1},getBytesInUse:{minArgs:0,maxArgs:1},remove:{minArgs:1,maxArgs:1},set:{minArgs:1,maxArgs:1}}},tabs:{captureVisibleTab:{minArgs:0,maxArgs:2},create:{minArgs:1,maxArgs:1},detectLanguage:{minArgs:0,maxArgs:1},discard:{minArgs:0,maxArgs:1},duplicate:{minArgs:1,maxArgs:1},executeScript:{minArgs:1,maxArgs:2},get:{minArgs:1,maxArgs:1},getCurrent:{minArgs:0,maxArgs:0},getZoom:{minArgs:0,maxArgs:1},getZoomSettings:{minArgs:0,maxArgs:1},goBack:{minArgs:0,maxArgs:1},goForward:{minArgs:0,maxArgs:1},highlight:{minArgs:1,maxArgs:1},insertCSS:{minArgs:1,maxArgs:2},move:{minArgs:2,maxArgs:2},query:{minArgs:1,maxArgs:1},reload:{minArgs:0,maxArgs:2},remove:{minArgs:1,maxArgs:1},removeCSS:{minArgs:1,maxArgs:2},sendMessage:{minArgs:2,maxArgs:3},setZoom:{minArgs:1,maxArgs:2},setZoomSettings:{minArgs:1,maxArgs:2},update:{minArgs:1,maxArgs:2}},topSites:{get:{minArgs:0,maxArgs:0}},webNavigation:{getAllFrames:{minArgs:1,maxArgs:1},getFrame:{minArgs:1,maxArgs:1}},webRequest:{handlerBehaviorChanged:{minArgs:0,maxArgs:0}},windows:{create:{minArgs:0,maxArgs:1},get:{minArgs:1,maxArgs:2},getAll:{minArgs:0,maxArgs:1},getCurrent:{minArgs:0,maxArgs:1},getLastFocused:{minArgs:0,maxArgs:1},remove:{minArgs:1,maxArgs:1},update:{minArgs:2,maxArgs:2}}};if(0===Object.keys(b).length)throw new Error("api-metadata.json has not been included in browser-polyfill");class c extends WeakMap{constructor(a,b=void 0){super(b),this.createItem=a}get(a){return this.has(a)||this.set(a,this.createItem(a)),super.get(a)}}const d=a=>a&&"object"==typeof a&&"function"==typeof a.then,e=(b,c)=>(...d)=>{a.runtime.lastError?b.reject(new Error(a.runtime.lastError.message)):c.singleCallbackArg||1>=d.length&&!1!==c.singleCallbackArg?b.resolve(d[0]):b.resolve(d)},f=a=>1==a?"argument":"arguments",g=(a,b)=>function(c,...d){if(d.lengthb.maxArgs)throw new Error(`Expected at most ${b.maxArgs} ${f(b.maxArgs)} for ${a}(), got ${d.length}`);return new Promise((f,g)=>{if(b.fallbackToNoCallback)try{c[a](...d,e({resolve:f,reject:g},b))}catch(e){console.warn(`${a} API method doesn't seem to support the callback parameter, `+"falling back to call it without a callback: ",e),c[a](...d),b.fallbackToNoCallback=!1,b.noCallback=!0,f()}else b.noCallback?(c[a](...d),f()):c[a](...d,e({resolve:f,reject:g},b))})},h=(a,b,c)=>new Proxy(b,{apply(b,d,e){return c.call(d,a,...e)}});let i=Function.call.bind(Object.prototype.hasOwnProperty);const j=(a,b={},c={})=>{let d=Object.create(null),e=Object.create(a);return new Proxy(e,{has(b,c){return c in a||c in d},get(e,f){if(f in d)return d[f];if(!(f in a))return;let k=a[f];if("function"==typeof k){if("function"==typeof b[f])k=h(a,a[f],b[f]);else if(i(c,f)){let b=g(f,c[f]);k=h(a,a[f],b)}else k=k.bind(a);}else if("object"==typeof k&&null!==k&&(i(b,f)||i(c,f)))k=j(k,b[f],c[f]);else if(i(c,"*"))k=j(k,b[f],c["*"]);else return Object.defineProperty(d,f,{configurable:!0,enumerable:!0,get(){return a[f]},set(b){a[f]=b}}),k;return d[f]=k,k},set(b,c,e){return c in d?d[c]=e:a[c]=e,!0},defineProperty(a,b,c){return Reflect.defineProperty(d,b,c)},deleteProperty(a,b){return Reflect.deleteProperty(d,b)}})},k=a=>({addListener(b,c,...d){b.addListener(a.get(c),...d)},hasListener(b,c){return b.hasListener(a.get(c))},removeListener(b,c){b.removeListener(a.get(c))}}),l=new c(a=>"function"==typeof a?function(b){const c=j(b,{},{getContent:{minArgs:0,maxArgs:0}});a(c)}:a),m=new c(a=>"function"==typeof a?function(b,c,e){let f,g,h=!1,i=new Promise(a=>{f=function(b){h=!0,a(b)}});try{g=a(b,c,f)}catch(a){g=Promise.reject(a)}const j=!0!==g&&d(g);if(!0!==g&&!j&&!h)return!1;const k=a=>{a.then(a=>{e(a)},a=>{let b;b=a&&(a instanceof Error||"string"==typeof a.message)?a.message:"An unexpected error occurred",e({__mozWebExtensionPolyfillReject__:!0,message:b})}).catch(a=>{console.error("Failed to send onMessage rejected reply",a)})};return j?k(g):k(i),!0}:a),n=({reject:b,resolve:c},d)=>{a.runtime.lastError?a.runtime.lastError.message==="The message port closed before a response was received."?c():b(new Error(a.runtime.lastError.message)):d&&d.__mozWebExtensionPolyfillReject__?b(new Error(d.message)):c(d)},o=(a,b,c,...d)=>{if(d.lengthb.maxArgs)throw new Error(`Expected at most ${b.maxArgs} ${f(b.maxArgs)} for ${a}(), got ${d.length}`);return new Promise((a,b)=>{const e=n.bind(null,{resolve:a,reject:b});d.push(e),c.sendMessage(...d)})},p={devtools:{network:{onRequestFinished:k(l)}},runtime:{onMessage:k(m),onMessageExternal:k(m),sendMessage:o.bind(null,"sendMessage",{minArgs:1,maxArgs:3})},tabs:{sendMessage:o.bind(null,"sendMessage",{minArgs:2,maxArgs:3})}},q={clear:{minArgs:1,maxArgs:1},get:{minArgs:1,maxArgs:1},set:{minArgs:1,maxArgs:1}};return b.privacy={network:{"*":q},services:{"*":q},websites:{"*":q}},j(a,p,b)})(chrome)}else a.exports=globalThis.browser}); 2 | //# sourceMappingURL=browser-polyfill.min.js.map 3 | 4 | // webextension-polyfill v.0.10.0 (https://github.com/mozilla/webextension-polyfill) 5 | 6 | /* This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 9 | -------------------------------------------------------------------------------- /src/options/options.js: -------------------------------------------------------------------------------- 1 | // LATER: 2 | // - Edit? 3 | 4 | // Load link patterns into the link patterns table. 5 | function loadLinkPatterns() { 6 | const linkTable = document.getElementById("table-link-patterns").tBodies[0]; 7 | linkTable.innerHTML = ""; 8 | browser.storage.sync.get("options").then((data) => { 9 | if (data.options == undefined || data.options.length <= 0) { 10 | data.options = []; 11 | } 12 | data.options.forEach((option) => { 13 | // Create table row. 14 | const tr = document.createElement("tr"); 15 | tr.id = option.id; 16 | 17 | // Initialize node types. 18 | const nodes = []; 19 | 20 | // Create table cells. 21 | // Create title cell. 22 | const tdTitle = document.createElement("td"); 23 | const strong = document.createElement("strong"); 24 | strong.textContent = option.title; 25 | tdTitle.appendChild(strong); 26 | nodes.push(tdTitle); 27 | 28 | // Create pattern cell. 29 | const tdPattern = document.createElement("td"); 30 | const pre = document.createElement("pre"); 31 | pre.textContent = option.pattern; 32 | tdPattern.appendChild(pre); 33 | nodes.push(tdPattern); 34 | 35 | // Create show parent cell. 36 | const tdContext = document.createElement("td"); 37 | const checkboxContext = document.createElement("input"); 38 | checkboxContext.setAttribute("type", "checkbox"); 39 | checkboxContext.setAttribute("disabled", "true"); 40 | checkboxContext.checked = option.showParent; 41 | tdContext.appendChild(checkboxContext); 42 | nodes.push(tdContext); 43 | 44 | // Create summary type cell. 45 | const tdSummaryType = document.createElement("td"); 46 | if (option.summaryType == "all") { 47 | tdSummaryType.textContent = "All"; 48 | } else if (option.summaryType == "latest") { 49 | tdSummaryType.textContent = "Latest"; 50 | } else if (option.summaryType == "none") { 51 | tdSummaryType.textContent = "None"; 52 | } else if (option.summaryType == undefined) { 53 | tdSummaryType.textContent = "All"; 54 | } else { 55 | tdSummaryType.textContent = `Unknown (${option.summaryType})`; 56 | } 57 | nodes.push(tdSummaryType); 58 | 59 | // Create show parent cell. 60 | const tdDate = document.createElement("td"); 61 | const checkboxDate = document.createElement("input"); 62 | checkboxDate.setAttribute("type", "checkbox"); 63 | checkboxDate.setAttribute("disabled", "true"); 64 | checkboxDate.checked = option.showDate; 65 | tdDate.appendChild(checkboxDate); 66 | nodes.push(tdDate); 67 | 68 | // Create edit cell. 69 | const tdEdit = document.createElement("td"); 70 | const buttonEdit = document.createElement("button"); 71 | buttonEdit.textContent = "Edit"; 72 | buttonEdit.addEventListener("click", () => editLinkPattern(option.id)); 73 | tdEdit.appendChild(buttonEdit); 74 | nodes.push(tdEdit); 75 | 76 | // Create delete cell. 77 | const tdDelete = document.createElement("td"); 78 | const buttonDelete = document.createElement("button"); 79 | buttonDelete.setAttribute("class", "button-delete"); 80 | buttonDelete.textContent = "Delete"; 81 | tdDelete.appendChild(buttonDelete); 82 | nodes.push(tdDelete); 83 | 84 | // Create reorder cells. 85 | // Create up button. 86 | const tdReorder = document.createElement("td"); 87 | const buttonReorderUp = document.createElement("button"); 88 | buttonReorderUp.setAttribute("class", "button-reorder-up"); 89 | buttonReorderUp.textContent = "Up"; 90 | tdReorder.appendChild(buttonReorderUp); 91 | // Create down button. 92 | const buttonReorderDown = document.createElement("button"); 93 | buttonReorderDown.setAttribute("class", "button-reorder-down"); 94 | buttonReorderDown.textContent = "Down"; 95 | tdReorder.appendChild(buttonReorderDown); 96 | nodes.push(tdReorder); 97 | 98 | // Add cells to row. 99 | tr.append(...nodes); 100 | 101 | // Add row to table. 102 | linkTable.appendChild(tr); 103 | 104 | //Add event listeners to dynamic elements. 105 | document 106 | .querySelector(`[id = '${option.id}'] td button.button-delete`) 107 | .addEventListener("click", () => deleteLink(option.id)); 108 | document 109 | .querySelector(`[id = '${option.id}'] td button.button-reorder-up`) 110 | .addEventListener("click", () => reorderLinkPattern(option.id, -1)); 111 | document 112 | .querySelector(`[id = '${option.id}'] td button.button-reorder-down`) 113 | .addEventListener("click", () => reorderLinkPattern(option.id, 1)); 114 | }); 115 | }); 116 | } 117 | 118 | // Set the error message for the link patterns input. If err is empty, hide the error message. 119 | function setLinkPatternError(err) { 120 | document.getElementById("link-patterns-error").textContent = err; 121 | if (err != "" && err != undefined) { 122 | document.getElementById("link-patterns-error").classList.remove("hidden"); 123 | return; 124 | } 125 | document.getElementById("link-patterns-error").classList.add("hidden"); 126 | } 127 | 128 | // Save a new link pattern from user input values. 129 | function saveLinkPatterns() { 130 | if (document.getElementById("title").value == "") { 131 | setLinkPatternError("Missing required field: Title"); 132 | return; 133 | } 134 | if (document.getElementById("pattern").value == "") { 135 | setLinkPatternError("Missing required field: RegEx Pattern"); 136 | return; 137 | } 138 | 139 | // Get existing link options to append to. 140 | browser.storage.sync.get("options").then((data) => { 141 | // Hide previous error messages. 142 | setLinkPatternError(""); 143 | // Initialize options if none exist. 144 | if (data.options == undefined || data.options.length <= 0) { 145 | data.options = []; 146 | } 147 | // Validate RegEx. 148 | try { 149 | new RegExp(document.getElementById("pattern").value); 150 | } catch (SyntaxError) { 151 | setLinkPatternError( 152 | "Invalid RegEx pattern! - Great work! That's difficult to do! :D" 153 | ); 154 | console.error("Invalid RegEx"); 155 | return; 156 | } 157 | // Add new link pattern to data. 158 | data.options.push({ 159 | id: crypto.randomUUID(), 160 | title: document.getElementById("title").value, 161 | pattern: document.getElementById("pattern").value, 162 | showParent: document.getElementById("show-parent").checked, 163 | summaryType: document.getElementById("summary-type").value, 164 | showDate: document.getElementById("show-date").checked, 165 | }); 166 | // Save new link pattern to disk. 167 | browser.storage.sync.set({ options: data.options }).then(() => { 168 | // Load the new patterns table. 169 | loadLinkPatterns(); 170 | // Reset input fields. 171 | document.getElementById("title").value = ""; 172 | document.getElementById("pattern").value = ""; 173 | document.getElementById("show-parent").checked = false; 174 | document.getElementById("summary-type").value = "none"; 175 | document.getElementById("show-date").checked = false; 176 | }); 177 | }); 178 | } 179 | 180 | // Reorder link patterns in the link patterns table. 181 | // id = ID of the link pattern to move. 182 | // move = Number of positions to move the link pattern. Negative numbers move up, positive numbers move down. 183 | function reorderLinkPattern(id, move) { 184 | browser.storage.sync.get("options").then((data) => { 185 | if (data.options.length <= 0) { 186 | //Shouldn't happen? 187 | return; 188 | } 189 | if (move == 0 || move == undefined) { 190 | //No move. 191 | return; 192 | } 193 | let found = false; 194 | data.options.forEach((option) => { 195 | if (option.id == id && !found) { 196 | found = true; 197 | let pOptionIndex = data.options.indexOf(option) + move; 198 | if (pOptionIndex < 0 || pOptionIndex >= data.options.length) { 199 | //OOB array. 200 | console.error("OOB array"); 201 | return; 202 | } 203 | let option2Move = data.options.splice( 204 | data.options.indexOf(option), 205 | 1 206 | )[0]; 207 | data.options.splice(pOptionIndex, 0, option2Move); 208 | } 209 | }); 210 | 211 | browser.storage.sync.set({ options: data.options }).then(() => { 212 | loadLinkPatterns(); 213 | }); 214 | }); 215 | } 216 | 217 | // Delete a link pattern from the link patterns table. 218 | function deleteLink(id) { 219 | browser.storage.sync.get("options").then((data) => { 220 | if (data.options.length <= 0) { 221 | //Shouldn't happen? 222 | return; 223 | } 224 | data.options.forEach((option) => { 225 | if (option.id == id) { 226 | data.options.splice(data.options.indexOf(option), 1); 227 | } 228 | }); 229 | browser.storage.sync.set({ options: data.options }).then(() => { 230 | loadLinkPatterns(); 231 | }); 232 | }); 233 | } 234 | 235 | // Edit a link pattern from the link patterns table. 236 | function editLinkPattern(id) { 237 | // Disable all buttons except the one being edited. 238 | document 239 | .querySelectorAll("#table-link-patterns td button") 240 | .forEach((button) => { 241 | button.disabled = true; 242 | }); 243 | 244 | // Fill the input fields with the selected link pattern's current values. 245 | browser.storage.sync.get("options").then((data) => { 246 | const option = data.options.find((option) => option.id === id); 247 | if (option) { 248 | document.getElementById("title").value = option.title; 249 | document.getElementById("pattern").value = option.pattern; 250 | document.getElementById("show-parent").checked = option.showParent; 251 | document.getElementById("summary-type").value = 252 | option.summaryType || "none"; 253 | document.getElementById("show-date").checked = option.showDate || false; 254 | 255 | // Post a message that we are editing. 256 | setLinkPatternError( 257 | `You are editing the "${option.title}" link pattern!` 258 | ); 259 | 260 | document.getElementById(id).classList.add("editing"); 261 | 262 | // Change the Save button to an Update button. 263 | const saveButton = document.getElementById("button-save-link-patterns"); 264 | saveButton.textContent = "Update Link Pattern"; 265 | saveButton.removeEventListener("click", saveLinkPatterns); 266 | saveButton.setAttribute("editing", id); 267 | saveButton.onclick = updateLinkPattern; 268 | } 269 | }); 270 | } 271 | 272 | // Update an existing link pattern with the values from the input fields. 273 | function updateLinkPattern() { 274 | const id = document 275 | .getElementById("button-save-link-patterns") 276 | .getAttribute("editing"); 277 | browser.storage.sync.get("options").then((data) => { 278 | const optionIndex = data.options.findIndex((option) => option.id === id); 279 | if (optionIndex !== -1) { 280 | // Validate RegEx. 281 | try { 282 | new RegExp(document.getElementById("pattern").value); 283 | } catch (SyntaxError) { 284 | setLinkPatternError( 285 | "Invalid RegEx pattern! - Great work! That's difficult to do! :D" 286 | ); 287 | console.error("Invalid RegEx"); 288 | return; 289 | } 290 | 291 | // Update the link pattern with the new values. 292 | data.options[optionIndex].title = document.getElementById("title").value; 293 | data.options[optionIndex].pattern = 294 | document.getElementById("pattern").value; 295 | data.options[optionIndex].showParent = 296 | document.getElementById("show-parent").checked; 297 | data.options[optionIndex].summaryType = 298 | document.getElementById("summary-type").value; 299 | data.options[optionIndex].showDate = 300 | document.getElementById("show-date").checked; 301 | 302 | // Save the updated link patterns to storage. 303 | browser.storage.sync.set({ options: data.options }).then(() => { 304 | // Load the updated patterns table. 305 | loadLinkPatterns(); 306 | 307 | // Reset input fields. 308 | document.getElementById("title").value = ""; 309 | document.getElementById("pattern").value = ""; 310 | document.getElementById("show-parent").checked = false; 311 | document.getElementById("summary-type").value = "none"; 312 | document.getElementById("show-date").checked = false; 313 | 314 | // Change the Update button back to a Save button. 315 | const saveButton = document.getElementById("button-save-link-patterns"); 316 | saveButton.textContent = "Save Link Pattern"; 317 | saveButton.removeEventListener("click", updateLinkPattern); 318 | saveButton.addEventListener("click", saveLinkPatterns); 319 | 320 | //Clear the message that we are editing. 321 | setLinkPatternError(""); 322 | 323 | //saveButton.onclick = saveLinkPatterns; 324 | 325 | // Re-enable all edit buttons. 326 | /* document 327 | .querySelectorAll("#table-link-patterns td button") 328 | .forEach((button) => { 329 | if (button.textContent === "Edit") { 330 | button.disabled = false; 331 | } 332 | }); */ 333 | }); 334 | } 335 | }); 336 | } 337 | 338 | // Export/Download link patterns as JSON. 339 | function downloadLinkPatternsJSON() { 340 | browser.storage.sync.get("options").then((data) => { 341 | if (data.options == undefined || data.options.length <= 0) { 342 | return; 343 | } 344 | const blob = new Blob([JSON.stringify(data.options)], { 345 | type: "application/json", 346 | }); 347 | const url = URL.createObjectURL(blob); 348 | const link = document.createElement("a"); 349 | link.href = url; 350 | link.download = "link-patterns.json"; 351 | link.click(); 352 | URL.revokeObjectURL(url); 353 | }); 354 | } 355 | 356 | // Import link patterns from JSON. 357 | function importLinkPatternsJSON() { 358 | const inputElement = document.getElementById("link-patterns-import-file"); 359 | const file = inputElement.files[0]; 360 | const fileReader = new FileReader(); 361 | 362 | // Clear input. 363 | document.getElementById("link-patterns-import-file").value = ""; 364 | 365 | fileReader.readAsText(file, "UTF-8"); 366 | fileReader.onload = function () { 367 | const fileContent = fileReader.result; 368 | const newOptions = JSON.parse(fileContent); 369 | const overwrite = 370 | document.getElementById("link-patterns-import-type").value == "overwrite" 371 | ? true 372 | : false; 373 | // Validate the JSON data. 374 | 375 | newOptions.forEach((option) => { 376 | // Check for missing fields. 377 | if ( 378 | option.id == undefined || 379 | option.title == undefined || 380 | option.pattern == undefined || 381 | option.showParent == undefined 382 | ) { 383 | console.error("Invalid JSON data (missing fields)"); 384 | return; 385 | } 386 | // Set default summary type if not found. 387 | if (option.summaryType == undefined) { 388 | option.summaryType = "all"; 389 | } 390 | // Always set new ID to avoid duplicates. 391 | option.id = crypto.randomUUID(); 392 | // Validate RegEx. 393 | try { 394 | new RegExp(option.pattern); 395 | } catch (SyntaxError) { 396 | console.error("Invalid JSON data (bad pattern)"); 397 | return; 398 | } 399 | }); 400 | 401 | // Add to existing data. 402 | if (!overwrite) { 403 | browser.storage.sync.get("options").then((data) => { 404 | if (data.options == undefined || data.options.length <= 0) { 405 | data.options = []; 406 | } 407 | data.options.push(...newOptions); 408 | browser.storage.sync.set({ options: data.options }).then(() => { 409 | loadLinkPatterns(); 410 | }); 411 | }); 412 | return; 413 | } 414 | 415 | browser.storage.sync.set({ options: newOptions }).then(() => { 416 | loadLinkPatterns(); 417 | }); 418 | }; 419 | 420 | fileReader.onerror = function () { 421 | console.error("Unable to read file"); 422 | }; 423 | } 424 | 425 | // Save the global extension options from user inputs. 426 | function saveGlobalOptions() { 427 | browser.storage.sync.get("optionsGlobal").then((data) => { 428 | if (data.optionsGlobal == undefined) { 429 | data.optionsGlobal = { 430 | wrapLists: false, 431 | includeAttachments: false, 432 | includeImages: false, 433 | }; 434 | } 435 | 436 | data.optionsGlobal.wrapLists = 437 | document.getElementById("wrap-lists").checked; 438 | data.optionsGlobal.includeAttachments = document.getElementById( 439 | "include-attachments" 440 | ).checked; 441 | data.optionsGlobal.includeImages = 442 | document.getElementById("include-images").checked; 443 | 444 | browser.storage.sync.set({ 445 | optionsGlobal: data.optionsGlobal, 446 | }); 447 | }); 448 | } 449 | 450 | // Load the global extension options into the list of global options. 451 | function loadGlobalOptions() { 452 | browser.storage.sync.get("optionsGlobal").then((data) => { 453 | if (data.optionsGlobal == undefined) { 454 | data.optionsGlobal = { 455 | wrapLists: false, 456 | includeAttachments: false, 457 | includeImages: false, 458 | }; 459 | } 460 | document.getElementById("wrap-lists").checked = 461 | data.optionsGlobal.wrapLists; 462 | document.getElementById("include-attachments").checked = 463 | data.optionsGlobal.includeAttachments; 464 | document.getElementById("include-images").checked = 465 | data.optionsGlobal.includeImages; 466 | }); 467 | } 468 | 469 | document.addEventListener("DOMContentLoaded", () => { 470 | // Add event listeners to static elements. 471 | // Global options event listeners. 472 | document 473 | .getElementById("button-save-global-options") 474 | .addEventListener("click", saveGlobalOptions); 475 | loadGlobalOptions(); 476 | 477 | // Link patterns event listeners. 478 | document 479 | .getElementById("button-save-link-patterns") 480 | .addEventListener("click", saveLinkPatterns); 481 | document 482 | .getElementById("link-patterns-import") 483 | .addEventListener("click", importLinkPatternsJSON); 484 | document 485 | .getElementById("link-patterns-export") 486 | .addEventListener("click", downloadLinkPatternsJSON); 487 | loadLinkPatterns(); 488 | }); 489 | -------------------------------------------------------------------------------- /src/background/background.js: -------------------------------------------------------------------------------- 1 | // "importScripts" is only supported in chrome. Firefox loads the polyfill from the manifest.json file. 2 | if (typeof importScripts === "function") { 3 | importScripts("../lib/browser-polyfill.min.js"); 4 | } 5 | 6 | // Sends a message to the content script to execute a fetch. 7 | // Code from https://stackoverflow.com/questions/55214828/how-to-make-a-cross-origin-request-in-a-content-script-currently-blocked-by-cor/55215898#55215898 8 | async function fetchResource(input, init) { 9 | const type = "fetch"; 10 | return new Promise((resolve, reject) => { 11 | browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { 12 | browser.tabs 13 | .sendMessage(tabs[0].id, { type, input, init }) 14 | .then((messageResponse) => { 15 | const [response, error] = messageResponse; 16 | if (response === null) { 17 | reject(error); 18 | } else { 19 | // Use undefined on a 204 - No Content 20 | const body = response.body ? new Blob([response.body]) : undefined; 21 | resolve( 22 | new Response(body, { 23 | status: response.status, 24 | statusText: response.statusText, 25 | }) 26 | ); 27 | } 28 | }); 29 | }); 30 | }); 31 | } 32 | 33 | // Parse the HTML text and return an array of links. 34 | async function parseAElementsFromHTMLText(htmlText) { 35 | const type = "parse-html-a"; 36 | const [tab] = await chrome.tabs.query({ 37 | active: true, 38 | lastFocusedWindow: true, 39 | }); 40 | const response = await chrome.tabs.sendMessage(tab.id, { 41 | type: type, 42 | htmlText: htmlText, 43 | }); 44 | return response; 45 | } 46 | 47 | // Fetch ticket data, fetch settings, process the ticket, then store the result. 48 | // This function is called when the extension is first loaded, when the ticket is changed, and when the settings are changed. 49 | // There are three sections of this function: 50 | // 1. Comment collecting loop section - collects all comments from the ticket. 51 | // 2. Custom field link collecting section - collects all links from custom fields. 52 | // 3. Link filtering section - filters the links based on the settings. 53 | async function filterTicket() { 54 | // Reset the ticketStorage to loading. 55 | await browser.storage.local.set({ 56 | ticketStorage: { 57 | links: [], 58 | attachments: [], 59 | images: [], 60 | state: "loading", 61 | }, 62 | }); 63 | 64 | // Get the current active tab. 65 | const queryOptions = { active: true, lastFocusedWindow: true }; 66 | const [tab] = await browser.tabs.query(queryOptions); 67 | 68 | // Get make a real URL from the text URL. 69 | const url = new URL(tab.url); 70 | 71 | // Get the ticket ID from the URL. 72 | const stringArr = url.href.split("/"); 73 | const ticketID = stringArr[stringArr.length - 1]; 74 | 75 | // Comment collecting loop section 76 | // ******************************* 77 | const rlimit = 25; // Max number of requests to make. 78 | const firstPage = `https://${url.hostname}/api/v2/tickets/${ticketID}/comments?sort_order=desc`; // URL of the first page of comments. 79 | let nextPage = firstPage; // URL of the next page of comments. 80 | let r = 1; // Number of requests made. 81 | 82 | let numComments = 0; // Number of comments received from Zendesk. 83 | const linksArr = []; // Array of link objects to be displayed. 84 | const attachmentsArr = []; // Array of attachment objects to be displayed. 85 | const imagesArr = []; // Array of image objects to be displayed. 86 | 87 | // Loop through all pages of comments until there are no more pages. 88 | while (nextPage != "" && r <= rlimit) { 89 | console.log(`Processing request #${r}`); 90 | 91 | // Get the next page of comments data. 92 | const response = await fetchResource(nextPage).catch((error) => { 93 | console.error("Request failed:", error); 94 | }); 95 | const commentData = await response.json(); 96 | if (commentData.next_page != null) { 97 | nextPage = commentData.next_page; 98 | } else { 99 | nextPage = ""; 100 | } 101 | 102 | // If this is the first request, get the number of comments. 103 | // (the number of comments doesn't change between requests) 104 | if (r == 1 && commentData.count > 0) { 105 | console.log(`Received ${commentData.count} comments`); 106 | numComments = commentData.count; 107 | } 108 | 109 | // Increment the request counter. 110 | r++; 111 | 112 | //Grab only the required fields from the JSON. 113 | await commentData.comments.forEach(async (comment) => { 114 | // Parse the HTML text and return an array of links. 115 | const links = await parseAElementsFromHTMLText(comment.html_body); 116 | // Push the required link information to the linksArr. 117 | if (links.length > 0) { 118 | links.forEach((link) => { 119 | linksArr.push({ 120 | commentID: comment.id, 121 | auditID: comment.audit_id, 122 | createdAt: comment.created_at, 123 | parent_text: link.parent_text, 124 | text: link.text, 125 | href: link.href, 126 | source: "comment", 127 | }); 128 | }); 129 | } 130 | 131 | // Push the required attachment information to the attachmentsArr. 132 | if (comment.attachments.length > 0) { 133 | const tempArr = []; 134 | comment.attachments.forEach((attachment) => { 135 | if (!attachment.content_type.startsWith("image/")) { 136 | tempArr.push(attachment); 137 | } 138 | }); 139 | if (tempArr.length > 0) { 140 | attachmentsArr.push({ 141 | commentID: comment.id, 142 | auditID: comment.audit_id, 143 | created_at: comment.created_at, 144 | attachments: tempArr, 145 | }); 146 | } 147 | } 148 | 149 | // Filter images out of attachments data and push to imagesArr 150 | comment.attachments.forEach((attachment) => { 151 | if (attachment.content_type.startsWith("image/")) { 152 | imagesArr.push({ 153 | commentID: comment.id, 154 | auditID: comment.audit_id, 155 | createdAt: comment.created_at, 156 | url: attachment.content_url, 157 | mappedURL: attachment.mapped_content_url, 158 | fileName: attachment.file_name, 159 | }); 160 | } 161 | }); 162 | }); 163 | } 164 | 165 | // Custom field link collecting section. 166 | // ************************************* 167 | const response = await fetchResource( 168 | `https://${url.hostname}/api/v2/tickets/${ticketID}` 169 | ).catch((error) => { 170 | console.error("Request failed:", error); 171 | }); 172 | const ticketData = await response.json(); 173 | const customFields = ticketData.ticket.custom_fields; 174 | 175 | // For each custom field, check if it is a string and if it contains a link. 176 | customFields.forEach((field) => { 177 | if (field.value != null && typeof field.value == "string") { 178 | field.value.split(/[\n\s]/g).forEach((valueArrItem) => { 179 | // If the value is a link, add it to the linksArr for filtering. 180 | if (valueArrItem.search(/^https?:\/\//i) >= 0) { 181 | console.log(`found link in custom field: ${valueArrItem}`); 182 | linksArr.push({ 183 | createdAt: null, 184 | text: valueArrItem, 185 | href: valueArrItem, 186 | source: "custom field", 187 | }); 188 | } 189 | }); 190 | } 191 | }); 192 | 193 | // Link filtering section - this is where the magic (regex) happens. 194 | // **************************************************************** 195 | const filters = await browser.storage.sync 196 | .get("options") 197 | .then((optionsStorage) => { 198 | if ( 199 | optionsStorage.options == undefined || 200 | optionsStorage.options.length <= 0 201 | ) { 202 | optionsStorage.options = []; 203 | } 204 | return optionsStorage.options; 205 | }); 206 | 207 | // This is an array of objects with the following structure: 208 | // { 209 | // title: "", 210 | // showParent: true/false, 211 | // links: [] 212 | // } 213 | const filteredLinks = []; 214 | 215 | // For each filter, check if any of the links in the linksArr match 216 | // the filter pattern. If they do, add them to the filteredLinks array 217 | filters.forEach((filter) => { 218 | const filteredLinksArr = []; 219 | linksArr.forEach((link) => { 220 | const re = new RegExp(filter.pattern); 221 | if (re.test(link.href)) { 222 | const link2Push = Object.assign({}, link); 223 | link2Push.summaryType = 224 | filter.summaryType === undefined ? "all" : filter.summaryType; 225 | link2Push.showDate = 226 | filter.showDate === undefined ? false : filter.showDate; 227 | filteredLinksArr.push(link2Push); 228 | } 229 | }); 230 | 231 | // Remove duplicates. Keep the latest. 232 | const filteredLinksArrUnique = []; 233 | filteredLinksArr.forEach((link) => { 234 | const found = filteredLinksArrUnique.find((l) => l.href == link.href); 235 | // If not found, add to uniques array. 236 | if (found == undefined) { 237 | filteredLinksArrUnique.push(link); 238 | // If found, compare createdAt dates and keep the latest. 239 | } else if (link.createdAt > found.createdAt && found.createdAt != null) { 240 | filteredLinksArrUnique.push(link); 241 | filteredLinksArrUnique.splice(filteredLinksArrUnique.indexOf(found), 1); 242 | console.log("Removing duplicate link: " + link.href); 243 | } 244 | }); 245 | 246 | // Add the unique links to the filteredLinks array. 247 | if (filteredLinksArrUnique.length > 0) { 248 | filteredLinks.push({ 249 | title: filter.title, 250 | showParent: filter.showParent, 251 | links: filteredLinksArrUnique, 252 | }); 253 | } 254 | }); 255 | 256 | // Alternative implementation of the previous algorithm for future thought: 257 | /* 258 | const filteredLinks = filters.flatMap((filter) => { 259 | const re = new RegExp(filter.pattern); 260 | const filteredLinksArr = linksArr 261 | .filter((link) => re.test(link.href)) 262 | .map((link) => { 263 | return { 264 | ...link, 265 | summaryType: filter.summaryType === undefined ? "all" : filter.summaryType, 266 | showDate: filter.showDate === undefined ? false : filter.showDate, 267 | }; 268 | }); 269 | 270 | const filteredLinksArrUnique = filteredLinksArr.reduce((unique, link) => { 271 | const found = unique.find((l) => l.href == link.href); 272 | if (!found) { 273 | return [...unique, link]; 274 | } else if (link.createdAt > found.createdAt && found.createdAt != null) { 275 | return [...unique.filter((l) => l.href !== link.href), link]; 276 | } else { 277 | return unique; 278 | } 279 | }, []); 280 | 281 | if (filteredLinksArrUnique.length > 0) { 282 | return { 283 | title: filter.title, 284 | showParent: filter.showParent, 285 | links: filteredLinksArrUnique, 286 | }; 287 | } else { 288 | return []; 289 | } 290 | }); 291 | */ 292 | 293 | console.log("filtered links: ", filteredLinks); 294 | console.log("attachments: ", attachmentsArr); 295 | console.log("images: ", imagesArr); // Log the images array 296 | 297 | // Store the filtered links, attachments, and images for the current ticket in the browser storage. 298 | browser.storage.local.set({ 299 | ticketStorage: { 300 | links: filteredLinks, 301 | attachments: attachmentsArr, 302 | images: imagesArr, // Store the images array 303 | state: "complete", 304 | count: numComments, 305 | ticketID: ticketID, 306 | updatedAt: Date.now(), 307 | }, 308 | }); 309 | } 310 | 311 | // Compare two version strings. 312 | // Return 1 if version1 is greater than version2. 313 | // Return -1 if version1 is less than version2. 314 | // Return 0 if version1 is equal to version2. 315 | function compareVersions(version1, version2) { 316 | const v1parts = version1.split("."); 317 | const v2parts = version2.split("."); 318 | 319 | for (let i = 0; i < v1parts.length; ++i) { 320 | if (v2parts.length === i) { 321 | return 1; 322 | } 323 | 324 | if (v1parts[i] === v2parts[i]) { 325 | continue; 326 | } 327 | if (v1parts[i] > v2parts[i]) { 328 | return 1; 329 | } 330 | return -1; 331 | } 332 | 333 | if (v1parts.length != v2parts.length) { 334 | return -1; 335 | } 336 | 337 | return 0; 338 | } 339 | 340 | // Extension has been updated or initially installed. 341 | // Handles setting default options and updating storage based on previous version. 342 | browser.runtime.onInstalled.addListener((data) => { 343 | const reason = data.reason; 344 | const previousVersion = data.previousVersion; 345 | if (reason === "install") { 346 | console.log("Zendesk Link Collector - installed"); 347 | // Set the default options on install. 348 | browser.storage.sync.set({ 349 | optionsGlobal: { 350 | wrapLists: false, 351 | backgroundProcessing: false, 352 | includeAttachments: true, 353 | includeImages: true, 354 | }, 355 | }); 356 | 357 | // Set the default patterns on install. 358 | // Check if patterns from a previous installation exist before overwriting them. 359 | browser.storage.sync.get("options").then((data) => { 360 | if (data.options == undefined || data.options.length <= 0) { 361 | browser.storage.sync.set({ 362 | options: [ 363 | { 364 | id: "b19a712c-dd34-491f-a43a-c0483f44f045", 365 | title: "GitHub Docs", 366 | pattern: "https:\\/\\/docs\\.github\\.com\\/", 367 | showParent: false, 368 | summaryType: "none", 369 | showDate: false, 370 | }, 371 | { 372 | id: "4adcb721-769c-48cd-b1b4-21bc76addad4", 373 | title: "GitHub Discussions", 374 | pattern: 375 | "https:\\/\\/github\\.com\\/orgs\\/community\\/discussions", 376 | showParent: false, 377 | summaryType: "all", 378 | showDate: true, 379 | }, 380 | { 381 | id: "9f6bc302-e46a-4621-a55d-fc4af232984d", 382 | title: "Zendesk Tickets", 383 | pattern: "https://[A-Za-z0-9]+.zendesk.com/agent/tickets/[0-9]+", 384 | showParent: false, 385 | summaryType: "all", 386 | showDate: false, 387 | }, 388 | ], 389 | }); 390 | } 391 | }); 392 | } else if (reason === "update") { 393 | console.log( 394 | "Zendesk Link Collector - updated from version " + previousVersion 395 | ); 396 | // Check that all currently expected storage values are set. 397 | // If not, set them to default. 398 | browser.storage.sync.get("optionsGlobal").then((data) => { 399 | if (data.optionsGlobal == undefined) { 400 | data.optionsGlobal = {}; 401 | } 402 | browser.storage.sync.set({ 403 | optionsGlobal: { 404 | wrapLists: 405 | data.optionsGlobal.wrapLists === undefined 406 | ? false 407 | : data.optionsGlobal.wrapLists, 408 | backgroundProcessing: 409 | data.optionsGlobal.backgroundProcessing === undefined 410 | ? false 411 | : data.optionsGlobal.backgroundProcessing, 412 | includeAttachments: 413 | data.optionsGlobal.includeAttachments === undefined 414 | ? true 415 | : data.optionsGlobal.includeAttachments, 416 | includeImages: 417 | data.optionsGlobal.includeImages === undefined 418 | ? true 419 | : data.optionsGlobal.includeImages, 420 | }, 421 | }); 422 | }); 423 | 424 | // EXAMPLE: Update storage based on previous version. For when that might be needed. 425 | // 426 | // if (compareVersions(previousVersion, "1.1.0") == -1) { 427 | // browser.storage.sync.get("optionsGlobal").then((data) => { 428 | // browser.storage.sync.set({ 429 | // optionsGlobal: { 430 | // wrapLists: data.optionsGlobal.wrapLists, 431 | // backgroundProcessing: false, 432 | // }, 433 | // }); 434 | // }); 435 | // } 436 | } 437 | }); 438 | 439 | // Check if background processing is enabled. 440 | // This is used to control whether event listeners that indicate a new ticket is being viewed should do anything. 441 | async function isBackgroundProcessingEnabled() { 442 | const data = await browser.storage.sync.get("optionsGlobal"); 443 | // Just in case the options are not set, return false. 444 | if ( 445 | data.optionsGlobal == undefined || 446 | data.optionsGlobal.backgroundProcessing == undefined 447 | ) { 448 | return false; 449 | } 450 | return data.optionsGlobal.backgroundProcessing; 451 | } 452 | 453 | // A new browser tab is active. 454 | // This is used to detect when a new ticket is being viewed. 455 | // Filter out events from active tabs that are not ticket pages. 456 | browser.tabs.onActivated.addListener((activeTab) => { 457 | browser.tabs.get(activeTab.tabId).then((tab) => { 458 | // Only process ticket pages. 459 | // Disable extension and change icon to grey if not a ticket page. 460 | if ( 461 | !tab.url || 462 | tab.url.search( 463 | /^https:\/\/[\-_A-Za-z0-9]+\.zendesk.com\/agent\/tickets\/[0-9]+/i 464 | ) == -1 465 | ) { 466 | browser.action.disable(tab.id); 467 | browser.action.setIcon({ path: "../icons/zlc-icon-disabled-16x16.png" }); 468 | return; 469 | } 470 | // A new ticket is being viewed, so process it and enable the extension. 471 | isBackgroundProcessingEnabled().then((status) => { 472 | if (status) { 473 | filterTicket(); 474 | } 475 | }); 476 | 477 | browser.action.setIcon({ path: "../icons/zlc-icon-16x16.png" }); 478 | browser.action.enable(tab.id); 479 | }); 480 | }); 481 | 482 | // A browser tab is updated. 483 | // This is used to detect when a new ticket is being viewed. 484 | // Filter out events from tabs that are not active, or are not ticket pages. 485 | browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { 486 | // Could be a ticket, but it's still loading or is not an active tab. 487 | if (changeInfo.status != "complete" || !tab.active) { 488 | return; 489 | } 490 | 491 | // This is likely not a ticket, so disable the extension and return. 492 | if ( 493 | !tab.url || 494 | tab.url.search( 495 | /^https:\/\/[\-_A-Za-z0-9]+\.zendesk.com\/agent\/tickets\/[0-9]+/i 496 | ) == -1 497 | ) { 498 | browser.action.disable(tab.id); 499 | browser.action.setIcon({ path: "../icons/zlc-icon-disabled-16x16.png" }); 500 | return; 501 | } 502 | 503 | // A new ticket is being viewed, so process it and enable the extension. 504 | isBackgroundProcessingEnabled().then((status) => { 505 | if (status) { 506 | filterTicket(); 507 | } 508 | }); 509 | browser.action.setIcon({ path: "../icons/zlc-icon-16x16.png" }); 510 | browser.action.enable(tab.id); 511 | }); 512 | 513 | // Listen for messages from the popup 514 | browser.runtime.onMessage.addListener((message) => { 515 | if (message.type == "refresh") { 516 | filterTicket(); 517 | } 518 | }); 519 | 520 | // Listen for keyboard shortcuts 521 | browser.commands.onCommand.addListener((command) => { 522 | switch (command) { 523 | case "copy-ticket-id": 524 | // Logic to send a message to the contentscript to copy the ticket ID to the clipboard. 525 | // If background processing is disabled, send a message to the contentscript to indicate that copying is not possible. 526 | isBackgroundProcessingEnabled().then((status) => { 527 | if (!status) { 528 | browser.tabs 529 | .query({ active: true, currentWindow: true }) 530 | .then((tabs) => { 531 | browser.tabs.sendMessage(tabs[0].id, { 532 | type: "copy-not-possible", 533 | }); 534 | }); 535 | return; 536 | } 537 | browser.tabs 538 | .query({ active: true, currentWindow: true }) 539 | .then((tabs) => { 540 | browser.tabs.sendMessage(tabs[0].id, { type: "copy-ticket-id" }); 541 | }); 542 | }); 543 | break; 544 | case "copy-ticket-id-md": 545 | // Logic to send a message to the contentscript to copy the ticket ID to the clipboard in markdown. 546 | // If background processing is disabled, send a message to the contentscript to indicate that copying is not possible. 547 | isBackgroundProcessingEnabled().then((status) => { 548 | if (!status) { 549 | browser.tabs 550 | .query({ active: true, currentWindow: true }) 551 | .then((tabs) => { 552 | browser.tabs.sendMessage(tabs[0].id, { 553 | type: "copy-not-possible", 554 | }); 555 | }); 556 | return; 557 | } 558 | browser.tabs 559 | .query({ active: true, currentWindow: true }) 560 | .then((tabs) => { 561 | browser.tabs.sendMessage(tabs[0].id, { type: "copy-ticket-id-md" }); 562 | }); 563 | }); 564 | break; 565 | default: 566 | console.log(`Command ${command} not recognized.`); 567 | } 568 | }); 569 | 570 | // TODO: Listen for ticket changed messages from the content script 571 | -------------------------------------------------------------------------------- /diagram.svg: -------------------------------------------------------------------------------- 1 | srcsrcsamplessamples.github.githubpopuppopupoptionsoptionsiconsiconsworkflowsworkflowslib/browser-polyf...lib/browser-polyf...lib/browser-polyf...content-scripts/c...content-scripts/c...content-scripts/c...background/backgr...background/backgr...background/backgr...manifest-fi...manifest-fi...manifest-fi...manifest.jsonmanifest.jsonmanifest.jsonmanifest-c...manifest-c...manifest-c...sample.htmlsample.htmlsample.htmlmakefilemakefilemakefilepopup.jspopup.jspopup.jspopup.csspopup.csspopup.csspopup.htmlpopup.htmlpopup.htmloptions.jsoptions.jsoptions.jsoptions.htmloptions.htmloptions.htmloptions.cssoptions.cssoptions.csscodeql.ymlcodeql.ymlcodeql.yml.css.html.js.json.svg.ymleach dot sized by file size -------------------------------------------------------------------------------- /src/popup/popup.js: -------------------------------------------------------------------------------- 1 | // Scroll to the comment with the given commentID or auditID. 2 | // Actual scrolling is done in the content script. 3 | function scrollToComment(data) { 4 | browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { 5 | browser.tabs.sendMessage(tabs[0].id, { 6 | type: "scroll", 7 | commentID: data.commentID, 8 | auditID: data.auditID, 9 | }); 10 | }); 11 | } 12 | 13 | // Write the configurable summary to the clipboard. 14 | async function writeSummaryClipboard() { 15 | let summary = ""; 16 | document.querySelectorAll(".list-links").forEach((list) => { 17 | // If "all" summary type, add all to summary. 18 | if (list.getAttribute("data-summary-type") == "all") { 19 | summary += `### ${list.getAttribute("data-title")}\n\n`; 20 | list.childNodes.forEach((li) => { 21 | summary += `- [${li.textContent}](${ 22 | li.querySelector("a").href 23 | }) - ${li.getAttribute("data-created-at")}\n`; 24 | }); 25 | summary += "\n"; 26 | // If "latest" summary type, add only the latest to summary. 27 | } else if (list.getAttribute("data-summary-type") == "latest") { 28 | summary += `### ${list.getAttribute("data-title")} (Latest)\n\n`; 29 | const latest = list.childNodes[list.childNodes.length - 1]; 30 | summary += `- [${latest.textContent}](${ 31 | latest.querySelector("a").href 32 | }) - ${latest.getAttribute("data-created-at")}\n`; 33 | summary += "\n"; 34 | } 35 | }); 36 | 37 | // Include attachments and images in the markdown summary if the respective global options are enabled. 38 | // Fallback to enabled if the options are not set or null. 39 | await browser.storage.sync.get("optionsGlobal").then(async (data) => { 40 | const includeAttachments = data.optionsGlobal?.includeAttachments ?? true; 41 | const includeImages = data.optionsGlobal?.includeImages ?? true; 42 | 43 | console.log(includeAttachments, includeImages); 44 | 45 | if (includeAttachments) { 46 | summary += "### Attachments\n\n"; 47 | await browser.storage.local.get("ticketStorage").then(async (data) => { 48 | if (data.ticketStorage && data.ticketStorage.attachments.length > 0) { 49 | const markdownLinks = data.ticketStorage.attachments 50 | .map((attachment) => 51 | attachment.attachments 52 | .map( 53 | (file) => 54 | `[${file.file_name}](${file.content_url}) - ${attachment.created_at}` 55 | ) 56 | .join("\n") 57 | ) 58 | .join("\n\n"); 59 | summary += markdownLinks; 60 | } 61 | }); 62 | summary += "\n"; 63 | } 64 | 65 | if (includeImages) { 66 | summary += "### Images\n\n"; 67 | await browser.storage.local.get("ticketStorage").then((data) => { 68 | if (data.ticketStorage && data.ticketStorage.images.length > 0) { 69 | const markdownImages = data.ticketStorage.images 70 | .map( 71 | (image) => 72 | `_${image.fileName}_ - ${image.createdAt}\n\n![${image.fileName}](${image.url})` 73 | ) 74 | .join("\n\n"); 75 | summary += markdownImages; 76 | } 77 | }); 78 | summary += "\n"; 79 | } 80 | }); 81 | 82 | if (summary != "") { 83 | navigator.clipboard.writeText(summary); 84 | document.getElementById("summary-copy").classList.add("hidden"); 85 | document.getElementById("summary-check").classList.remove("hidden"); 86 | document.getElementById("summary-text").textContent = "Copied!"; 87 | // Hide the checkmark after 2 seconds. 88 | setTimeout(() => { 89 | document.getElementById("summary-check").classList.add("hidden"); 90 | document.getElementById("summary-copy").classList.remove("hidden"); 91 | document.getElementById("summary-text").textContent = "Summary"; 92 | }, 2000); 93 | } 94 | } 95 | 96 | //Write a link to the clipboard in markdown format. 97 | function writeLinkClipboard(text, href) { 98 | const link = `[${text}](${href})`; 99 | navigator.clipboard.writeText(link); 100 | } 101 | 102 | // Code from https://stackoverflow.com/questions/55214828/how-to-make-a-cross-origin-request-in-a-content-script-currently-blocked-by-cor/55215898#55215898 103 | async function fetchResource(input, init) { 104 | const type = "fetch"; 105 | return new Promise((resolve, reject) => { 106 | browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { 107 | browser.tabs 108 | .sendMessage(tabs[0].id, { type, input, init }) 109 | .then((messageResponse) => { 110 | const [response, error] = messageResponse; 111 | if (response === null) { 112 | reject(error); 113 | } else { 114 | // Use undefined on a 204 - No Content 115 | const body = response.body ? new Blob([response.body]) : undefined; 116 | resolve( 117 | new Response(body, { 118 | status: response.status, 119 | statusText: response.statusText, 120 | }) 121 | ); 122 | } 123 | }); 124 | }); 125 | }); 126 | } 127 | 128 | async function displayLinks(linksBundle) { 129 | // If there are no links, display a message and return. 130 | if ( 131 | linksBundle.length <= 0 && 132 | document.querySelectorAll("#list-container-links .list-links").length <= 0 133 | ) { 134 | document 135 | .getElementById("not-found-container-links") 136 | .classList.remove("hidden"); 137 | return; 138 | } 139 | document.getElementById("not-found-container-links").classList.add("hidden"); 140 | 141 | // Get list container 142 | const linksList = document.getElementById("list-container-links"); 143 | 144 | //Clear the list container of headers and lists from a potential previous run. 145 | document 146 | .querySelectorAll("#list-container-links h3, #list-container-links ul") 147 | .forEach((element) => { 148 | element.parentNode.removeChild(element); 149 | }); 150 | 151 | // Add wrap class if option is set. 152 | if (optionsGlobal.wrapLists) { 153 | linksList.classList.add("wrap"); 154 | } 155 | 156 | // For each bundle, create a header and the list of links. 157 | linksBundle.forEach((bundle) => { 158 | //Check for existing header 159 | let ul; 160 | let foundHeader = false; 161 | 162 | if (document.getElementById(`header-${bundle.title}`) != null) { 163 | // Header already exists, so list should already exist. 164 | ul = document.getElementById(`list-${bundle.title}`); 165 | foundHeader = true; 166 | } else { 167 | // Create header. 168 | const header = document.createElement("h3"); 169 | header.setAttribute("class", "list-header list-header-links"); 170 | header.setAttribute("id", `header-${bundle.title}`); 171 | header.textContent = bundle.title; 172 | linksList.appendChild(header); 173 | 174 | // Create list. 175 | ul = document.createElement("ul"); 176 | ul.setAttribute("class", "list-links"); 177 | ul.setAttribute("id", `list-${bundle.title}`); 178 | ul.setAttribute("data-title", bundle.title); 179 | ul.setAttribute("data-summary-type", bundle.links[0].summaryType); 180 | } 181 | // For each link in bundle, create a list item. 182 | bundle.links.forEach((link) => { 183 | // Create the list item. 184 | const li = document.createElement("li"); 185 | li.setAttribute("class", "list-item-links"); 186 | li.setAttribute("data-created-at", link.createdAt); 187 | li.setAttribute("data-summary-type", link.summaryType); 188 | li.setAttribute("data-source", link.source); 189 | 190 | // Create the scroll icon and append to list item, if there is a comment to scroll to. 191 | if (link.commentID != undefined || link.auditID != undefined) { 192 | const iScroll = document.createElement("i"); 193 | iScroll.setAttribute("class", "icon-invert icon-li icon-search"); 194 | iScroll.setAttribute("commentID", link.commentID); 195 | iScroll.setAttribute("auditID", link.auditID); 196 | iScroll.setAttribute("title", "Scroll to link's source comment."); 197 | li.appendChild(iScroll); 198 | } 199 | 200 | // Create the copy to markdown icon and append to list item. 201 | const iCopy = document.createElement("i"); 202 | iCopy.setAttribute("class", "icon-invert icon-li icon-copy"); 203 | iCopy.setAttribute("title", "Copy link to markdown."); 204 | li.appendChild(iCopy); 205 | 206 | // Add link content or parent context to list item. 207 | if (bundle.showParent) { 208 | // Parse the parent context as HTML and append to list item. 209 | // (Parent context is returned from Zendesk API as plain text) 210 | const parser = new DOMParser(); 211 | const doc = parser.parseFromString(link.parent_text, "text/html"); 212 | 213 | // Need to add `target="_blank"` to all links in the parent context. 214 | // Otherwise, they do not open in a tab. 215 | doc.querySelectorAll(`a`).forEach((a) => { 216 | a.setAttribute("target", "_blank"); 217 | a.setAttribute( 218 | "title", 219 | `URL: ${a.href}\n\nComment created at: ${li.getAttribute( 220 | "data-created-at" 221 | )}\nLink source: ${li.getAttribute("data-source")}` 222 | ); 223 | }); 224 | 225 | // Get all the body because that's all we care about. 226 | const bodyNodes = doc.getElementsByTagName("body")[0].childNodes; 227 | 228 | // Get all the text nodes and wrap them in a span. 229 | let nodes = []; 230 | bodyNodes.forEach((node) => { 231 | if (node.nodeType == Node.TEXT_NODE) { 232 | const span = document.createElement("span"); 233 | span.textContent = node.textContent; 234 | // span.setAttribute('class', 'link-context'); 235 | nodes.push(span); 236 | } else { 237 | nodes.push(node); 238 | } 239 | }); 240 | 241 | // Append all nodes to list item. 242 | const spanContext = document.createElement("span"); 243 | spanContext.setAttribute("class", "link-context"); 244 | spanContext.append(...nodes); 245 | li.append(spanContext); 246 | } else { 247 | const a = document.createElement("a"); 248 | a.setAttribute("target", "_blank"); 249 | a.setAttribute("href", link.href); 250 | a.setAttribute( 251 | "title", 252 | `URL: ${a.href}\n\nComment created at: ${li.getAttribute( 253 | "data-created-at" 254 | )}\nLink source: ${li.getAttribute("data-source")}` 255 | ); 256 | a.textContent = link.text; 257 | li.appendChild(a); 258 | } 259 | 260 | if (link.showDate) { 261 | // Append the date to the list item. 262 | const spanDate = document.createElement("span"); 263 | const spaceNode = document.createTextNode(" "); 264 | spanDate.setAttribute("class", "link-date"); 265 | const date = new Date(link.createdAt); 266 | const year = date.getFullYear().toString().slice(-2); 267 | const time = date.toLocaleTimeString("en-US", { 268 | hour: "2-digit", 269 | minute: "2-digit", 270 | hour12: true, 271 | }); 272 | 273 | spanDate.textContent = `\u00A0- ${date.toLocaleString("en-US", { 274 | month: "short", 275 | })} ${date.getDate()}, '${year} at ${time}`; 276 | spanDate.setAttribute( 277 | "title", 278 | `Click to copy time in UTC\n\n${link.createdAt}` 279 | ); 280 | li.appendChild(spaceNode); 281 | li.appendChild(spanDate); 282 | spanDate.addEventListener("click", () => { 283 | navigator.clipboard.writeText(link.createdAt); 284 | }); 285 | } 286 | 287 | ul.appendChild(li); 288 | }); 289 | 290 | // Only append the ul to a header if it has not been done previously. 291 | if (!foundHeader) { 292 | linksList.appendChild(ul); 293 | } 294 | }); 295 | 296 | // Add event listeners to icon for scrolling. 297 | document 298 | .getElementById("list-container-links") 299 | .querySelectorAll("i.icon-search") 300 | .forEach((i) => { 301 | i.addEventListener("click", () => { 302 | scrollToComment({ 303 | commentID: i.getAttribute("commentID"), 304 | auditID: i.getAttribute("auditID"), 305 | }); 306 | }); 307 | }); 308 | 309 | // Add event listeners to icon for copy. 310 | document 311 | .getElementById("list-container-links") 312 | .querySelectorAll("i.icon-copy") 313 | .forEach((i) => { 314 | i.addEventListener("click", () => { 315 | const href = i.parentElement.querySelector("a").href; 316 | const text = i.parentElement.textContent; 317 | writeLinkClipboard(text, href); 318 | }); 319 | }); 320 | 321 | // Add title attribute to custom field field icons. 322 | document 323 | .querySelectorAll('.list-item-links[data-source="custom field"]') 324 | .forEach((elem) => { 325 | elem.setAttribute("title", "This link was found in a custom field."); 326 | }); 327 | } 328 | 329 | async function displayAttachments(attachmentsArr) { 330 | // If there are no attachments, display a message and return. 331 | if (attachmentsArr.length <= 0) { 332 | document 333 | .getElementById("not-found-container-attachments") 334 | .classList.remove("hidden"); 335 | return; 336 | } 337 | document 338 | .getElementById("not-found-container-attachments") 339 | .classList.add("hidden"); 340 | 341 | // Create and display attachments list. 342 | // Get attachments container. 343 | const attachmentsList = document.getElementById("list-container-attachments"); 344 | 345 | //Clear the attachments container of headers and lists from a potential previous run. 346 | document 347 | .querySelectorAll( 348 | "#list-container-attachments h3, #list-container-attachments ul" 349 | ) 350 | .forEach((element) => { 351 | element.parentNode.removeChild(element); 352 | }); 353 | 354 | const ul = document.createElement("ul"); 355 | ul.setAttribute("class", "list-attachments"); 356 | 357 | // For each comment, create a top-level list item. 358 | attachmentsArr.forEach((comment) => { 359 | const liDate = document.createElement("li"); 360 | liDate.setAttribute("class", "list-item-attachments"); 361 | const txtDate = document.createTextNode( 362 | `Comment on: ${comment.created_at}` 363 | ); 364 | 365 | // Create the icon and append to list item. 366 | const i = document.createElement("i"); 367 | i.setAttribute("class", "icon-invert icon-li icon-search"); 368 | i.setAttribute("commentID", comment.commentID); 369 | i.setAttribute("auditID", comment.auditID); 370 | liDate.append(i, txtDate); 371 | 372 | const ulComment = document.createElement("ul"); 373 | ulComment.setAttribute("class", "list-attachments"); 374 | 375 | // For each attachment, create a list item and append to top-level list item. 376 | comment.attachments.forEach((attachment) => { 377 | const liAttachment = document.createElement("li"); 378 | liAttachment.setAttribute("class", "list-item-attachments"); 379 | const aAttachment = document.createElement("a"); 380 | aAttachment.setAttribute("target", "_blank"); 381 | aAttachment.setAttribute("href", attachment.content_url); 382 | aAttachment.textContent = attachment.file_name; 383 | 384 | liAttachment.appendChild(aAttachment); 385 | ulComment.appendChild(liAttachment); 386 | liDate.appendChild(ulComment); 387 | }); 388 | 389 | ul.appendChild(liDate); 390 | attachmentsList.appendChild(ul); 391 | }); 392 | 393 | // Add event listeners to icon for scrolling. 394 | document 395 | .getElementById("list-container-attachments") 396 | .querySelectorAll("i") 397 | .forEach((i) => { 398 | i.addEventListener("click", () => { 399 | scrollToComment({ 400 | commentID: i.getAttribute("commentID"), 401 | auditID: i.getAttribute("auditID"), 402 | }); 403 | }); 404 | }); 405 | } 406 | 407 | // Implement logic to populate the "Images" tab with image previews 408 | async function displayImages(imagesArr) { 409 | // If there are no images, display a message and return. 410 | if (imagesArr.length <= 0) { 411 | document 412 | .getElementById("not-found-container-images") 413 | .classList.remove("hidden"); 414 | return; 415 | } 416 | document.getElementById("not-found-container-images").classList.add("hidden"); 417 | 418 | // Get images container 419 | const imagesList = document.getElementById("list-container-images"); 420 | 421 | // Clear the images container of previous content 422 | imagesList.innerHTML = ""; 423 | 424 | const ul = document.createElement("ul"); 425 | ul.setAttribute("class", "list-images"); 426 | 427 | // For each image, create an image element and append to the container 428 | imagesArr.forEach((image) => { 429 | const li = document.createElement("li"); 430 | li.setAttribute("class", "list-item-images"); 431 | li.setAttribute("data-created-at", image.createdAt); 432 | li.setAttribute("data-summary-type", image.summaryType); 433 | li.setAttribute("data-source", image.source); 434 | 435 | // Create the scroll icon and append to list item, if there is a comment to scroll to. 436 | if (image.commentID != undefined || image.auditID != undefined) { 437 | const iScroll = document.createElement("i"); 438 | iScroll.setAttribute("class", "icon-invert icon-li icon-search"); 439 | iScroll.setAttribute("commentID", image.commentID); 440 | iScroll.setAttribute("auditID", image.auditID); 441 | iScroll.setAttribute("title", "Scroll to image's source comment."); 442 | li.appendChild(iScroll); 443 | } 444 | 445 | const img = document.createElement("img"); 446 | img.src = image.url; 447 | img.alt = image.fileName; 448 | img.title = `Click to open in new tab\n\nFile: ${image.fileName}\nComment created at: ${image.createdAt}`; 449 | img.addEventListener("click", () => { 450 | // Send a message to the contentscript to click Zendesk's image preview button 451 | browser.tabs.query({ active: true, currentWindow: true }).then((tabs) => { 452 | browser.tabs.sendMessage(tabs[0].id, { 453 | type: "image-preview", 454 | imageTitle: image.fileName, 455 | imageURL: image.mappedURL, 456 | }); 457 | }); 458 | }); 459 | 460 | li.appendChild(img); 461 | ul.appendChild(li); 462 | }); 463 | 464 | // Append the list of images to the images container 465 | imagesList.appendChild(ul); 466 | 467 | // Add event listener to scroll to comment when scroll icon is clicked 468 | document 469 | .getElementById("list-container-images") 470 | .querySelectorAll("i.icon-search") 471 | .forEach((i) => { 472 | i.addEventListener("click", () => { 473 | scrollToComment({ 474 | commentID: i.getAttribute("commentID"), 475 | auditID: i.getAttribute("auditID"), 476 | }); 477 | }); 478 | }); 479 | } 480 | 481 | // Function to copy all attachments in markdown format to clipboard 482 | function copyAttachmentsMarkdown() { 483 | browser.storage.local.get("ticketStorage").then((data) => { 484 | if (data.ticketStorage && data.ticketStorage.attachments.length > 0) { 485 | const markdownLinks = data.ticketStorage.attachments 486 | .map((attachment) => 487 | attachment.attachments 488 | .map( 489 | (file) => 490 | `[${file.file_name}](${file.content_url}) - ${attachment.created_at}` 491 | ) 492 | .join("\n") 493 | ) 494 | .join("\n\n"); 495 | navigator.clipboard.writeText(markdownLinks).then(() => { 496 | document.getElementById("attachments-copy").classList.add("hidden"); 497 | document.getElementById("attachments-check").classList.remove("hidden"); 498 | document.getElementById("attachments-text").textContent = "Copied!"; 499 | // Hide the checkmark after 2 seconds. 500 | setTimeout(() => { 501 | document.getElementById("attachments-check").classList.add("hidden"); 502 | document 503 | .getElementById("attachments-copy") 504 | .classList.remove("hidden"); 505 | document.getElementById("attachments-text").textContent = 506 | "Attachments"; 507 | }, 2000); 508 | console.log("Attachments copied to clipboard in markdown format."); 509 | }); 510 | } 511 | }); 512 | } 513 | 514 | // Function to copy all images in markdown format to clipboard 515 | function copyImagesMarkdown() { 516 | browser.storage.local.get("ticketStorage").then((data) => { 517 | if (data.ticketStorage && data.ticketStorage.images.length > 0) { 518 | const markdownImages = data.ticketStorage.images 519 | .map( 520 | (image) => 521 | `_${image.fileName}_ - ${image.createdAt}\n\n![${image.fileName}](${image.url})` 522 | ) 523 | .join("\n\n"); 524 | navigator.clipboard.writeText(markdownImages).then(() => { 525 | document.getElementById("images-copy").classList.add("hidden"); 526 | document.getElementById("images-check").classList.remove("hidden"); 527 | document.getElementById("images-text").textContent = "Copied!"; 528 | // Hide the checkmark after 2 seconds. 529 | setTimeout(() => { 530 | document.getElementById("images-check").classList.add("hidden"); 531 | document.getElementById("images-copy").classList.remove("hidden"); 532 | document.getElementById("images-text").textContent = "Images"; 533 | }, 2000); 534 | console.log("Images copied to clipboard in markdown format."); 535 | }); 536 | } 537 | }); 538 | } 539 | 540 | // Global options. 541 | const optionsGlobal = {}; 542 | browser.storage.sync.get("optionsGlobal").then((data) => { 543 | if (data.optionsGlobal == undefined || data.optionsGlobal.length <= 0) { 544 | data.optionsGlobal = []; 545 | } 546 | optionsGlobal.wrapLists = data.optionsGlobal.wrapLists; 547 | optionsGlobal.backgroundProcessing = data.optionsGlobal.backgroundProcessing; 548 | }); 549 | 550 | // Start the popup. 551 | function start() { 552 | browser.storage.local.get("ticketStorage").then((data) => { 553 | // Something is wrong? 554 | if (data.ticketStorage == undefined || data.ticketStorage.length <= 0) { 555 | console.error( 556 | "Ticket storage doesn't look expected: ", 557 | data.ticketStorage 558 | ); 559 | return; 560 | } 561 | console.log("Received ticket from storage: ", data.ticketStorage); 562 | document.getElementById("loader").classList.add("loading"); 563 | document.getElementById("list-container-links").classList.add("hidden"); 564 | 565 | // Display the links. 566 | displayLinks(data.ticketStorage.links); 567 | displayAttachments(data.ticketStorage.attachments); 568 | displayImages(data.ticketStorage.images); 569 | document 570 | .getElementById("button-refresh") 571 | .setAttribute( 572 | "title", 573 | `Refresh the ticket data immediately.` + 574 | `\n\nComments processed: ${data.ticketStorage.count}` + 575 | `\nTicket ID: ${data.ticketStorage.ticketID}` + 576 | `\nLast updated: ${new Date(data.ticketStorage.updatedAt)}` 577 | ); 578 | 579 | document.getElementById("loader").classList.remove("loading"); 580 | document.getElementById("list-container-links").classList.remove("hidden"); 581 | }); 582 | } 583 | 584 | // Send message to background script requesting refresh of ticketStorage. 585 | function refresh() { 586 | //Clear the list container of headers and lists from a potential previous run. 587 | document 588 | .querySelectorAll("#list-container-links h3, #list-container-links ul") 589 | .forEach((element) => { 590 | element.parentNode.removeChild(element); 591 | }); 592 | 593 | //Clear the attachments container of headers and lists from a potential previous run. 594 | document 595 | .querySelectorAll( 596 | "#list-container-attachments h3, #list-container-attachments ul" 597 | ) 598 | .forEach((element) => { 599 | element.parentNode.removeChild(element); 600 | }); 601 | 602 | browser.runtime.sendMessage({ type: "refresh" }); 603 | } 604 | 605 | // Listen for changes to the ticketStorage. 606 | // This means the background script has finished collecting links. 607 | browser.storage.onChanged.addListener((changed) => { 608 | if (changed.ticketStorage == undefined) { 609 | return; 610 | } 611 | if (changed.ticketStorage.newValue.state == "complete") { 612 | start(); 613 | } else if (changed.ticketStorage.newValue.state == "loading") { 614 | document.getElementById("loader").classList.add("loading"); 615 | document.getElementById("list-container-links").classList.add("hidden"); 616 | } 617 | }); 618 | 619 | /* 620 | * ******************** 621 | * * MAIN ENTRY POINT * 622 | * ******************** 623 | * */ 624 | document.addEventListener("DOMContentLoaded", () => { 625 | // Start the popup. 626 | // If background processing is disabled, we have to also send a refresh request to get the current ticket. 627 | // Otherwise, the background script will have the new ticket already and we can directly start. 628 | browser.storage.sync.get("optionsGlobal").then((data) => { 629 | if (data.optionsGlobal.backgroundProcessing) { 630 | // Show that background processing is enabled. 631 | // Directly load from ticket storage. 632 | document.getElementById("background-processing").checked = true; 633 | start(); 634 | } else { 635 | // Show that background processing is disabled. 636 | // Send refresh request to background script. 637 | document.getElementById("background-processing").checked = false; 638 | refresh(); 639 | } 640 | }); 641 | 642 | // Add event listeners to static elements. 643 | 644 | // Event listener for the open options link in the "not found" message. 645 | document 646 | .getElementById("not-found-link-patterns-options") 647 | .addEventListener("click", () => { 648 | browser.runtime.openOptionsPage(); 649 | }); 650 | 651 | // Event listener to open options when options button is clicked. 652 | document.getElementById("button-options").addEventListener("click", () => { 653 | browser.runtime.openOptionsPage(); 654 | }); 655 | 656 | // Event listener to copy summary to clipboard when summary button is clicked. 657 | document.getElementById("button-summary").addEventListener("click", () => { 658 | writeSummaryClipboard(); 659 | }); 660 | 661 | // Event listener to toggle background processing. 662 | document 663 | .getElementById("button-background-processing") 664 | .addEventListener("click", (event) => { 665 | const checkbox = document.getElementById("background-processing"); 666 | browser.storage.sync.get("optionsGlobal").then((data) => { 667 | // If run in background is disabled, then enable it. 668 | if (!data.optionsGlobal.backgroundProcessing) { 669 | console.log("Enable background processing."); 670 | data.optionsGlobal.backgroundProcessing = true; 671 | browser.storage.sync 672 | .set({ 673 | optionsGlobal: data.optionsGlobal, 674 | }) 675 | .then(() => { 676 | checkbox.checked = true; 677 | }); 678 | return; 679 | } 680 | // If run in background is enabled, then disable it. 681 | console.log("Disable background processing."); 682 | data.optionsGlobal.backgroundProcessing = false; 683 | browser.storage.sync 684 | .set({ 685 | optionsGlobal: data.optionsGlobal, 686 | }) 687 | .then(() => { 688 | checkbox.checked = false; 689 | }); 690 | }); 691 | }); 692 | 693 | // Add event listener to the refresh button. 694 | document.getElementById("button-refresh").addEventListener("click", () => { 695 | refresh(); 696 | }); 697 | 698 | // Add event listeners to view swap buttons. 699 | // Links tab is clicked. 700 | document.getElementById("button-links").addEventListener("click", () => { 701 | document.getElementById("button-links").classList.add("checked"); 702 | document.getElementById("list-container-links").classList.add("selected"); 703 | document.querySelectorAll(".row-links").forEach((row) => { 704 | row.classList.add("selected"); 705 | }); 706 | document.querySelectorAll(".row-attachments").forEach((row) => { 707 | row.classList.remove("selected"); 708 | }); 709 | document.querySelectorAll(".row-images").forEach((row) => { 710 | row.classList.remove("selected"); 711 | }); 712 | 713 | document.getElementById("button-attachments").classList.remove("checked"); 714 | document.getElementById("button-images").classList.remove("checked"); 715 | document 716 | .getElementById("list-container-attachments") 717 | .classList.remove("selected"); 718 | document 719 | .getElementById("list-container-images") 720 | .classList.remove("selected"); 721 | }); 722 | 723 | // Attachment tab is clicked. 724 | document 725 | .getElementById("button-attachments") 726 | .addEventListener("click", () => { 727 | document.getElementById("button-links").classList.remove("checked"); 728 | document.getElementById("button-images").classList.remove("checked"); 729 | document 730 | .getElementById("list-container-links") 731 | .classList.remove("selected"); 732 | document 733 | .getElementById("list-container-images") 734 | .classList.remove("selected"); 735 | 736 | document.querySelectorAll(".row-links").forEach((row) => { 737 | row.classList.remove("selected"); 738 | }); 739 | document.querySelectorAll(".row-attachments").forEach((row) => { 740 | row.classList.add("selected"); 741 | }); 742 | document.querySelectorAll(".row-images").forEach((row) => { 743 | row.classList.remove("selected"); 744 | }); 745 | 746 | document.getElementById("button-attachments").classList.add("checked"); 747 | document 748 | .getElementById("list-container-attachments") 749 | .classList.add("selected"); 750 | }); 751 | 752 | // Image tab is clicked. 753 | document.getElementById("button-images").addEventListener("click", () => { 754 | document.getElementById("button-images").classList.add("checked"); 755 | document.getElementById("list-container-images").classList.add("selected"); 756 | 757 | // Deselect other tabs 758 | document.getElementById("button-links").classList.remove("checked"); 759 | document 760 | .getElementById("list-container-links") 761 | .classList.remove("selected"); 762 | document.getElementById("button-attachments").classList.remove("checked"); 763 | document 764 | .getElementById("list-container-attachments") 765 | .classList.remove("selected"); 766 | 767 | // Hide summary and background processing options for images tab 768 | document.querySelectorAll(".row-links").forEach((row) => { 769 | row.classList.remove("selected"); 770 | }); 771 | document.querySelectorAll(".row-attachments").forEach((row) => { 772 | row.classList.remove("selected"); 773 | }); 774 | document.querySelectorAll(".row-images").forEach((row) => { 775 | row.classList.add("selected"); 776 | }); 777 | }); 778 | 779 | // Dynamically retrieve the version number from manifest.json and insert it into the "What's new?" button text. 780 | const manifestData = browser.runtime.getManifest(); 781 | const version = manifestData.version; 782 | const whatsNewButton = document.getElementById("button-whats-new"); 783 | whatsNewButton.textContent = `v${version}`; 784 | whatsNewButton.setAttribute( 785 | "href", 786 | `https://github.com/bagtoad/zendesk-link-collector/releases/tag/v${version}` 787 | ); 788 | 789 | // Add event listeners for the new buttons to copy attachments and images in markdown format 790 | document 791 | .getElementById("button-copy-attachments-md") 792 | .addEventListener("click", copyAttachmentsMarkdown); 793 | document 794 | .getElementById("button-copy-images-md") 795 | .addEventListener("click", copyImagesMarkdown); 796 | }); 797 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------