Skip to content

Commit

Permalink
Merge pull request #31 from Apollo156156/master
Browse files Browse the repository at this point in the history
issues#30 - fixed copy lines to GitHub
  • Loading branch information
pelid authored May 8, 2024
2 parents 8967566 + 1474bd4 commit fe56ccd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
- Исправлена инструкция для запуска в firefox, [issue #19](https://github.com/devmanorg/github-copy-plugin/issues/19)
- Добавляет определения языка при копировании кода в gitlab, [issue #16](https://github.com/devmanorg/github-copy-plugin/issues/16)
- Исправляет получение типа файла в ссылках с get параметрами, [issue #28](https://github.com/devmanorg/github-copy-plugin/issues/28)
- Исправляет копирование строк в GitHub, [issue #30](https://github.com/devmanorg/github-copy-plugin/issues/30)
14 changes: 8 additions & 6 deletions sites/github.com.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ var copyMarkdownSnippetFromGithub = (function(){ // ES6 modules are not supporte
}

function convertLineElToText(lineEl){
let spans = lineEl.querySelectorAll('span');
let textFragments = Array.prototype.map.call(spans, span => span.getAttribute('data-code-text'))
let lines = Array.from(lineEl.querySelector('.react-file-line').childNodes);
let textFragments = Array.prototype.map.call(lines, line => line.textContent)
return textFragments.join('')
}

function readHighlightedLines(){
// Read code lines highlighted on GitHub page, return multiline string
let lines = document.querySelectorAll('.js-file-line-container .js-file-line.highlighted');
if (lines.length === 0) {
lines = document.querySelectorAll('div[aria-current]');
let lines = Array.from(document.querySelectorAll('.highlighted-line'));
const numbers = lines.map(line => line.getAttribute('data-line-number'));
let texts = numbers.map(number => document.querySelector(`[data-key="${number - 1}"]`))
if (texts.length === 0) {
texts = document.querySelectorAll('div[aria-current]');
}
const codeLines = Array.prototype.map.call(lines, convertLineElToText);
const codeLines = Array.prototype.map.call(texts, convertLineElToText);
return codeLines.join('\n');
}

Expand Down

0 comments on commit fe56ccd

Please sign in to comment.