Skip to content

Instantly share code, notes, and snippets.

@voltrevo
Last active September 15, 2017 06:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voltrevo/71188b20256616e9c1911911f83717a1 to your computer and use it in GitHub Desktop.
Save voltrevo/71188b20256616e9c1911911f83717a1 to your computer and use it in GitHub Desktop.
'use strict';
const rows = Array.prototype.slice.apply(
document.querySelectorAll('.js-file-line')
);
const code = rows
.map(el =>
el.innerHTML
.replace(/<[^>]*>/g, '')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&amp;/g, '&')
.replace(/%0A/g, escape('%0A'))
)
.join('%0A')
;
const lnk = document.createElement('a');
lnk.href = `javascript:(()=>{${code}})()`;
lnk.textContent = document.title;
lnk.setAttribute('class', 'btn btn-sm');
document.querySelector('.file-actions').appendChild(lnk);
@aiham
Copy link

aiham commented Sep 15, 2017

I like this lots ;-)

@aiham
Copy link

aiham commented Sep 15, 2017

Actually, on second thought, I dislike hyphens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment