Created
October 24, 2021 17:37
-
-
Save azazar/16769218056fd19f847e7a8fe2dee6b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name portfoliovisualizer.com Download Link | |
| // @namespace http://portfoliovisualizer.com.azazar.com/ | |
| // @version 0.1 | |
| // @description Add Portfolio Download Link | |
| // @author Azazar | |
| // @match https://www.portfoliovisualizer.com/* | |
| // @icon https://www.google.com/s2/favicons?domain=portfoliovisualizer.com | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| for(let linkNum = 1; ; linkNum++) { | |
| let link = document.getElementById('saveLink' + linkNum); | |
| if (link === null) { | |
| break; | |
| } | |
| let table = link.parentNode.parentNode.parentNode.parentNode; | |
| let symbolIndex = -1; | |
| let volumeIndex = -1; | |
| let cells = table.tHead.rows[0].cells; | |
| for(let cellIdx = 0; cellIdx < cells.length; cellIdx++) { | |
| let cell = cells[cellIdx]; | |
| if (cell.textContent === 'Ticker') { | |
| symbolIndex = cellIdx; | |
| } | |
| else if (cell.textContent === 'Allocation') { | |
| volumeIndex = cellIdx; | |
| } | |
| } | |
| let csv = "Symbol,Volume\n"; | |
| let rows = table.tBodies[0].rows; | |
| for(let rowIdx = 0; rowIdx < rows.length; rowIdx++) { | |
| let cells = rows[rowIdx].cells; | |
| csv += cells[symbolIndex].textContent + "," + cells[volumeIndex].textContent + "\n"; | |
| } | |
| console.log("CSV:", csv); | |
| let newLink = document.createElement('A'); | |
| newLink.appendChild(document.createTextNode('⇓ Export »')); | |
| newLink.setAttribute('href', 'data:text/csv;base64,' + btoa(csv)); | |
| newLink.setAttribute('download', 'portfolio' + linkNum + '.csv'); | |
| link.parentNode.appendChild(newLink); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment