Skip to content

Instantly share code, notes, and snippets.

@TortoiseWrath
Last active February 21, 2024 20:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TortoiseWrath/0def31f4fa6a42cfbda553f2302b9705 to your computer and use it in GitHub Desktop.
Save TortoiseWrath/0def31f4fa6a42cfbda553f2302b9705 to your computer and use it in GitHub Desktop.
FreeTaxUSA capital gains script
// Copyright 2022 Google LLC.
// SPDX-License-Identifier: Apache-2.0
// This is not an officially supported Google product. They just technically own it because I work for them.
// A function to programatically enter non-1099-B capital gains/losses into FreeTaxUSA.
// Because I'd rather run a script for half an hour than pay for tax preparation software with an import button.
// Run in browser console.
const process = async (description, acq_date, basis, sold_date, proceeds, wash_sale_amount) => {
submitButton('BUTTON_YES',document.querySelector('a.button1'));
while (!document.getElementById('sale_type-I')) {
await new Promise(r => setTimeout(r, 100));
}
document.getElementById('sale_type-I').checked = true;
submitButton('BUTTON_DONE',document.querySelector('a.button1'));
while (!document.getElementById('temp_inv_desc')) {
await new Promise(r => setTimeout(r, 100));
}
document.getElementById('temp_inv_desc').value = description;
document.getElementById('acq_date').value = acq_date;
document.getElementById('sold_date').value = sold_date;
document.getElementById('sale_price').value = proceeds;
document.getElementById('temp_basis').value = basis;
document.getElementById('basis_shown-C').checked = true;
submitButton('BUTTON_DONE',document.querySelector('a.button1'));
while (!document.getElementById('is_adjustments-help-3')) {
await new Promise(r => setTimeout(r, 100));
}
submitButton('BUTTON_DONE',document.querySelector('a.button1'));
if (parseInt(proceeds) < parseInt(basis)) {
while (!document.getElementById('is_wash-1')) {
await new Promise(r => setTimeout(r, 100));
}
if (parseInt(wash_sale_amount)) {
document.getElementById('is_wash-1').checked = true;
submitButton('BUTTON_DONE',document.querySelector('a.button1'));
while (!document.getElementById('temp_disallowed_wash')) {
await new Promise(r => setTimeout(r, 100));
}
document.getElementById('temp_disallowed_wash').value =
Math.min(parseInt(wash_sale_amount), parseInt(basis) - parseInt(proceeds));
}
submitButton('BUTTON_DONE',document.querySelector('a.button1'));
}
while (document.querySelectorAll('a.button1').length !== 4) {
await new Promise(r => setTimeout(r, 100));
}
};
// Example usage:
let rows = `10675.84 DOGE 3/10/2018 45 1/29/2021 734 0
97.237459 DOGE 1/29/2021 7 1/29/2021 5 2
934.252541 DOGE 1/29/2021 45 1/29/2021 44 0`.split('\n');
(async () => {
let i = 0;
for (const row of rows) {
console.log(i++, row);
const values = row.split('\t');
await process(...values);
await new Promise(r => setTimeout(r, 1000));
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment