What’s this strange script doing in my GitHub repo?
Asked by
morning bus transfer
I was going through one of my GitHub repositories when I stumbled upon this script at the top of my index.html file, which I definitely don't remember adding:
```javascript
<script type="text/javascript">
var gk_isXlsx = false;
var gk_xlsxFileLookup = {};
var gk_fileData = {};
function filledCell(cell) {
return cell !== '' && cell != null;
}
function loadFileData(filename) {
if (gk_isXlsx && gk_xlsxFileLookup[filename]) {
try {
var workbook = XLSX.read(gk_fileData[filename], { type: 'base64' });
var firstSheetName = workbook.SheetNames[0];
var worksheet = workbook.Sheets[firstSheetName];
// Convert sheet to JSON to filter blank rows
var jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1, blankrows: false, defval: '' });
// Filter out blank rows
var filteredData = jsonData.filter(row => row.some(filledCell));
// Heuristic to find the header row
var headerRowIndex = filteredData.findIndex((row, index) =>
row.filter(filledCell).length >= filteredData[index + 1]?.filter(filledCell).length
);
// Fallback
if (headerRowIndex === -1 || headerRowIndex > 25) {
headerRowIndex = 0;
}
// Convert filtered JSON back to CSV
var csv = XLSX.utils.aoa_to_sheet(filteredData.slice(headerRowIndex));
csv = XLSX.utils.sheet_to_csv(csv, { header: 1 });
return csv;
} catch (e) {
console.error(e);
return "";
}
}
return gk_fileData[filename] || "";
}
</script>
```
The only file I have in this repo is index.html, and there are no GitHub Actions implemented. After searching online, I discovered that this exact script appears in several places:
- [Kaggle dataset](https://www.kaggle.com/datasets/waleed1980/global-pharmacy-bi-bloom-dataset/data)
- [Domoticz forum](https://forum.domoticz.com/viewtopic.php?p=326841&sid=50d57b4e00bf7ab23dc6e802b5c001dd#p326841)
- [CodePen](https://codepen.io/Dipin-Kakkar/pen/xbGwoXa)
So, does anyone know what this script is or how it ended up in my repository? I'm aware that it's related to converting .xlsx files to .csv via JSON.
Answers
It looks like this script is a helper function from the SheetJS library. It's designed to convert spreadsheets to CSV format, which is super handy! You probably didn’t add it yourself; it might have been included by a library you are using or possibly slipped in through a template or other code you copied.
Reply to this answer
Add your answer
Answers are reviewed before publication.
morning bus transfer: Do you have any guesses as to how it got mixed into my code?