Skip to main content
Sign in
Snippets Groups Projects
Commit d0b986ce authored by Jan Seipel's avatar Jan Seipel
Browse files

initial commit

parents
Branches
No related tags found
No related merge requests found
// ==UserScript==
// @name netzradar-yourls-downloader
// @namespace http://tampermonkey.net/
// @version 2024-07-09
// @description Lädt Daten aus unserer Yourls-Instanz als CSV herunter
// @author You
// @match http://x.swr.de/a/admin/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const getDataFromRow = (d) => {
const shortURL = d.querySelector("td.keyword > a").href
const title = d.querySelector("td.url > a").title
const link = d.querySelector("td.url > a").href
const unixTime = d.querySelector("span.timestamp").innerText
const dateObj = new Date(unixTime *1000)
const dateStr = dateObj.toISOString().split("T")[0]
const clicks = d.querySelector("td.clicks").innerText
return '"' + [shortURL, title, link, dateStr, clicks].join('";"') + '"'
}
const createCSV = () => {
const rows = document.querySelectorAll("tr[id^='id-']")
const rowData = [...rows].map((d) => getDataFromRow(d))
const csv = rowData.join("\n")
return csv
}
const createDownload = () => {
const csv = createCSV()
const a = document.createElement('a');
a.href = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
//supported by chrome 14+ and firefox 20+
a.download = 'yourls-data.csv';
//needed for firefox
document.getElementsByTagName('body')[0].appendChild(a);
//supported by chrome 20+ and firefox 5+
a.click();
}
const createDownloadButton = () => {
let btn = document.createElement("input")
btn.type = "button"
btn.value = "Download csv"
btn.className = "button"
btn.onclick = () => createDownload()
document.getElementById("filter_buttons").appendChild(btn)
}
createDownloadButton()
})();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment