1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00
hack-chat-main/documentation/scripts/linenumber.js

26 lines
671 B
JavaScript
Raw Normal View History

2023-12-30 15:24:12 +08:00
/*global document */
2022-06-23 00:32:51 +08:00
(() => {
2023-12-30 15:24:12 +08:00
const source = document.getElementsByClassName('prettyprint source linenums');
let i = 0;
let lineNumber = 0;
let lineId;
let lines;
let totalLines;
let anchorHash;
2022-06-23 00:32:51 +08:00
2023-12-30 15:24:12 +08:00
if (source && source[0]) {
anchorHash = document.location.hash.substring(1);
lines = source[0].getElementsByTagName('li');
totalLines = lines.length;
2022-06-23 00:32:51 +08:00
2023-12-30 15:24:12 +08:00
for (; i < totalLines; i++) {
lineNumber++;
lineId = `line${lineNumber}`;
lines[i].id = lineId;
if (lineId === anchorHash) {
lines[i].className += ' selected';
}
}
2022-06-23 00:32:51 +08:00
}
})();