Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gianpaj/168861c335dc41069810cd1c81d5c13a to your computer and use it in GitHub Desktop.
Save gianpaj/168861c335dc41069810cd1c81d5c13a to your computer and use it in GitHub Desktop.
Removes duplicate alert logs from the alert logs list in TradingView
// find all the alert logs 'div' elements that contain the text. e.g. 'BTCUSDTPERP, 15 Crossing Horizontal Line'
const listSelector = ".widgetbar-widget-alerts_log > div:nth-child(2) .message-_BiOF1cO";
// get all the alert logs 'div' elements as an array of objects. sort them by 'pair' name.
// e.g.
// { i: 0, textContent: "BTCUSDTPERP, 15 Crossing Horizontal Line", pair: "BTCUSDTPERP" }
var arr = Array.from(document.querySelectorAll(listSelector))
.map((a, i) => ({
i,
textContent: a.textContent,
pair: a.textContent.split(" ")[0].replace(",", ""),
}))
.sort((a, b) => a.pair > b.pair);
// find in 'arr' array elements duplicated by the 'pair' key. keep those that are duplicated. i.e. remove the first one and keep the others
const findDuplicates = (arr) => {
const result = [];
const map = new Map();
for (const item of arr) {
if (map.has(item.pair)) {
result.push(item);
} else {
map.set(item.pair, true);
}
}
return result;
};
// get duplicate elements - RUN THIS before trying to delete the alert logs
findDuplicates(arr).map((item) => document.querySelectorAll(listSelector)[item.i]);
// click on duplicate elements (x) icon to remove them
findDuplicates(arr).forEach((item) =>
setTimeout(
() => document.querySelectorAll(listSelector)[item.i].parentElement.querySelector('[role="button"]').click(),
100
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment